Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,33 @@ def api_access_token
render json: { api_access_token: sessions_current_project&.api_access_token }
end

# POST /projects/quick_create
def quick_create
if !(Rails.env.development? || Settings.sandbox_mode?)
redirect_to projects_path, alert: 'Quick project is only available in development and sandboxes!'
end

# Best-effort: name that sorts first alphabetically and is unique
stamp = Time.now.utc.strftime('%Y-%m-%d:%H_%M_%S')
name = "0 - #{sessions_current_user.name}'s quick project #{stamp}"

@project = Project.new(name: name)
#@project.set_new_api_access_token = true

Project.transaction do
@project.save!
ProjectMember.create!(
project_id: @project.id,
user_id: sessions_current_user.id,
is_project_administrator: true
)
end

redirect_to select_project_path(@project), notice: 'Quick project created and selected.'
rescue ActiveRecord::RecordInvalid => e
redirect_to projects_path, alert: "Could not create quick project: #{e.record.errors.full_messages.to_sentence}"
end

private

def set_project
Expand Down
12 changes: 11 additions & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
</div>

<div class="attributes">
<%= button_to 'Edit', edit_user_path(@user), method: :get, class: 'button btn-primary btn btn-medium-size' %><br>
<%= button_to 'Edit', edit_user_path(@user), method: :get, class: 'button btn-primary btn btn-medium-size' %>

<% if Rails.env.development? || Settings.sandbox_mode? %>
<%= button_to("Create a quick project",
quick_create_projects_path,
method: :post, class: 'button btn-primary btn btn-medium-size margin-large-top',
data: { turbolinks: false })
-%>
<% end %>
<br>

<%= render 'attributes' %>
</div>

Expand Down
1 change: 1 addition & 0 deletions config/routes/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
get 'list'
get 'search'
get 'autocomplete'
post 'quick_create'
end

member do
Expand Down