Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix edit flow of LDAP groups

Oliver Güntherad4b84e1ddd9
diff --git a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb
index 673b3c2b0a4..092f8e80c1a 100644
--- a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb
+++ b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb
@@ -1,3 +1,32 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
module LdapGroups
class SynchronizedGroupsController < ::ApplicationController
before_action :require_admin
@@ -6,7 +35,7 @@ module LdapGroups
redirect_to action: :index, status: :see_other
end
- before_action :find_group, only: %i(show destroy_info destroy)
+ before_action :find_group, only: %i(show edit update destroy_info destroy)
layout "admin"
menu_item :plugin_ldap_groups
@@ -17,13 +46,13 @@ module LdapGroups
@filters = SynchronizedFilter.includes(:ldap_auth_source, :groups)
end
+ def show; end
+
def new
@group = SynchronizedGroup.new
end
- def show
- render
- end
+ def edit; end
def create
@group = SynchronizedGroup.new permitted_params
@@ -38,6 +67,17 @@ module LdapGroups
render_400
end
+ def update
+ if @group.update(permitted_params)
+ flash[:notice] = I18n.t(:notice_successful_update)
+ redirect_to action: :show
+ else
+ render action: :edit, status: :unprocessable_entity
+ end
+ rescue ActionController::ParameterMissing
+ render_400
+ end
+
def destroy_info
render
end
@@ -59,9 +99,7 @@ module LdapGroups
end
def permitted_params
- params
- .require(:synchronized_group)
- .permit(:dn, :group_id, :ldap_auth_source_id, :sync_users)
+ params.expect(synchronized_group: %i[dn group_id ldap_auth_source_id sync_users])
end
end
end
diff --git a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/_form.html.erb b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/_form.html.erb
new file mode 100644
index 00000000000..34f330d5759
--- /dev/null
+++ b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/_form.html.erb
@@ -0,0 +1,45 @@
+<fieldset class="form--fieldset">
+ <legend class="form--fieldset-legend"><%= @group.class.human_attribute_name "auth_source" %></legend>
+
+ <div class="form--field -required">
+ <%= f.select :ldap_auth_source_id,
+ LdapAuthSource.pluck(:name, :id),
+ required: true,
+ include_blank: "--- #{t(:actionview_instancetag_blank_option)} ---",
+ container_class: "-middle" %>
+ <div class="form--field-instructions">
+ <%= t("ldap_groups.synchronized_groups.form.auth_source_text") %>
+ </div>
+ </div>
+</fieldset>
+<fieldset class="form--fieldset">
+ <legend class="form--fieldset-legend"><%= @group.class.model_name.human %></legend>
+
+ <div class="form--field -required">
+ <%= f.text_field :dn,
+ required: true,
+ container_class: "-middle" %>
+ <div class="form--field-instructions">
+ <%= t("ldap_groups.synchronized_groups.form.dn_text") %>
+ </div>
+ </div>
+
+ <div class="form--field -required">
+ <%= f.check_box :sync_users,
+ container_class: "-middle" %>
+ <div class="form--field-instructions">
+ <%= t("ldap_groups.synchronized_groups.form.sync_users_text") %>
+ </div>
+ </div>
+
+ <div class="form--field -required">
+ <%= f.select :group_id,
+ Group.order(lastname: :asc).pluck(:lastname, :id),
+ required: true,
+ include_blank: "--- #{t(:actionview_instancetag_blank_option)} ---",
+ container_class: "-middle" %>
+ <div class="form--field-instructions">
+ <%= t("ldap_groups.synchronized_groups.form.group_text") %>
+ </div>
+ </div>
+</fieldset>
diff --git a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/edit.html.erb b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/edit.html.erb
new file mode 100644
index 00000000000..66098edfd60
--- /dev/null
+++ b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/edit.html.erb
@@ -0,0 +1,28 @@
+<% html_title(t(:label_administration), t("ldap_groups.synchronized_groups.add_new")) -%>
+
+<%=
+ render Primer::OpenProject::PageHeader.new do |header|
+ header.with_title { h(@group.dn) }
+ header.with_breadcrumbs(
+ [{ href: admin_index_path, text: t(:label_administration) },
+ { href: admin_settings_authentication_path, text: t(:label_authentication) },
+ { href: ldap_groups_synchronized_groups_path, text: I18n.t("ldap_groups.label_menu_item") },
+ nested_breadcrumb_element(t("ldap_groups.synchronized_groups.singular"), @group.dn)],
+ selected_item_font_weight: :normal
+ )
+ end
+%>
+
+<%= error_messages_for @group %>
+
+<%= labelled_tabular_form_for @group,
+ as: :synchronized_group,
+ url: { action: :update } do |f| %>
+
+ <%= render partial: "form", locals: { f: } %>
+
+ <p>
+ <%= styled_button_tag t(:button_save), class: "-primary -with-icon icon-checkmark" %>
+ <%= link_to t(:button_cancel), url_for(action: :index), class: "button -with-icon icon-cancel" %>
+ </p>
+<% end %>
diff --git a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/new.html.erb b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/new.html.erb
index 929a0d8fa06..940f33fd60e 100644
--- a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/new.html.erb
+++ b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/new.html.erb
@@ -18,51 +18,7 @@
as: :synchronized_group,
url: { action: :create } do |f| %>
- <fieldset class="form--fieldset">
- <legend class="form--fieldset-legend"><%= @group.class.human_attribute_name "auth_source" %></legend>
-
- <div class="form--field -required">
- <%= f.select :ldap_auth_source_id,
- LdapAuthSource.pluck(:name, :id),
- required: true,
- include_blank: "--- #{t(:actionview_instancetag_blank_option)} ---",
- container_class: "-middle" %>
- <div class="form--field-instructions">
- <%= t("ldap_groups.synchronized_groups.form.auth_source_text") %>
- </div>
- </div>
- </fieldset>
- <fieldset class="form--fieldset">
- <legend class="form--fieldset-legend"><%= @group.class.model_name.human %></legend>
-
- <div class="form--field -required">
- <%= f.text_field :dn,
- required: true,
- container_class: "-middle" %>
- <div class="form--field-instructions">
- <%= t("ldap_groups.synchronized_groups.form.dn_text") %>
- </div>
- </div>
-
- <div class="form--field -required">
- <%= f.check_box :sync_users,
- container_class: "-middle" %>
- <div class="form--field-instructions">
- <%= t("ldap_groups.synchronized_groups.form.sync_users_text") %>
- </div>
- </div>
-
- <div class="form--field -required">
- <%= f.select :group_id,
- Group.order(lastname: :asc).pluck(:lastname, :id),
- required: true,
- include_blank: "--- #{t(:actionview_instancetag_blank_option)} ---",
- container_class: "-middle" %>
- <div class="form--field-instructions">
- <%= t("ldap_groups.synchronized_groups.form.group_text") %>
- </div>
- </div>
- </fieldset>
+ <%= render partial: "form", locals: { f: } %>
<p>
<%= styled_button_tag t(:button_create), class: "-primary -with-icon icon-checkmark" %>
diff --git a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/show.html.erb b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/show.html.erb
index 2b6717fbb2c..62146d17394 100644
--- a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/show.html.erb
+++ b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/show.html.erb
@@ -10,6 +10,35 @@
nested_breadcrumb_element(t("ldap_groups.synchronized_groups.singular"), @group.dn)],
selected_item_font_weight: :normal
)
+
+ unless @group.filter
+ header.with_action_button(
+ tag: :a,
+ mobile_icon: :pencil,
+ mobile_label: t(:button_edit),
+ size: :medium,
+ href: edit_ldap_groups_synchronized_group_path(@group),
+ aria: { label: I18n.t(:button_edit) },
+ title: I18n.t(:button_edit)
+ ) do |button|
+ button.with_leading_visual_icon(icon: :pencil)
+ t(:button_edit)
+ end
+ end
+
+ header.with_action_button(
+ tag: :a,
+ scheme: :danger,
+ mobile_icon: :trash,
+ mobile_label: t(:button_delete),
+ size: :medium,
+ href: destroy_info_ldap_groups_synchronized_group_path(@group),
+ aria: { label: I18n.t(:button_delete) },
+ title: I18n.t(:button_delete)
+ ) do |button|
+ button.with_leading_visual_icon(icon: :trash)
+ t(:button_delete)
+ end
end
%>
diff --git a/modules/ldap_groups/config/routes.rb b/modules/ldap_groups/config/routes.rb
index f66e6f61535..1fd8922ee92 100644
--- a/modules/ldap_groups/config/routes.rb
+++ b/modules/ldap_groups/config/routes.rb
@@ -13,10 +13,8 @@ Rails.application.routes.draw do
end
resources :synchronized_groups,
- param: :ldap_group_id,
- only: %i(new index create show destroy) do
+ param: :ldap_group_id do
member do
- # Destroy warning
get "destroy_info"
end
end
diff --git a/modules/ldap_groups/spec/features/administration_spec.rb b/modules/ldap_groups/spec/features/administration_spec.rb
index 85913001bc5..656c8eb7c27 100644
--- a/modules/ldap_groups/spec/features/administration_spec.rb
+++ b/modules/ldap_groups/spec/features/administration_spec.rb
@@ -45,11 +45,21 @@ RSpec.describe "LDAP group sync administration spec", :js do
find("td.dn a").click
expect(page).to have_css ".generic-table--empty-row"
+ # Edit entry
+ click_on "Edit"
+ fill_in "DN", with: "cn=bar,ou=groups,dc=example,dc=com"
+ click_on "Save"
+
+ expect_flash(message: I18n.t(:notice_successful_update))
+
+ visit ldap_groups_synchronized_groups_path
+ expect(page).to have_css("td.dn", text: "cn=bar,ou=groups,dc=example,dc=com")
+
# Check created group
sync = LdapGroups::SynchronizedGroup.last
expect(sync.group_id).to eq(group.id)
expect(sync.ldap_auth_source_id).to eq(auth_source.id)
- expect(sync.dn).to eq "cn=foo,ou=groups,dc=example,dc=com"
+ expect(sync.dn).to eq "cn=bar,ou=groups,dc=example,dc=com"
# Assume we have a membership
sync.users.create user_id: admin.id
@@ -63,7 +73,7 @@ RSpec.describe "LDAP group sync administration spec", :js do
find(".buttons a", text: "Delete").click
SeleniumHubWaiter.wait
- find(".danger-zone--verification input").set "cn=foo,ou=groups,dc=example,dc=com"
+ find(".danger-zone--verification input").set "cn=bar,ou=groups,dc=example,dc=com"
SeleniumHubWaiter.wait
click_on "Delete"