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

Encapsulate restricted mentionable predicate fn

Kabiru Mwenja5e62896aa52a
diff --git a/frontend/src/app/core/path-helper/apiv3-paths.ts b/frontend/src/app/core/path-helper/apiv3-paths.ts
index 2c21c1ac787..4a656267cae 100644
--- a/frontend/src/app/core/path-helper/apiv3-paths.ts
+++ b/frontend/src/app/core/path-helper/apiv3-paths.ts
@@ -46,16 +46,12 @@ export class ApiV3Paths {
// that are members of that project:
filters.add('member', '=', [(workPackage.project as HalResource).id as string]);
} else {
- const isRestrictedAttributeValue = 'data-work-packages--activities-tab--restricted-comment-is-restricted-value';
- const addingCommentIsRestricted = document.getElementById('work-packages-activities-tab-add-comment-component')?.getAttribute(isRestrictedAttributeValue) === 'true';
- const editingCommentIsRestricted = document.querySelector('.work-packages-activities-tab-journals-item-component-edit')?.getAttribute(isRestrictedAttributeValue) === 'true';
-
// that are mentionable on the work package
- if (addingCommentIsRestricted || editingCommentIsRestricted) {
- filters.add('restricted_mentionable_on_work_package', '=', [workPackage.id.toString()]);
- } else {
- filters.add('mentionable_on_work_package', '=', [workPackage.id.toString()]);
- }
+ filters.add(
+ (this.isRestrictedMentionable() ? 'restricted_mentionable_on_work_package' : 'mentionable_on_work_package'),
+ '=',
+ [workPackage.id.toString()],
+ );
}
// That are users:
filters.add('type', '=', ['User', 'Group']);
@@ -67,4 +63,18 @@ export class ApiV3Paths {
return `${this.apiV3Base}/principals?${filters.toParams({ sortBy: '[["name","asc"]]', offset: '1', pageSize: '10' })}`;
}
+
+ /**
+ * Check if either adding or editing a comment is restricted, and thus
+ * the mentionable principals are to be restricted
+ *
+ * @returns {boolean}
+ */
+ private isRestrictedMentionable():boolean {
+ const isRestrictedAttributeValue = 'data-work-packages--activities-tab--restricted-comment-is-restricted-value';
+ const addingCommentIsRestricted = document.getElementById('work-packages-activities-tab-add-comment-component')?.getAttribute(isRestrictedAttributeValue) === 'true';
+ const editingCommentIsRestricted = document.querySelector('.work-packages-activities-tab-journals-item-component-edit')?.getAttribute(isRestrictedAttributeValue) === 'true';
+
+ return addingCommentIsRestricted || editingCommentIsRestricted;
+ }
}