Add API filter for membership autocompleters to avoid that already selected projects can be chosen again

pull/10674/head
Henriette Darge 2 years ago
parent 4f864d59a6
commit 4462a7b3c3
  1. 25
      app/helpers/application_helper.rb
  2. 8
      app/helpers/users_helper.rb
  3. 2
      app/views/groups/_memberships.html.erb
  4. 2
      app/views/individual_principals/_memberships.html.erb

@ -152,31 +152,6 @@ module ApplicationHelper
end
end
def project_tree_options_for_select(projects, selected: nil, disabled: {}, &_block)
options = ''.html_safe
Project.project_level_list(projects).each do |element|
identifier = element[:project].id
tag_options = {
value: h(identifier),
title: h(element[:project].name)
}
if !selected.nil? && selected.id == identifier
tag_options[:selected] = true
end
tag_options[:disabled] = true if disabled.include? identifier
content = ''.html_safe
content << (('&nbsp;' * 3 * element[:level]) + '&#187; ').html_safe if element[:level] > 0
content << element[:project].name
options << content_tag('option', content, tag_options)
end
options
end
# Yields the given block for each project with its level in the tree
#
# Wrapper for Project#project_tree

@ -118,14 +118,6 @@ module UsersHelper
end
end
# Options for the new membership projects combo-box
#
# Disables projects the user is already member in
def options_for_membership_project_select(user, projects)
options = project_tree_options_for_select(projects, disabled: user.projects.ids.to_set)
content_tag('option', "--- #{I18n.t(:actionview_instancetag_blank_option)} ---") + options
end
def user_name(user)
user ? user.name : I18n.t('user.deleted')
end

@ -128,7 +128,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= label_tag "membership_project_id", t(:description_choose_project), class: "hidden-for-sighted" %>
<%= angular_component_tag 'op-project-autocompleter',
inputs: {
apiFilters: [],
apiFilters: [['id', '!', @group.projects.ids.map(&:to_s)]],
name: 'membership[project_id]'
},
data: {

@ -147,7 +147,7 @@ See COPYRIGHT and LICENSE files for more details.
<legend class="form--fieldset-legend"><%=t(:label_project_new)%></legend>
<%= angular_component_tag 'op-project-autocompleter',
inputs: {
apiFilters: [],
apiFilters: [['id', '!', @individual_principal.projects.ids.map(&:to_s)]],
name: 'membership[project_id]'
},
data: {

Loading…
Cancel
Save