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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#48044] added api specifications for project storages endpoints
Eric Schubert41385cc658e0
diff --git a/docs/api/apiv3/components/schemas/project_storage_collection_model.yml b/docs/api/apiv3/components/schemas/project_storage_collection_model.ymlnew file mode 100644index 00000000000..093d42ca37c--- /dev/null+++ b/docs/api/apiv3/components/schemas/project_storage_collection_model.yml@@ -0,0 +1,47 @@+# Schema: ProjectStorageCollectionModel+---+allOf:+ - $ref: './collection_model.yml'+ - type: object+ required:+ - _links+ - _embedded+ properties:+ _links:+ type: object+ required:+ - self+ properties:+ self:+ allOf:+ - $ref: "./link.yml"+ - description: |-+ This file links collection++ **Resource**: ProjectStorageCollectionModel+ _embedded:+ type: object+ required:+ - elements+ properties:+ elements:+ type: array+ items:+ $ref: './project_storage_model.yml'++example:+ _type: Collection+ total: 2+ count: 2+ _links:+ self:+ href: '/api/v3/project_storages?filters=%5B%7B%22storage%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%2281%22%5D%7D%7D%5D'+ _embedded:+ elements:+ - id: 1337+ _type: ProjectStorage+ _hint: project storage resource shortened for brevity+ - id: 1338+ _type: ProjectStorage+ _hint: File Link resource shortened for brevity+diff --git a/docs/api/apiv3/components/schemas/project_storage_model.yml b/docs/api/apiv3/components/schemas/project_storage_model.ymlnew file mode 100644index 00000000000..6813dd0f386--- /dev/null+++ b/docs/api/apiv3/components/schemas/project_storage_model.yml@@ -0,0 +1,99 @@+# Schema: ProjectStorageModel+---+type: object+required:+ - _type+ - id+ - projectFolderMode+ - createdAt+ - updatedAt+properties:+ _type:+ type: string+ enum:+ - ProjectStorage+ id:+ type: integer+ description: The project storage's id+ minimum: 1+ projectFolderMode:+ type: string+ enum:+ - inactive+ - manual+ createdAt:+ type: string+ format: date-time+ description: Time of creation+ updatedAt:+ type: string+ format: date-time+ description: Time of the most recent change to the project storage+ _links:+ type: object+ required:+ - self+ - creator+ - storage+ - project+ properties:+ self:+ allOf:+ - $ref: './link.yml'+ - description: |-+ This project storage.++ **Resource**: ProjectStorage+ creator:+ allOf:+ - $ref: './link.yml'+ - description: |-+ The user who created the project storage.++ **Resource**: User+ storage:+ allOf:+ - $ref: './link.yml'+ - description: |-+ The storage resource, that is linked to a project with this project storage.++ **Resource**: Storage+ project:+ allOf:+ - $ref: './link.yml'+ - description: |-+ The project resource, that is linked to a storage with this project storage.++ **Resource**: Project+ projectFolder:+ allOf:+ - $ref: './link.yml'+ - description: |-+ The directory on the storage that is used as a manual project folder.++ **Resource**: StorageFile++ # Conditions++ Only provided, if the `projectFolderMode` is set to `manual`.++example:+ _type: 'ProjectStorage'+ id: 1337+ projectFolderMode: 'manual'+ createdAt: '2023-01-20T14:30:00Z'+ updatedAt: '2023-05-23T11:57:48Z'+ _links:+ self:+ href: '/api/v3/project_storages/23'+ projectFolder:+ href: '/api/v3/storages/81/files/30'+ creator:+ title: 'Darth Vader'+ href: '/api/v3/users/3'+ project:+ title: 'Death Star 3.0'+ href: '/api/v3/projects/11'+ storage:+ title: "Palpatine's Data Vault"+ href: '/api/v3/storages/81'diff --git a/docs/api/apiv3/components/schemas/role_model.yml b/docs/api/apiv3/components/schemas/role_model.ymlindex 393aba7c110..ecf44ab571a 100644--- a/docs/api/apiv3/components/schemas/role_model.yml+++ b/docs/api/apiv3/components/schemas/role_model.yml@@ -4,12 +4,15 @@ type: objectrequired:- nameproperties:+ _type:+ type: string+ enum:+ - Roleid:type: integerdescription: Role idreadOnly: true- minimum: 0- exclusiveMinimum: true+ minimum: 1name:type: stringdescription: Role namediff --git a/docs/api/apiv3/components/schemas/status_model.yml b/docs/api/apiv3/components/schemas/status_model.ymlindex 3764f23140a..da3f9113e6f 100644--- a/docs/api/apiv3/components/schemas/status_model.yml+++ b/docs/api/apiv3/components/schemas/status_model.yml@@ -2,12 +2,15 @@---type: objectproperties:+ _type:+ type: string+ enum:+ - Statusid:type: integerdescription: Status idreadOnly: true- minimum: 0- exclusiveMinimum: true+ minimum: 1name:type: stringdescription: Status namediff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.ymlindex f842ea7d856..879d7fa3465 100644--- a/docs/api/apiv3/openapi-spec.yml+++ b/docs/api/apiv3/openapi-spec.yml@@ -265,6 +265,10 @@ paths:"$ref": "./paths/priorities.yml""/api/v3/priorities/{id}":"$ref": "./paths/priority.yml"+ "/api/v3/project_storages":+ "$ref": "./paths/project_storages.yml"+ "/api/v3/project_storages/{id}":+ "$ref": "./paths/project_storage.yml""/api/v3/projects":"$ref": "./paths/projects.yml""/api/v3/projects/form":@@ -686,6 +690,10 @@ components:"$ref": "./components/schemas/priority_model.yml"ProjectModel:"$ref": "./components/schemas/project_model.yml"+ ProjectStorageCollectionModel:+ "$ref": "./components/schemas/project_storage_collection_model.yml"+ ProjectStorageModel:+ "$ref": "./components/schemas/project_storage_model.yml"Project_copy_form:"$ref": "./components/schemas/project_copy_form.yml"Project_create_form:diff --git a/docs/api/apiv3/paths/project_storage.yml b/docs/api/apiv3/paths/project_storage.ymlnew file mode 100644index 00000000000..e3561a1732a--- /dev/null+++ b/docs/api/apiv3/paths/project_storage.yml@@ -0,0 +1,38 @@+# /api/v3/project_storage/{id}+---+get:+ summary: Gets a project storage+ operationId: get_project_storage+ tags:+ - File Links+ description: |-+ Gets a project storage resource. This resource contains all data that is applicable on the relation between a+ storage and a project.+ parameters:+ - name: id+ description: Project storage id+ in: path+ required: true+ schema:+ type: integer+ example: 1337+ responses:+ '200':+ description: OK+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/project_storage_model.yml'+ '404':+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ example:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:NotFound+ message: The requested resource could not be found.+ description: |-+ Returned if the project storage does not exist or the client does not have sufficient permissions to see it.++ **Required permission:** view file linksdiff --git a/docs/api/apiv3/paths/project_storages.yml b/docs/api/apiv3/paths/project_storages.ymlnew file mode 100644index 00000000000..23d0c4738c3--- /dev/null+++ b/docs/api/apiv3/paths/project_storages.yml@@ -0,0 +1,44 @@+# /api/v3/project_storage/{id}+---+get:+ summary: Gets a list of project storages+ operationId: list_project_storages+ tags:+ - File Links+ description: |-+ Gets a collection of all project storages that meet the provided filters and the user has permission to see them.+ parameters:+ - name: filters+ in: query+ required: false+ schema:+ default: '[]'+ type: string+ description: |-+ JSON specifying filter conditions.+ Accepts the same format as returned by the [queries](https://www.openproject.org/docs/api/endpoints/queries/)+ endpoint. Currently supported filters are:++ - project_id+ - storage_id+ example: '[{ "project_id": { "operator": "=", "values": ["42"] }}, { "storage_id": { "operator": "=", "values": ["1337"] }}]'+ responses:+ '200':+ description: OK+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/project_storage_collection_model.yml'+ '404':+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ example:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:NotFound+ message: The requested resource could not be found.+ description: |-+ Returned if the project storage does not exist or the client does not have sufficient permissions to see it.++ **Required permission:** view file linksdiff --git a/frontend/src/global_styles/content/_forms.sass b/frontend/src/global_styles/content/_forms.sassindex 37e1927786e..ac6f30a814b 100644--- a/frontend/src/global_styles/content/_forms.sass+++ b/frontend/src/global_styles/content/_forms.sass@@ -518,6 +518,15 @@ fieldset.form--fieldset&.-with-bottom-spacingmargin-bottom: 1rem+.form--field-error+ @extend %form--field-after-container+ font-style: italic+ max-width: 500px+ color: var(--content-form-error-color)++ &.-with-bottom-spacing+ margin-bottom: 1rem+.form--inline-instructionsfont-style: italicdisplay: inlinediff --git a/frontend/src/stimulus/controllers/dynamic/project-storage-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/project-storage-form.controller.tsindex 5163ddafec4..20a39cf5e6b 100644--- a/frontend/src/stimulus/controllers/dynamic/project-storage-form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/project-storage-form.controller.ts@@ -43,6 +43,7 @@ export default class ProjectStorageFormController extends Controller {static targets = ['projectFolderSection','projectFolderIdInput',+ 'projectFolderIdValidation','selectedFolderText','storage','storageSelector',@@ -51,15 +52,12 @@ export default class ProjectStorageFormController extends Controller {static values = {folderMode: String,placeholderFolderName: String,- emptyFolderNameValidation: String,};declare folderModeValue:string;declare placeholderFolderNameValue:string;- declare emptyFolderNameValidationValue:string;-declare readonly storageTargets:HTMLElement[];declare readonly storageSelectorTarget:HTMLSelectElement;@@ -70,6 +68,8 @@ export default class ProjectStorageFormController extends Controller {declare readonly projectFolderIdInputTarget:HTMLInputElement;+ declare readonly projectFolderIdValidationTarget:HTMLSpanElement;+declare readonly selectedFolderTextTarget:HTMLSpanElement;declare readonly hasProjectFolderSectionTarget:boolean;@@ -101,6 +101,7 @@ export default class ProjectStorageFormController extends Controller {filter((modal) => modal.submitted),).subscribe((modal) => {+ this.projectFolderIdValidationTarget.style.display = 'none';this.selectedFolderTextTarget.innerText = modal.location.name;this.projectFolderIdInputTarget.value = modal.location.id as string;});diff --git a/lib/api/decorators/query_params_representer.rb b/lib/api/decorators/query_params_representer.rbindex 1ead401fe3c..e18a30dd935 100644--- a/lib/api/decorators/query_params_representer.rb+++ b/lib/api/decorators/query_params_representer.rb@@ -46,6 +46,15 @@ module APIto_h.to_jsonend+ ##+ # Output as query params used for directly using in URL queries.+ # Outputs columns[]=A,columns[]=B due to Rails query output.+ def to_url_query(merge_params: {})+ to_h+ .merge(merge_params.symbolize_keys)+ .to_query+ end+def to_h(*_args)p = default_hashdiff --git a/lib/api/v3/queries/query_params_representer.rb b/lib/api/v3/queries/query_params_representer.rbindex 4605afd3aa6..9b37b15f5d9 100644--- a/lib/api/v3/queries/query_params_representer.rb+++ b/lib/api/v3/queries/query_params_representer.rb@@ -43,15 +43,6 @@ module APIto_h(column_key: :'columns[]').to_jsonend- ##- # Output as query params used for directly using in URL queries.- # Outputs columns[]=A,columns[]=B due to Rails query output.- def to_url_query(merge_params: {})- to_h- .merge(merge_params.symbolize_keys)- .to_query- end-def to_h(column_key: :columns)p = superdiff --git a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rbindex d2004070d04..903f1d7654f 100644--- a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb@@ -73,7 +73,7 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController.result# Calculate the list of available Storage objects, subtracting already enabled storages.- @available_storages = Storages::ProjectStorages::CreateContract.new(@project_storage, current_user).assignable_storages+ @available_storages = available_storages# Show the HTML form to create the object.render '/storages/project_settings/new'@@ -91,11 +91,13 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController# Create success/error messages to the userif service_result.success?flash[:notice] = I18n.t(:notice_successful_create)+ redirect_to project_settings_projects_storages_pathelse- flash[:error] = service_result.message || I18n.t('notice_internal_server_error')+ @errors = service_result.errors+ @project_storage = service_result.result+ @available_storages = available_storages+ render '/storages/project_settings/new'end-- redirect_to project_settings_projects_storages_path # Redirect: Project -> Settings -> File Storagesend# Edit page is very similar to new page, except that we don't need to set@@ -121,10 +123,11 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsControllerif service_result.success?flash[:notice] = I18n.t(:notice_successful_update)- redirect_to project_settings_projects_storages_path # Redirect: Project -> Settings -> File Storages+ redirect_to project_settings_projects_storages_pathelse@errors = service_result.errors- render :edit+ @project_storage = @object+ render '/storages/project_settings/edit'endend@@ -184,6 +187,7 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsControllerendredirect_back(fallback_location: project_settings_projects_storages_path(project_id: project.id))end+# rubocop:enable Metrics/AbcSizeprivate@@ -198,4 +202,8 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController.to_h.reverse_merge(project_id: @project.id)end++ def available_storages+ Storages::ProjectStorages::CreateContract.new(@project_storage, current_user).assignable_storages+ endenddiff --git a/modules/storages/app/views/storages/project_settings/_form.html.erb b/modules/storages/app/views/storages/project_settings/_form.html.erbindex 679f3bbd132..61094fe1434 100644--- a/modules/storages/app/views/storages/project_settings/_form.html.erb+++ b/modules/storages/app/views/storages/project_settings/_form.html.erb@@ -30,13 +30,12 @@ See COPYRIGHT and LICENSE files for more details.<% content_controller 'project-storage-form',dynamic: true,'project-storage-form-folder-mode-value': @project_storage.project_folder_mode,- 'project-storage-form-placeholder-folder-name-value': t(:"storages.label_no_selected_folder"),- 'project-storage-form-empty-folder-name-validation-value': t(:"storages.label_empty_project_folder_validation")+ 'project-storage-form-placeholder-folder-name-value': t(:"storages.label_no_selected_folder")%><div class="form--field -required"><% case action_name %>- <% when 'new' %>+ <% when 'new', 'create' %><%= f.select :storage_id,(@available_storages.map do |storage|[@@ -56,6 +55,7 @@ See COPYRIGHT and LICENSE files for more details.]end),{+ class: '-bold',selected: @available_storages.first.id.to_s,container_class: '-slim'},@@ -69,7 +69,7 @@ See COPYRIGHT and LICENSE files for more details..</span><% end %>- <% when 'edit' %>+ <% when 'edit', 'update' %><%= f.label :storage_id, class: "form--label -bold" do %><%= t(:"storages.label_storage") %><% end %>@@ -136,7 +136,6 @@ See COPYRIGHT and LICENSE files for more details.data-project-storage-form-target="projectFolderSection"><%= f.hidden_field :project_folder_id,- required: true,data: {'project-storage-form-target': "projectFolderIdInput"} %>@@ -153,6 +152,14 @@ See COPYRIGHT and LICENSE files for more details.data-project-storage-form-target="selectedFolderText"></span></div>+ <% if @errors.present? && @errors.any? %>+ <%= content_tag :span,+ t(:"storages.instructions.empty_project_folder_validation"),+ class: 'form--field-error -with-bottom-spacing',+ data: {+ 'project-storage-form-target': "projectFolderIdValidation"+ } %>+ <% end %></div><% end %>diff --git a/modules/storages/app/views/storages/project_settings/edit.html.erb b/modules/storages/app/views/storages/project_settings/edit.html.erbindex 83c1b017340..18f885750d3 100644--- a/modules/storages/app/views/storages/project_settings/edit.html.erb+++ b/modules/storages/app/views/storages/project_settings/edit.html.erb@@ -32,8 +32,6 @@ See COPYRIGHT and LICENSE files for more details.<%= toolbar title: t("storages.page_titles.project_settings.edit") %><%= labelled_tabular_form_for @project_storage, url: project_settings_projects_storage_path(project_id: @project_storage.project, id: @project_storage) do |f| -%>- <%= error_messages_for_contract @project_storage, @errors %>-<section class="form--section"><%= render partial: '/storages/project_settings/form',locals: { f: f, available_storages: @available_storages, submit_button_label: t('button_save') }diff --git a/modules/storages/app/views/storages/project_settings/new.html.erb b/modules/storages/app/views/storages/project_settings/new.html.erbindex 9c374a32026..c2c8abf6ffa 100644--- a/modules/storages/app/views/storages/project_settings/new.html.erb+++ b/modules/storages/app/views/storages/project_settings/new.html.erb@@ -32,8 +32,6 @@ See COPYRIGHT and LICENSE files for more details.<%= toolbar title: t("storages.page_titles.project_settings.new") %><%= labelled_tabular_form_for @project_storage, url: project_settings_projects_storages_path do |f| -%>- <%= error_messages_for_contract @project_storage, @errors %>-<section class="form--section"><% if @available_storages.any? %><%= render partial: '/storages/project_settings/form',diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex e501e16648b..2612a98cada 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -67,6 +67,7 @@ en:host: "Please add the host address of your storage including the https://. It should not be longer than 255 characters."no_storage_set_up: "There are no file storages set up yet."no_specific_folder: "By default, each user will start at their own home folder when they upload a file."+ empty_project_folder_validation: "Selecting a folder is mandatory to proceed."existing_manual_folder: >You can designate an existing folder as the root folder for this project. The permissions are however not automatically managed, theadministrator needs to manually ensure relevant users have access. The selected folder can be used by multiple projects.@@ -105,7 +106,6 @@ en:label_existing_manual_folder: "Existing folder with manually managed permissions"label_no_specific_folder: "No specific folder"label_no_selected_folder: "No selected folder"- label_empty_project_folder_validation: "Selecting a folder is mandatory to proceed"label_storage: "Storage"label_storages: "Storages"no_results: "No storages set up yet."diff --git a/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb b/modules/storages/lib/api/v3/project_storages/project_storage_representer.rbindex 7f32da802d6..3582a75628e 100644--- a/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb+++ b/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb@@ -38,7 +38,6 @@ module API::V3::ProjectStoragesproperty :iddate_time_property :created_atdate_time_property :updated_at- property :project_folder_idproperty :project_folder_modelink :projectFolder dodiff --git a/modules/storages/lib/api/v3/project_storages/project_storages_api.rb b/modules/storages/lib/api/v3/project_storages/project_storages_api.rbindex a96c2e814f8..a7393998e78 100644--- a/modules/storages/lib/api/v3/project_storages/project_storages_api.rb+++ b/modules/storages/lib/api/v3/project_storages/project_storages_api.rb@@ -48,6 +48,7 @@ module API::V3::ProjectStorages::API::V3::ProjectStorages::ProjectStorageCollectionRepresenter.new(results,self_link: api_v3_paths.project_storages,+ query: API::Decorators::QueryParamsRepresenter.new(query).to_h,current_user:)end