Skip to content

Commit

Permalink
Should close #320
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonMatthes committed Jan 28, 2019
1 parent 1d0536d commit 3000df4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def notify_users(title, message)
def create
prepare_params
@request = Request.new(request_params.merge(user: current_user))
@request.assign_sudo_users(request_params[:sudo_user_ids][1..-1])

respond_to do |format|
if @request.save
@request.assign_sudo_users(request_params[:sudo_user_ids][1..-1])
successful_save(format)
else
unsuccessful_action(format, :new)
Expand Down
2 changes: 1 addition & 1 deletion app/models/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def assign_sudo_users(sudo_user_ids)
if !assignment.nil?
assignment.update_attribute(:sudo, true)
else
users_assigned_to_requests.create(sudo: true, user_id: id)
users_assigned_to_requests.new(sudo: true, user_id: id)
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions app/views/requests/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

<div class="field form-group">
<%= form.label :ram_mb, "RAM in GB" %>
<%= form.number_field :ram_mb, value: @request.persisted? ? mb_to_gb(@request.ram_mb) : nil, min: 0, class: 'form-control', id: 'ram' %>
<%= form.number_field :ram_mb, value: (@request && !@request&.ram_mb.nil?) ? mb_to_gb(@request.ram_mb) : nil, min: 0, class: 'form-control', id: 'ram' %>
</div>

<div class="field form-group">
<%= form.label :storage_mb, "Storage in GB" %>
<%= form.number_field :storage_mb, value: @request.persisted? ? mb_to_gb(@request.storage_mb) : nil, min: 0, class: 'form-control', id: 'storage' %>
<%= form.number_field :storage_mb, value: (@request && !@request&.storage_mb.nil?) ? mb_to_gb(@request.storage_mb) : nil, min: 0, class: 'form-control', id: 'storage' %>
</div>

<div class="field form-group">
Expand Down Expand Up @@ -91,6 +91,7 @@
<% end %>

<% if locals[:updating] %>
<hr/>
<%= form_with(model: request, url:{action: 'reject', id: request}, local: true) do |rejection_form| %>
<div class="field form-group">
<%= rejection_form.label :rejection_information %>
Expand Down
12 changes: 9 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
t.index ["user_id"], name: "index_requests_on_user_id"
end

create_table "requests_responsible_users", id: false, force: :cascade do |t|
t.integer "request_id", null: false
t.integer "user_id", null: false
t.index ["request_id", "user_id"], name: "index_requests_responsible_users_on_request_id_and_user_id"
end

create_table "responsible_users", force: :cascade do |t|
t.integer "user_id", null: false
t.integer "project_id", null: false
Expand Down Expand Up @@ -123,11 +129,11 @@
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.integer "role"
t.string "first_name"
t.string "last_name"
t.string "ssh_key"
t.string "provider"
t.string "uid"
t.string "ssh_key"
t.string "first_name"
t.string "last_name"
t.integer "user_id"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
Expand Down

0 comments on commit 3000df4

Please sign in to comment.