[28066] Fix duplicate label names in membership create/edit

https://community.openproject.com/wp/28066
pull/6453/head
Oliver Günther 6 years ago
parent 69c14a72a1
commit 2e1d6e1218
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 13
      app/controllers/groups_controller.rb
  2. 4
      app/models/permitted_params.rb
  3. 8
      app/views/groups/_memberships.html.erb
  4. 2
      spec/support/pages/groups.rb
  5. 2
      spec_legacy/functional/groups_controller_spec.rb

@ -142,15 +142,22 @@ class GroupsController < ApplicationController
def create_memberships
membership_params = permitted_params.group_membership
membership_id = membership_params[:membership_id]
@membership = membership_id.present? ? Member.find(membership_id) : Member.new(principal: @group)
if membership_id.present?
key = :membership
@membership = Member.find(membership_id)
else
key = :new_membership
@membership = Member.new(principal: @group)
end
service = ::Members::EditMembershipService.new(@membership, save: true, current_user: current_user)
result = service.call(attributes: membership_params[:membership])
result = service.call(attributes: membership_params[key])
if result.success?
flash[:notice] = I18n.t :notice_successful_update
else
flash[:error] = result.errors.full_mesages.join("\n")
flash[:error] = result.errors.full_messages.join("\n")
end
redirect_to controller: '/groups', action: 'edit', id: @group, tab: 'memberships'
end

@ -509,6 +509,10 @@ class PermittedParams
membership: [
:project_id,
role_ids: []
],
new_membership: [
:project_id,
role_ids: []
]
],
member: [

@ -117,14 +117,14 @@ See docs/COPYRIGHT.rdoc for more details.
<div class="grid-content">
<% if projects.any? %>
<%= styled_form_tag(memberships_of_group_path(@group), method: :post) do %>
<fieldset class="form--fieldset">
<fieldset class="form--fieldset add-membership-form-fieldset">
<legend class="form--fieldset-legend"><%=l(:label_project_new)%></legend>
<%= label_tag "membership_project_id", l(:description_choose_project), class: "hidden-for-sighted" %>
<%= styled_select_tag 'membership[project_id]', options_for_membership_project_select(@group, projects) %>
<%= label_tag "new_membership_project_id", l(:description_choose_project), class: "hidden-for-sighted" %>
<%= styled_select_tag 'new_membership[project_id]', options_for_membership_project_select(@group, projects) %>
<div class="form--field -vertical">
<%= styled_label_tag nil, "#{l(:label_role_plural)}:" %>
<div class="form--field-container -vertical">
<%= labeled_check_box_tags 'membership[role_ids][]', roles %>
<%= labeled_check_box_tags 'new_membership[role_ids][]', roles %>
</div>
</div>
<div><%= styled_button_tag l(:button_add), class: '-highlight -with-icon icon-checkmark' %></div>

@ -103,7 +103,7 @@ module Pages
end
def select_project!(project_name)
select(project_name, from: 'membership_project_id')
select(project_name, from: 'new_membership_project_id')
end
def add_user!(user_name)

@ -95,7 +95,7 @@ describe GroupsController, type: :controller do
it 'should create membership' do
assert_difference 'Group.find(10).members.count' do
post :create_memberships, params: { id: 10, membership: { project_id: 2, role_ids: ['1', '2'] } }
post :create_memberships, params: { id: 10, new_membership: { project_id: 2, role_ids: ['1', '2'] } }
end
end

Loading…
Cancel
Save