Skip to content

Commit

Permalink
Merge pull request #13136 from opf/implementation/49140-change-defaul…
Browse files Browse the repository at this point in the history
…t-project-folder-setting

[#49140] Change default project folder setting
  • Loading branch information
Kharonus authored Jul 21, 2023
2 parents 11c7338 + d518f74 commit 0a98b5c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ class BaseContract < ::ModelContract
end
end

def assignable_storages
Storages::Storage.visible(user).where.not(id: @model.project.projects_storages.pluck(:storage_id))
end

private

def project_folder_mode_manual?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,16 @@ def index
# Show a HTML page with a form in order to create a new ProjectStorage
# Called by: When a user clicks on the "+New" button in Project -> Settings -> File Storages
def new
@available_storages = available_storages
@project_storage = ::Storages::ProjectStorages::SetAttributesService
.new(user: current_user,
model: Storages::ProjectStorage.new,
contract_class: EmptyContract)
.call(project: @project)
.call(project: @project,
storage: @available_storages.find_by(id: params.dig(:storages_project_storage, :storage_id)))
.result

@available_storages = available_storages
@last_project_folders = {}

storage_id = params.dig(:storages_project_storage, :storage_id)
if storage_id.present?
@project_storage.storage = available_storages.find_by(id: storage_id)
end

render template: '/storages/project_settings/new'
end

Expand Down Expand Up @@ -165,6 +160,6 @@ def permitted_storage_settings_params
end

def available_storages
Storages::ProjectStorages::CreateContract.new(@project_storage, current_user).assignable_storages
Storages::Storage.visible.not_enabled_for_project(@project)
end
end
8 changes: 6 additions & 2 deletions modules/storages/app/models/storages/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Storages::Storage < ApplicationRecord

# Creates a scope of all storages, which belong to a project the user is a member
# and has the permission ':view_file_links'
scope :visible, ->(user = User.current) {
scope :visible, ->(user = User.current) do
if user.allowed_to_globally?(:manage_storages_in_project)
all
else
Expand All @@ -78,7 +78,11 @@ class Storages::Storage < ApplicationRecord
)
)
end
}
end

scope :not_enabled_for_project, ->(project) do
where.not(id: project.projects_storages.pluck(:storage_id))
end

def self.shorten_provider_type(provider_type)
case /Storages::(?'provider_name'.*)Storage/.match(provider_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@
# Used by: CreateService when setting attributes
module Storages::ProjectStorages
class SetAttributesService < ::BaseServices::SetAttributes
def set_default_attributes(_params)
def set_default_attributes(params)
model.creator ||= user

if params[:project_folder_mode].blank? && model.storage.present? && model.storage.automatically_managed?
# set default to automatic, if related storage is automatically managed
# do NOT override values set in params
model.project_folder_mode = "automatic"
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
# current_user, project, storage and other objects defined in the shared_contract_examples
# that includes all the stuff shared between create and update.
let(:project_storage) do
Storages::ProjectStorage.new(
build(
:project_storage,
creator: current_user,
project:,
storage:
Expand Down
13 changes: 11 additions & 2 deletions modules/storages/spec/features/manage_project_storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
# Setup storages in Project -> Settings -> File Storages
# This tests assumes that a Storage has already been setup
# in the Admin section, tested by admin_storage_spec.rb.
RSpec.describe 'Activation of storages in projects', js: true, webmock: true, with_flag: { storage_project_folders: true } do
RSpec.describe(
'Activation of storages in projects',
js: true,
webmock: true,
with_flag: { storage_project_folders: true,
managed_project_folders: true }
) do
let(:user) { create(:user) }
# The first page is the Project -> Settings -> General page, so we need
# to provide the user with the edit_project permission in the role.
Expand All @@ -42,7 +48,7 @@
edit_project])
end
let(:oauth_application) { create(:oauth_application) }
let(:storage) { create(:nextcloud_storage, oauth_application:) }
let(:storage) { create(:nextcloud_storage, :as_automatically_managed, oauth_application:) }
let(:project) do
create(:project,
members: { user => role },
Expand Down Expand Up @@ -112,6 +118,9 @@
expect(page).to have_select('storages_project_storage_storage_id', options: ['Storage 1 (nextcloud)'])
page.click_button('Continue')

# by default automatic have to be choosen if storage has automatic management enabled
expect(page).to have_checked_field("New folder with automatically managed permissions")

page.find_by_id('storages_project_storage_project_folder_mode_manual').click

# Select project folder
Expand Down
3 changes: 2 additions & 1 deletion modules/storages/spec/models/project_storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
{
storage:,
creator:,
project:
project:,
project_folder_mode: :inactive
}
end

Expand Down

0 comments on commit 0a98b5c

Please sign in to comment.