[master | DONE]: Add buttons for manage and sandbox in all monitors and align sandbox guard to include members also.

This commit is contained in:
Konstantinos Triantafyllou 2024-04-08 18:41:49 +03:00
parent e6fe8c7390
commit ff86fb98f1
6 changed files with 200 additions and 31 deletions

View File

@ -14,6 +14,9 @@ import {OpenaireEntities} from "../openaireLibrary/utils/properties/searchFields
import {RouterHelper} from "../openaireLibrary/utils/routerHelper.class";
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
import {ConfigurationService} from "../openaireLibrary/utils/configuration/configuration.service";
import {Session} from "../openaireLibrary/login/utils/helper.class";
import {properties as beta} from "../../environments/environment.beta";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
@Component({
selector: 'national',
@ -32,7 +35,7 @@ import {ConfigurationService} from "../openaireLibrary/utils/configuration/confi
</div>
</div>
<div class="uk-banner-footer">
<div class="uk-container uk-container-large">
<div class="uk-container uk-container-large uk-flex uk-flex-between">
<ul class="uk-banner-tab uk-padding-small uk-padding-remove-vertical">
<li [class.uk-active]="!isSearch">
<a [routerLink]="'/national'">{{entities.stakeholder}}</a>
@ -42,6 +45,14 @@ import {ConfigurationService} from "../openaireLibrary/utils/configuration/confi
Browse {{openaireEntities.RESULTS}}</a>
</li>
</ul>
<div *ngIf="!isMobile" class="uk-margin-large-right uk-flex uk-flex-middle">
<a *ngIf="isManager" [routerLink]="adminLink" target="_blank" class="uk-button uk-flex uk-flex-middle uk-margin-small-right">
Manage
</a>
<a *ngIf="isMember" [href]="sandboxLink" target="_blank" class="uk-button uk-flex uk-flex-middle uk-margin-small-right">
Sandbox
</a>
</div>
</div>
</div>
</div>
@ -60,10 +71,12 @@ import {ConfigurationService} from "../openaireLibrary/utils/configuration/confi
export class NationalComponent extends StakeholderBaseComponent implements OnInit {
stakeholder: Stakeholder;
loading: boolean = true;
isMobile: boolean = false;
isSearch: boolean = false;
openaireEntities = OpenaireEntities;
constructor(private stakeholderService: StakeholderService,
private userManagementService: UserManagementService,
private layoutService: LayoutService,
protected _router: Router,
protected _route: ActivatedRoute,
@ -81,6 +94,9 @@ export class NationalComponent extends StakeholderBaseComponent implements OnIni
ngOnInit() {
this.layoutService.setRootClass('country');
this.subscriptions.push(this.layoutService.isMobile.subscribe(isMobile => {
this.isMobile = isMobile;
}));
this.stakeholderService.getStakeholder(this._route.snapshot.data.stakeholder).subscribe(stakeholder => {
this.stakeholder = stakeholder;
if(this.stakeholder) {
@ -98,4 +114,23 @@ export class NationalComponent extends StakeholderBaseComponent implements OnIni
super.ngOnDestroy();
this.layoutService.setRootClass(null);
}
get isManager() {
return Session.isPortalAdministrator(this.userManagementService.user) ||
Session.isCurator(this.stakeholder.type, this.userManagementService.user) ||
Session.isManager(this.stakeholder.type, this.stakeholder.alias, this.userManagementService.user);
}
get isMember() {
return this.isManager ||
Session.isMember(this.stakeholder.type, this.stakeholder.alias, this.userManagementService.user);
}
get adminLink() {
return "/admin/" + this.stakeholder.alias;
}
get sandboxLink() {
return beta.domain + '/national/';
}
}

View File

@ -15,6 +15,9 @@ import {SearchDataprovidersService} from "../openaireLibrary/services/searchData
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
import {ConfigurationService} from "../openaireLibrary/utils/configuration/configuration.service";
import {Irish} from "../shared/irish";
import {Session} from "../openaireLibrary/login/utils/helper.class";
import {properties as beta} from "../../environments/environment.beta";
@Component({
selector: 'repository',
@ -44,7 +47,7 @@ import {Irish} from "../shared/irish";
</div>
<div class="uk-text-small">
<!-- Website URL -->
<div *ngIf="stakeholder.details.websiteURL && stakeholder.details.websiteURL != ''" class="uk-margin-xsmall-bottom">
<div *ngIf="stakeholder.details?.websiteURL" class="uk-margin-xsmall-bottom">
<span>Website URL: </span>
<span class="uk-text-italic">
<a href="{{stakeholder.details.websiteURL}}" target="_blank" class="custom-external">
@ -53,7 +56,7 @@ import {Irish} from "../shared/irish";
</span>
</div>
<!-- OAI-PMH URL-->
<div *ngIf="stakeholder.details.OAIPMHURL && stakeholder.details.OAIPMHURL != ''" class="uk-margin-xsmall-bottom">
<div *ngIf="stakeholder.details?.OAIPMHURL" class="uk-margin-xsmall-bottom">
<span>OAI-PMH URL: </span>
<span class="uk-text-italic">
<a href="{{stakeholder.details.OAIPMHURL}}" target="_blank" class="custom-external">
@ -84,11 +87,17 @@ import {Irish} from "../shared/irish";
</a>
</li>
</ul>
<a *ngIf="isProvideManager" [href]="provideLink" target="_blank" class="uk-button uk-margin-large-right uk-flex uk-flex-middle">
<span class="uk-margin-small-right">Manage at</span>
<img class="uk-margin-xsmall-bottom" width="78" src="assets/common-assets/logo-small-provide.png">
<icon name="east" flex="true" class="uk-margin-small-left"></icon>
</a>
<div *ngIf="!isMobile" class="uk-margin-large-right uk-flex uk-flex-middle">
<a *ngIf="isManager" [routerLink]="adminLink" target="_blank" class="uk-button uk-flex uk-flex-middle uk-margin-small-right">
Manage
</a>
<a *ngIf="isMember" [href]="sandboxLink" target="_blank" class="uk-button uk-flex uk-flex-middle uk-margin-small-right">
Sandbox
</a>
<a *ngIf="isProvideManager && provideLink" [href]="provideLink" target="_blank" class="uk-button uk-flex uk-flex-middle">
<img class="uk-margin-xsmall-bottom" width="78" src="assets/common-assets/logo-small-provide.png">
</a>
</div>
</div>
</div>
</div>
@ -104,6 +113,7 @@ export class RepositoryComponent extends StakeholderBaseComponent implements OnI
stakeholder: Stakeholder;
alias: string;
isSearch: boolean = false;
isMobile: boolean = false;
loading: boolean = false;
openaireEntities = OpenaireEntities;
isProvideManager: boolean;
@ -131,6 +141,9 @@ export class RepositoryComponent extends StakeholderBaseComponent implements OnI
this.title = 'Repository Monitors';
this.description = 'Repository Monitors';
this.setMetadata();
this.subscriptions.push(this.layoutService.isMobile.subscribe(isMobile => {
this.isMobile = isMobile;
}));
this.params.subscribe(params => {
this.alias = params['stakeholder'];
if (this.alias) {
@ -154,6 +167,9 @@ export class RepositoryComponent extends StakeholderBaseComponent implements OnI
this.isProvideManager = !!user.role.find(role => role.includes(this.stakeholder.details.originalId.toUpperCase()));
}));
this.loading = false;
}, error => {
this.stakeholder.details = null;
this.loading = false;
}));
} else {
this.navigateToError();
@ -167,6 +183,25 @@ export class RepositoryComponent extends StakeholderBaseComponent implements OnI
});
}
get isManager() {
return Session.isPortalAdministrator(this.userManagementService.user) ||
Session.isCurator(this.stakeholder.type, this.userManagementService.user) ||
Session.isManager(this.stakeholder.type, this.stakeholder.alias, this.userManagementService.user);
}
get isMember() {
return this.isManager ||
Session.isMember(this.stakeholder.type, this.stakeholder.alias, this.userManagementService.user);
}
get adminLink() {
return "/admin/" + this.stakeholder.alias;
}
get sandboxLink() {
return beta.domain + '/repository/' + this.stakeholder.alias;
}
get provideLink() {
if(this.stakeholder?.details?.originalId) {
return 'https://' + (this.properties.environment != 'production'?'beta.':'') + 'provide.openaire.eu/repository/' + this.stakeholder.details.originalId + '/dashboard';

View File

@ -13,6 +13,9 @@ import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sideb
import {OpenaireEntities} from "../openaireLibrary/utils/properties/searchFields";
import {ConfigurationService} from "../openaireLibrary/utils/configuration/configuration.service";
import {Irish} from "../shared/irish";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
import {Session} from "../openaireLibrary/login/utils/helper.class";
import {properties as beta} from "../../environments/environment.beta";
@Component({
selector: 'rfo',
@ -45,7 +48,7 @@ import {Irish} from "../shared/irish";
</div>
</div>
<div *ngIf="stakeholder" class="uk-banner-footer">
<div class="uk-container uk-container-large">
<div class="uk-container uk-container-large uk-flex uk-flex-between">
<ul class="uk-banner-tab uk-padding-small uk-padding-remove-vertical">
<li [class.uk-active]="!isSearch">
<a [routerLink]="['./', stakeholder.alias]" [relativeTo]="_route"
@ -56,6 +59,14 @@ import {Irish} from "../shared/irish";
[relativeTo]="_route">Browse {{openaireEntities.RESULTS}}</a>
</li>
</ul>
<div *ngIf="!isMobile" class="uk-margin-large-right uk-flex uk-flex-middle">
<a *ngIf="isManager" [routerLink]="adminLink" target="_blank" class="uk-button uk-flex uk-flex-middle uk-margin-small-right">
Manage
</a>
<a *ngIf="isMember" [href]="sandboxLink" target="_blank" class="uk-button uk-flex uk-flex-middle uk-margin-small-right">
Sandbox
</a>
</div>
</div>
</div>
</div>
@ -71,10 +82,12 @@ export class RfoComponent extends StakeholderBaseComponent implements OnInit {
stakeholder: Stakeholder;
alias: string;
isSearch: boolean = false;
isMobile: boolean = false;
loading: boolean = false;
openaireEntities = OpenaireEntities;
constructor(private stakeholderService: StakeholderService,
private userManagementService: UserManagementService,
private layoutService: LayoutService,
private _customFilterService: CustomFilterService,
protected _router: Router,
@ -96,6 +109,9 @@ export class RfoComponent extends StakeholderBaseComponent implements OnInit {
this.title = 'RFOs';
this.description = 'RFOs';
this.setMetadata();
this.subscriptions.push(this.layoutService.isMobile.subscribe(isMobile => {
this.isMobile = isMobile;
}));
this.params.subscribe(params => {
this.alias = params['stakeholder'];
if (this.alias) {
@ -131,4 +147,23 @@ export class RfoComponent extends StakeholderBaseComponent implements OnInit {
this.layoutService.setRootClass(null);
this.setProperties(Irish.irishAdminToolsCommunity, Irish.irishAdminToolsPortalType, this.configurationService);
}
get isManager() {
return Session.isPortalAdministrator(this.userManagementService.user) ||
Session.isCurator(this.stakeholder.type, this.userManagementService.user) ||
Session.isManager(this.stakeholder.type, this.stakeholder.alias, this.userManagementService.user);
}
get isMember() {
return this.isManager ||
Session.isMember(this.stakeholder.type, this.stakeholder.alias, this.userManagementService.user);
}
get adminLink() {
return "/admin/" + this.stakeholder.alias;
}
get sandboxLink() {
return beta.domain + '/rfo/' + this.stakeholder.alias;
}
}

View File

@ -13,7 +13,9 @@ import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sideb
import {OpenaireEntities} from "../openaireLibrary/utils/properties/searchFields";
import {ConfigurationService} from "../openaireLibrary/utils/configuration/configuration.service";
import {Irish} from "../shared/irish";
import {Role} from "../openaireLibrary/login/utils/helper.class";
import {Role, Session} from "../openaireLibrary/login/utils/helper.class";
import {properties as beta} from "../../environments/environment.beta";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
@Component({
selector: 'rpo',
@ -46,7 +48,7 @@ import {Role} from "../openaireLibrary/login/utils/helper.class";
</div>
</div>
<div *ngIf="stakeholder" class="uk-banner-footer">
<div class="uk-container uk-container-large">
<div class="uk-container uk-container-large uk-flex uk-flex-between">
<ul class="uk-banner-tab uk-padding-small uk-padding-remove-vertical">
<li [class.uk-active]="!isSearch">
<a [routerLink]="['./', stakeholder.alias]" [relativeTo]="_route"
@ -57,6 +59,14 @@ import {Role} from "../openaireLibrary/login/utils/helper.class";
[relativeTo]="_route">Browse {{openaireEntities.RESULTS}}</a>
</li>
</ul>
<div *ngIf="!isMobile" class="uk-margin-large-right uk-flex uk-flex-middle">
<a *ngIf="isManager" [routerLink]="adminLink" target="_blank" class="uk-button uk-flex uk-flex-middle uk-margin-small-right">
Manage
</a>
<a *ngIf="isMember" [href]="sandboxLink" target="_blank" class="uk-button uk-flex uk-flex-middle uk-margin-small-right">
Sandbox
</a>
</div>
</div>
</div>
</div>
@ -71,12 +81,14 @@ import {Role} from "../openaireLibrary/login/utils/helper.class";
export class RpoComponent extends StakeholderBaseComponent implements OnInit {
stakeholder: Stakeholder;
alias: string;
isMobile: boolean = false;
isSearch: boolean = false;
loading: boolean = false;
openaireEntities = OpenaireEntities;
constructor(private stakeholderService: StakeholderService,
private _customFilterService: CustomFilterService,
private userManagementService: UserManagementService,
private layoutService: LayoutService,
protected _router: Router,
protected _route: ActivatedRoute,
@ -97,6 +109,9 @@ export class RpoComponent extends StakeholderBaseComponent implements OnInit {
this.title = 'RPOs';
this.description = 'RPOs';
this.setMetadata();
this.subscriptions.push(this.layoutService.isMobile.subscribe(isMobile => {
this.isMobile = isMobile;
}));
this.params.subscribe(params => {
this.alias = params['stakeholder'];
if (this.alias) {
@ -133,6 +148,25 @@ export class RpoComponent extends StakeholderBaseComponent implements OnInit {
this.layoutService.setRootClass(null);
this.setProperties(Irish.irishAdminToolsCommunity, Irish.irishAdminToolsPortalType, this.configurationService);
}
get isManager() {
return Session.isPortalAdministrator(this.userManagementService.user) ||
Session.isCurator(this.stakeholder.type, this.userManagementService.user) ||
Session.isManager(this.stakeholder.type, this.stakeholder.alias, this.userManagementService.user);
}
get isMember() {
return this.isManager ||
Session.isMember(this.stakeholder.type, this.stakeholder.alias, this.userManagementService.user);
}
get adminLink() {
return "/admin/" + this.stakeholder.alias;
}
get sandboxLink() {
return beta.domain + '/rpo/' + this.stakeholder.alias;
}
}

View File

@ -1,35 +1,64 @@
import {AdminDashboardGuard} from "../openaireLibrary/monitor-admin/utils/adminDashboard.guard";
import {Injectable} from "@angular/core";
import {ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree} from "@angular/router";
import {Observable} from "rxjs";
import {ActivatedRouteSnapshot, Router, RouterStateSnapshot, UrlTree} from "@angular/router";
import {Observable, zip} from "rxjs";
import {properties} from "../../environments/environment";
import {LoginErrorCodes} from "../openaireLibrary/login/utils/guardHelper.class";
import {map, tap} from "rxjs/operators";
import {map, take, tap} from "rxjs/operators";
import {Session} from "../openaireLibrary/login/utils/helper.class";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
@Injectable({
providedIn: 'root'
})
export class SandboxGuard extends AdminDashboardGuard {
export class SandboxGuard {
constructor(private userManagementService: UserManagementService,
private stakeholderService: StakeholderService,
private router: Router) {
}
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
let sandbox = properties.environment === 'beta';
if(childRoute.data['researcher'] && childRoute.params.stakeholder && sandbox) {
let errorCode = LoginErrorCodes.NOT_LOGIN;
let alias = childRoute.params.stakeholder;
return this.userManagementService.getUserInfo().pipe(map(user => {
if(user) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}
return user && (Session.isPortalAdministrator(user) ||
Session.isCurator('researcher', user) || user?.orcid === alias);
}), tap(authorized => {
if(!authorized){
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl':state.url}});
}
}));
let sandbox = properties.environment === 'development';
if (childRoute.data['researcher'] && childRoute.params.stakeholder && sandbox) {
return this.checkResearcher(state.url, childRoute.params.stakeholder);
} else {
return !sandbox || super.canActivateChild(childRoute, state);
return !sandbox || this.check(state.url, childRoute.data?.stakeholder?childRoute.data.stakeholder:childRoute.params.stakeholder);
}
}
checkResearcher(path: string, alias: string) {
let errorCode = LoginErrorCodes.NOT_LOGIN;
return this.userManagementService.getUserInfo().pipe(map(user => {
if (user) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}
return user && (Session.isPortalAdministrator(user) ||
Session.isCurator('researcher', user) || user?.orcid === alias);
}), tap(authorized => {
if (!authorized) {
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
}
}));
}
check(path: string, alias: string): Observable<boolean> | boolean {
let errorCode = LoginErrorCodes.NOT_LOGIN;
return zip(
this.userManagementService.getUserInfo(), this.stakeholderService.getStakeholder(alias)
).pipe(take(1), map(res => {
if (res[0]) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}
return res[0] && res[1] && (Session.isPortalAdministrator(res[0]) ||
Session.isCurator(res[1].type, res[0]) ||
Session.isManager(res[1].type, res[1].alias, res[0]) ||
Session.isMember(res[1].type, res[1].alias, res[0]))
}), tap(authorized => {
if (!authorized) {
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
}
}));
}
}

View File

@ -80,6 +80,7 @@
}
& .uk-button {
height: 100%;
background: @banner-tab-button-background;
border-radius: @banner-tab-button-border-radius;