-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15164 from opf/implementation/53718-create-new-fo…
…rm-section-for-ampf-decision [#53718] added access management form section
- Loading branch information
Showing
24 changed files
with
608 additions
and
47 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
modules/storages/app/components/storages/admin/access_management_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<%= | ||
grid_layout('op-storage-view--row', | ||
tag: :div, | ||
test_selector: 'storage-access-management-section', | ||
align_items: :center) do |grid| | ||
grid.with_area(:item, tag: :div, mr: 3) do | ||
concat(render(Primer::Beta::Text.new(font_weight: :bold, mr: 1, test_selector: 'access-management-label')) do | ||
I18n.t('storages.file_storage_view.access_management.subtitle') | ||
end) | ||
concat(configuration_check_label_for(:access_management_configured)) | ||
end | ||
|
||
grid.with_area(:description, tag: :div, color: :subtle, test_selector: 'access-management-description') do | ||
render(Primer::Beta::Text.new) { access_management_description } | ||
end | ||
|
||
if editable_storage? | ||
grid.with_area(:"icon-button", tag: :div, color: :muted) do | ||
flex_layout(justify_content: :flex_end) do |icons_container| | ||
icons_container.with_column do | ||
render( | ||
Primer::Beta::IconButton.new( | ||
icon: :pencil, | ||
tag: :a, | ||
scheme: :invisible, | ||
href: edit_admin_settings_storage_access_management_path(storage), | ||
aria: { label: I18n.t('storages.label_edit_storage_access_management') }, | ||
test_selector: 'storage-edit-access-management-button', | ||
data: { turbo_stream: true } | ||
) | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
%> |
53 changes: 53 additions & 0 deletions
53
modules/storages/app/components/storages/admin/access_management_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 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 Storages::Admin | ||
class AccessManagementComponent < ApplicationComponent | ||
include OpPrimer::ComponentHelpers | ||
include StorageViewInformation | ||
|
||
alias_method :storage, :model | ||
|
||
private | ||
|
||
def access_management_description | ||
if storage.automatic_management_new_record? | ||
return I18n.t("storages.file_storage_view.access_management.setup_incomplete") | ||
end | ||
|
||
case storage.automatic_management_enabled | ||
when true | ||
I18n.t("storages.file_storage_view.access_management.automatic_management") | ||
when false | ||
I18n.t("storages.file_storage_view.access_management.manual_management") | ||
end | ||
end | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
...es/storages/app/components/storages/admin/forms/access_management_form_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<%= | ||
render(Primer::Beta::Text.new(tag: :div, test_selector: 'storage-access-management-form')) do | ||
primer_form_with( | ||
model:, | ||
url: admin_settings_storage_access_management_path(storage), | ||
method: form_method | ||
) do |form| | ||
flex_layout do |access_management_row| | ||
access_management_row.with_row(mb: 3) do | ||
render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t(:'storages.file_storage_view.access_management.subtitle') } | ||
end | ||
|
||
access_management_row.with_row(mb: 3) do | ||
render(Primer::Beta::Text.new(test_selector: 'storage-access-management-description')) do | ||
I18n.t(:'storages.file_storage_view.access_management.description') | ||
end | ||
end | ||
|
||
access_management_row.with_row do | ||
render(Storages::Admin::AccessManagementForm.new(form, storage:)) | ||
end | ||
|
||
access_management_row.with_row do | ||
render( | ||
Storages::Admin::SubmitOrCancelForm.new( | ||
form, | ||
storage:, | ||
submit_button_options: {}, | ||
cancel_button_options: { href: cancel_button_path } | ||
) | ||
) | ||
end | ||
end | ||
end | ||
end | ||
%> |
50 changes: 50 additions & 0 deletions
50
modules/storages/app/components/storages/admin/forms/access_management_form_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 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 Storages::Admin::Forms | ||
class AccessManagementFormComponent < ApplicationComponent | ||
include OpPrimer::ComponentHelpers | ||
alias_method :storage, :model | ||
|
||
private | ||
|
||
def form_method | ||
first_time_configuration? ? :post : :patch | ||
end | ||
|
||
def cancel_button_path | ||
edit_admin_settings_storage_path(storage) | ||
end | ||
|
||
def first_time_configuration? | ||
storage.automatic_management_new_record? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
modules/storages/app/controllers/storages/admin/access_management_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# frozen_string_literal: true | ||
|
||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 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. | ||
#++ | ||
|
||
class Storages::Admin::AccessManagementController < ApplicationController | ||
layout "admin" | ||
|
||
before_action :require_admin | ||
|
||
model_object Storages::OneDriveStorage | ||
before_action :find_model_object, only: %i[new create edit update] | ||
|
||
# menu_item is defined in the Redmine::MenuManager::MenuController | ||
# module, included from ApplicationController. | ||
# The menu item is defined in the engine.rb | ||
menu_item :storages_admin_settings | ||
|
||
# Show the admin page to set storage folder automatic management (for an already existing storage). | ||
# Sets the attributes automatically_managed as default true unless already set to false | ||
# renders a form (allowing the user to change automatically_managed bool and password). | ||
# Used by: The OauthClientsController#create, after the user inputs Oauth credentials for the first time. | ||
# Called by: Global app/config/routes.rb to serve Web page | ||
def new | ||
respond_to do |format| | ||
format.turbo_stream | ||
end | ||
end | ||
|
||
def create | ||
service_result = call_update_service | ||
|
||
service_result.on_success do | ||
respond_to { |format| format.turbo_stream } | ||
end | ||
|
||
service_result.on_failure do | ||
respond_to do |format| | ||
format.turbo_stream { render :edit } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
service_result = call_update_service | ||
|
||
service_result.on_success do | ||
respond_to { |format| format.turbo_stream } | ||
end | ||
|
||
service_result.on_failure do | ||
respond_to do |format| | ||
format.turbo_stream { render :edit } | ||
end | ||
end | ||
end | ||
|
||
def edit | ||
respond_to do |format| | ||
format.turbo_stream | ||
end | ||
end | ||
|
||
def default_breadcrumb | ||
ActionController::Base.helpers.link_to(t(:project_module_storages), admin_settings_storages_path) | ||
end | ||
|
||
def show_local_breadcrumb | ||
true | ||
end | ||
|
||
private | ||
|
||
def find_model_object(object_id = :storage_id) | ||
super(object_id) | ||
@storage = @object | ||
end | ||
|
||
def call_update_service | ||
::Storages::Storages::UpdateService | ||
.new(user: current_user, model: @storage) | ||
.call(permitted_storage_params) | ||
end | ||
|
||
def permitted_storage_params | ||
params | ||
.require(:storages_one_drive_storage) | ||
.permit("automatic_management_enabled") | ||
end | ||
end |
Oops, something went wrong.