Skip to content

Commit

Permalink
Merge pull request #15164 from opf/implementation/53718-create-new-fo…
Browse files Browse the repository at this point in the history
…rm-section-for-ampf-decision

[#53718] added access management form section
  • Loading branch information
Kharonus authored Apr 8, 2024
2 parents 40c68ee + 52a495f commit e0fd7ee
Show file tree
Hide file tree
Showing 24 changed files with 608 additions and 47 deletions.
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
%>
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
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
%>
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@
end

if storage.provider_type_one_drive?
general_info_row.with_row(mb: 3) do
render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t(:'storages.label_managed_project_folders.automatically_managed_folders') }
end

general_info_row.with_row(mb: 3) do
render(Primer::Beta::Text.new) { I18n.t("storages.page_titles.managed_project_folders.subtitle") }
end

general_info_row.with_row(mb: 3) do
render(Storages::Admin::ManagedProjectFolders::AutomaticManagementCheckbox.new(form, storage:))
end

general_info_row.with_row(mb: 3,
data: {
'storages--automatically-managed-project-folders-form-target': "oneDriveInformationText"
}) do
render(Primer::Beta::Text.new) { information_for_one_drive_automatic_management }
end

general_info_row.with_row(mb: 3) do
render(Storages::Admin::ProviderDriveIdInputForm.new(form))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ def caption_for_provider_type(provider_type)
).html_safe
end

def information_for_one_drive_automatic_management
href = ::OpenProject::Static::Links[:storage_docs][:one_drive_drive_id_guide][:href]
I18n.t(
"storages.page_titles.managed_project_folders.one_drive_information",
drive_id_link_text: render(Primer::Beta::Link.new(href:, target: "_blank")) do
I18n.t("storages.instructions.one_drive.documentation_link_text")
end
).html_safe
end

def application_link_text_for(href, link_text)
render(Primer::Beta::Link.new(href:, target: "_blank")) { link_text }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@
end

if storage.provider_type_one_drive?
component.with_row(scheme: :neutral, color: :muted) do
grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
grid.with_area(:item, tag: :div, mr: 3) do
render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.access_management.title') }
end
end
end

component.with_row(scheme: :default) do
render(OpTurbo::FrameComponent.new(id: :access_management_section)) do
render(Storages::Admin::AccessManagementComponent.new(storage))
end
end

component.with_row(scheme: :neutral, color: :muted) do
grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
grid.with_area(:item, tag: :div, mr: 3) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def configuration_check_label
if storage.provider_type_nextcloud?
configuration_check_label_for(:host_name_configured)
elsif storage.provider_type_one_drive?
configuration_check_label_for(:host_name_configured, :storage_tenant_drive_configured)
configuration_check_label_for(:name_configured, :storage_tenant_drive_configured)
end
end

Expand Down
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
Loading

0 comments on commit e0fd7ee

Please sign in to comment.