From f94cef013698f5fa5d9ee2732031fdb3b0935eb8 Mon Sep 17 00:00:00 2001 From: Santiago Fierro Date: Wed, 17 Sep 2025 10:25:28 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Agrego=20condici=C3=B3n=20para=20que=20pued?= =?UTF-8?q?an=20imprimir=20un=20certificado=20de=20dp=C3=B3sito=20los=20qu?= =?UTF-8?q?e=20pueden=20editar=20el=20item=20y=20el=20submmiter=20del=20it?= =?UTF-8?q?em?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/core/roles/role.service.ts | 74 ++++++++++++++++++- .../providers/dso-print-certificate.menu.ts | 7 +- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/app/core/roles/role.service.ts b/src/app/core/roles/role.service.ts index 365a5cbbb31..b916e7ade02 100644 --- a/src/app/core/roles/role.service.ts +++ b/src/app/core/roles/role.service.ts @@ -2,11 +2,23 @@ import { Injectable } from '@angular/core'; import { Observable, of, + combineLatest } from 'rxjs'; -import { distinctUntilChanged } from 'rxjs/operators'; +import { distinctUntilChanged, map, switchMap, catchError } from 'rxjs/operators'; import { CollectionDataService } from '../data/collection-data.service'; import { RoleType } from './role-types'; +import { ItemDataService } from '../data/item-data.service'; +import { EPerson } from '../eperson/models/eperson.model'; +import { AuthService } from '../auth/auth.service'; +import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; +import { Item } from '../shared/item.model'; +import { itemLinksToFollow } from 'src/app/shared/utils/relation-query.utils'; +import { LinkService } from '../cache/builders/link.service'; +import { followLink } from '../../shared/utils/follow-link-config.model'; +import { DSpaceObject } from '../shared/dspace-object.model'; +import { HttpClient } from '@angular/common/http'; + /** * A service that provides methods to identify user role. @@ -19,7 +31,13 @@ export class RoleService { * * @param {CollectionDataService} collectionService */ - constructor(private collectionService: CollectionDataService) { + constructor( + private collectionService: CollectionDataService, + private itemDataService: ItemDataService, + private auth: AuthService, + private linkService: LinkService, + private http: HttpClient, + ) { } /** @@ -31,6 +49,58 @@ export class RoleService { ); } + /** + * Retrieve the current user + */ + private getCurrentUser(): Observable { + return this.auth.isAuthenticated().pipe( + switchMap((authenticated) => { + if (authenticated) { + return this.auth.getAuthenticatedUserFromStore(); + } else { + return of(undefined); + } + }), + ); + + } + + + isSubmitterOfItem(dso: DSpaceObject): Observable { + return combineLatest([ + this.itemDataService.findById(dso.id), + this.getCurrentUser() + ]).pipe( + switchMap(([itemRD, currentUser]) => { + if (!currentUser || !itemRD.hasSucceeded) { + return of(false); + } + + // Get the item information + const item = itemRD.payload; + // The submitter is not a followLink for Item, so we get it manually + const submitter_link = (item._links as any).submitter; + + if (submitter_link?.href) { + // Call to the submitter link to get the EPerson + return this.http.get(submitter_link.href).pipe( + map(submitter => { + + const isSubmitter = submitter.uuid === currentUser.uuid; + + return isSubmitter; + }), + catchError(error => { + return of(false); + }) + ); + } + return of(false); + }) + ); + } + + /** * Check if current user is a controller */ diff --git a/src/app/shared/menu/providers/dso-print-certificate.menu.ts b/src/app/shared/menu/providers/dso-print-certificate.menu.ts index 8b39945486d..b18f7b6eb31 100644 --- a/src/app/shared/menu/providers/dso-print-certificate.menu.ts +++ b/src/app/shared/menu/providers/dso-print-certificate.menu.ts @@ -21,6 +21,7 @@ import { LinkMenuItemModel } from '../menu-item/models/link.model'; import { MenuItemType } from '../menu-item-type.model'; import { PartialMenuSection } from '../menu-provider.model'; import { DSpaceObjectPageMenuProvider } from './helper-providers/dso.menu'; +import { RoleService } from '../../../core/roles/role.service'; /** * Menu provider to create the "Edit" option in the DSO edit menu @@ -29,6 +30,7 @@ import { DSpaceObjectPageMenuProvider } from './helper-providers/dso.menu'; export class DSpaceObjectPrintCertificateMenuProvider extends DSpaceObjectPageMenuProvider { constructor( protected authorizationDataService: AuthorizationDataService, + protected roleService: RoleService, ) { super(); } @@ -36,11 +38,12 @@ export class DSpaceObjectPrintCertificateMenuProvider extends DSpaceObjectPageMe public getSectionsForContext(dso: DSpaceObject): Observable { return combineLatest([ this.authorizationDataService.isAuthorized(FeatureID.CanEditMetadata, dso.self), + this.roleService.isSubmitterOfItem(dso), ]).pipe( - map(([canEditItem]) => { + map(([canEditItem, isSubmitter]) => { return [ { - visible: canEditItem, + visible: canEditItem || isSubmitter, // Show if user can edit OR is submitter model: { type: MenuItemType.LINK, text: this.getDsoType(dso) + '.page.print', From 1f382880303daabcaf7f6ec81fab3c999a89ea5f Mon Sep 17 00:00:00 2001 From: Santiago Fierro Date: Thu, 18 Sep 2025 08:10:49 -0300 Subject: [PATCH 2/2] Agrego submitter a los linkds de Item --- src/app/core/roles/role.service.ts | 2 +- src/app/core/shared/item.model.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/core/roles/role.service.ts b/src/app/core/roles/role.service.ts index b916e7ade02..d95a4a27c8a 100644 --- a/src/app/core/roles/role.service.ts +++ b/src/app/core/roles/role.service.ts @@ -79,7 +79,7 @@ export class RoleService { // Get the item information const item = itemRD.payload; // The submitter is not a followLink for Item, so we get it manually - const submitter_link = (item._links as any).submitter; + const submitter_link = item._links.submitter; if (submitter_link?.href) { // Call to the submitter link to get the EPerson diff --git a/src/app/core/shared/item.model.ts b/src/app/core/shared/item.model.ts index d6066f098c0..b58539662e7 100644 --- a/src/app/core/shared/item.model.ts +++ b/src/app/core/shared/item.model.ts @@ -88,6 +88,7 @@ export class Item extends DSpaceObject implements ChildHALResource, HandleObject thumbnail: HALLink; accessStatus: HALLink; identifiers: HALLink; + submitter?: HALLink; self: HALLink; };