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

[#53672] Hide attachements on work creation form.

Pavel Balashou3afba3e18063
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html
index ed9b2fba0f5..c063526da05 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html
@@ -4,7 +4,7 @@
<section
class="op-tab-content--tab-section"
[ngClass]="{ 'op-tab-content--tab-section_no-header': (showAttachmentHeader$ | async) === false }"
- *ngIf="!this.workPackage.hideAttachments"
+ *ngIf="showAttachments"
data-test-selector="op-tab-content--tab-section"
>
<div
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
index f1a35d02757..79a105903b9 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
@@ -62,6 +62,8 @@ export class WorkPackageFilesTabComponent implements OnInit {
allowManageFileLinks$:Observable<boolean>;
+ showAttachments:boolean;
+
constructor(
private readonly i18n:I18nService,
private readonly currentUserService:CurrentUserService,
@@ -74,6 +76,7 @@ export class WorkPackageFilesTabComponent implements OnInit {
return;
}
+ this.showAttachments = !!this.workPackage.$links.attachments;
const canViewFileLinks = this.currentUserService.hasCapabilities$('file_links/view', project.id);
this.projectStorages = this
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.html b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.html
index b998cdd8a42..45c4b8367ab 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.html
@@ -122,7 +122,9 @@
*ngIf="isNewResource"
class="work-packages--storages"
>
- <div>
+ <div
+ *ngIf="this.workPackage.$links.attachments"
+ >
<div class="op-tab-content--header">
<span class="op-tab-content--header-text" [textContent]="text.attachments.label"></span>
</div>
diff --git a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-files-count.function.ts b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-files-count.function.ts
index 888b1c95ed7..56becc03a35 100644
--- a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-files-count.function.ts
+++ b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-files-count.function.ts
@@ -43,7 +43,7 @@ export function workPackageFilesCount(
return combineLatest(
[
- workPackage.hideAttachments ? new BehaviorSubject([]) : attachmentService.collection(workPackage.$links.attachments.href || ''),
+ workPackage.$links.attachments ? attachmentService.collection(workPackage.$links.attachments.href || '') : new BehaviorSubject([]),
fileLinkService.collection(workPackage.$links.fileLinks?.href || ''),
],
).pipe(
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts
index b03728f5215..77f03dc0934 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts
@@ -46,7 +46,7 @@ import {
WorkPackageNotificationService,
} from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
import {
- switchMap, take,
+ take,
} from 'rxjs/operators';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
@@ -184,8 +184,9 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
this.showStaticPagePath = this.PathHelper.workPackagePath(this.workPackageId);
// Fetch attachments of current work package
- const attachments = this.workPackage.attachments as unknown&{ href:string };
- this.attachmentsResourceService.fetchCollection(attachments.href).subscribe();
+ if (this.workPackage.$links.attachments) {
+ this.attachmentsResourceService.fetchCollection(this.workPackage.$links.attachments.href as string).subscribe();
+ }
if (this.workPackage.$links.fileLinks) {
this.fileLinkResourceService
diff --git a/lib/api/v3/attachments/attachable_representer_mixin.rb b/lib/api/v3/attachments/attachable_representer_mixin.rb
index 20fa5ba1be5..4dd49d46893 100644
--- a/lib/api/v3/attachments/attachable_representer_mixin.rb
+++ b/lib/api/v3/attachments/attachable_representer_mixin.rb
@@ -36,6 +36,8 @@ module API
included do
link :attachments do
+ next unless list_attachments?
+
{
href: attachments_by_resource
}
@@ -48,7 +50,7 @@ module API
next if represented.new_record?
{
- href: attachments_by_resource + "/prepare",
+ href: "#{attachments_by_resource}/prepare",
method: :post
}
end
@@ -69,6 +71,10 @@ module API
if: ->(*) { embed_links },
uncacheable: true
+ def list_attachments?
+ true
+ end
+
def attachments
::API::V3::Attachments::AttachmentCollectionRepresenter.new(attachment_set,
self_link: attachments_by_resource,
diff --git a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
index 4944fd97420..5dd5370716f 100644
--- a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
+++ b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
@@ -212,6 +212,14 @@ module API
location: :link,
writable: false
+ schema :attachments,
+ type: "AttachmentCollection",
+ required: false,
+ writable: false,
+ show_if: ->(*) do
+ !(represented.work_package.project.hide_attachments || Setting.hide_attachments)
+ end
+
schema_with_allowed_link :project,
type: "Project",
required: true,
@@ -224,12 +232,6 @@ module API
end
}
- schema_with_allowed_link :attachments,
- type: "AttachmentCollection",
- required: false,
- writable: false,
- href_callback: -> {}
-
schema_with_allowed_link :parent,
type: "WorkPackage",
required: false,
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb
index eff368af858..7aec2ab1a55 100644
--- a/lib/api/v3/work_packages/work_package_representer.rb
+++ b/lib/api/v3/work_packages/work_package_representer.rb
@@ -468,13 +468,6 @@ module API
status_id && status.is_readonly?
end
- property :hide_attachments,
- writable: false,
- render_nil: false,
- getter: ->(*) do
- project.hide_attachments || Setting.hide_attachments
- end
-
associated_resource :category
associated_resource :type
@@ -587,6 +580,10 @@ module API
super
end
+ def list_attachments?
+ !(represented.project.hide_attachments || Setting.hide_attachments)
+ end
+
# Permissions
def current_user_watcher?
@current_user_watcher ||= represented.watchers.any? { |w| w.user_id == current_user.id }
diff --git a/modules/storages/app/views/storages/project_settings/index.html.erb b/modules/storages/app/views/storages/project_settings/index.html.erb
index a193324174b..94f63778617 100644
--- a/modules/storages/app/views/storages/project_settings/index.html.erb
+++ b/modules/storages/app/views/storages/project_settings/index.html.erb
@@ -66,7 +66,7 @@ end
render(Primer::Alpha::ToggleSwitch.new(src: set_hide_attachments_project_path(@project),
csrf_token: form_authenticity_token,
status_label_position: :end,
- checked: @project.hide_attachments,))
+ checked: [email protected]_attachments))
end
end
l.with_row do