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

Add fetching of shares

Klaus Zanders448a9dd8c0ab
diff --git a/frontend/src/app/features/work-packages/directives/query-space/isolated-query-space.ts b/frontend/src/app/features/work-packages/directives/query-space/isolated-query-space.ts
index a83e3377f79..8c2a55df175 100644
--- a/frontend/src/app/features/work-packages/directives/query-space/isolated-query-space.ts
+++ b/frontend/src/app/features/work-packages/directives/query-space/isolated-query-space.ts
@@ -19,6 +19,7 @@ import { QueryFilterInstanceSchemaResource } from 'core-app/features/hal/resourc
import { QueryFormResource } from 'core-app/features/hal/resources/query-form-resource';
import { QuerySortByResource } from 'core-app/features/hal/resources/query-sort-by-resource';
import { QueryGroupByResource } from 'core-app/features/hal/resources/query-group-by-resource';
+import { ShareResource } from 'core-app/features/hal/resources/share-resource';
@Injectable()
export class IsolatedQuerySpace extends StatesGroup {
@@ -62,6 +63,9 @@ export class IsolatedQuerySpace extends StatesGroup {
// Required work packages to be rendered by hierarchy mode + relation columns
additionalRequiredWorkPackages = input<null>();
+ // Cached shares for work packages
+ workPackageSharesCache = input<ShareResource[]>();
+
// Input state that emits whenever table services have initialized
initialized = input<unknown>();
@@ -80,6 +84,6 @@ export class IsolatedQuerySpace extends StatesGroup {
filters: input<QueryFilterInstanceSchemaResource[]>(),
// Display of the WP results
- displayRepresentation: input<WorkPackageDisplayRepresentationValue|null>(),
+ displayRepresentation: input<WorkPackageDisplayRepresentationValue | null>(),
};
}
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-additional-elements.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-additional-elements.service.ts
index 3987c216ed9..83fb2490b12 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-additional-elements.service.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-additional-elements.service.ts
@@ -42,6 +42,8 @@ import { RelationResource } from 'core-app/features/hal/resources/relation-resou
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
import { WorkPackageViewHierarchiesService } from './wp-view-hierarchy.service';
import { WorkPackageViewColumnsService } from './wp-view-columns.service';
+import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
+import { ShareResource } from 'core-app/features/hal/resources/share-resource';
@Injectable()
export class WorkPackageViewAdditionalElementsService {
@@ -59,11 +61,13 @@ export class WorkPackageViewAdditionalElementsService {
public initialize(query:QueryResource, results:WorkPackageCollectionResource):void {
const rows = results.elements;
+ const workPackageIds = rows.map((el) => el.id!);
// Add relations to the stack
Promise.all([
- this.requireInvolvedRelations(rows.map((el) => el.id!)),
+ this.requireInvolvedRelations(workPackageIds),
this.requireHierarchyElements(rows),
+ this.requireWorkPackageShares(workPackageIds),
this.requireSumsSchema(results),
]).then((results:string[][]) => {
this.loadAdditional(_.flatten(results));
@@ -110,7 +114,7 @@ export class WorkPackageViewAdditionalElementsService {
return Promise.resolve([]);
}
- const resultIds = rows.map((el:WorkPackageResource) => (el.id as string|number).toString());
+ const resultIds = rows.map((el:WorkPackageResource) => (el.id as string | number).toString());
const ids = _.flatten(rows.map((el) => el.ancestorIds))
.filter((id) => !resultIds.includes(id));
@@ -143,4 +147,24 @@ export class WorkPackageViewAdditionalElementsService {
return Promise.resolve([]);
}
+
+ private requireWorkPackageShares(wpIds:string[]):Promise<string[]> {
+ if (!this.wpTableColumns.hasShareColumn()) { return Promise.resolve([]); }
+
+ const filters = new ApiV3FilterBuilder()
+ .add('entityType', '=', ['WorkPackage'])
+ .add('entityId', '=', wpIds);
+
+ this
+ .apiV3Service
+ .shares
+ .filtered(filters, { pageSize: '-1' })
+ .get()
+ .subscribe(({ elements }) => {
+ const shares = elements as ShareResource[];
+ this.querySpace.workPackageSharesCache.putValue(shares);
+ });
+
+ return Promise.resolve([]);
+ }
}
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service.ts
index 089e2987cae..7e90d7bb12a 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service.ts
@@ -89,7 +89,7 @@ export class WorkPackageViewColumnsService extends WorkPackageQueryStateService<
* Returns whether the current set of columns include shares
*/
public hasShareColumn() {
- return !!_.find(this.getColumns(), (c) => c.id === 'sharedWithUser');
+ return !!_.find(this.getColumns(), (c) => c.id === 'sharedWithUsers');
}
/**