From 116ead698b65f5cb1203c3e5796f10a2245ac40f Mon Sep 17 00:00:00 2001 From: argirok Date: Tue, 1 Aug 2023 12:25:46 +0300 Subject: [PATCH] Linking: check the claim field for its community before add it in the list of the communities that can be claimed. Allow all for connect and claim curators --- .../claimContextSearchForm.component.ts | 31 ++++++++++++++----- connect/communities/communities.service.ts | 2 ++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/claims/claim-utils/claimContextSearchForm.component.ts b/claims/claim-utils/claimContextSearchForm.component.ts index 95289d97..d48540e8 100644 --- a/claims/claim-utils/claimContextSearchForm.component.ts +++ b/claims/claim-utils/claimContextSearchForm.component.ts @@ -7,8 +7,8 @@ import {LoginErrorCodes} from '../../login/utils/guardHelper.class'; import {EnvProperties} from '../../utils/properties/env-properties'; import {Subscriber} from "rxjs"; import {OpenaireEntities} from "../../utils/properties/searchFields"; -import {CommunityService} from "../../connect/community/community.service"; import {CommunitiesService} from "../../connect/communities/communities.service"; +import {UserManagementService} from "../../services/user-management.service"; declare var UIkit: any; @@ -49,9 +49,14 @@ export class ClaimContextSearchFormComponent { keyword = ""; subscriptions = []; communityLogos = {}; + communityIds = []; + user = null; ngOnInit() { this.entitiesSelectOptions = this.showOptions.selectOptions; //get community logos + this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { + this.user = user; + this.subscriptions.push(this._communitiesService.getCommunities(this.properties, this.properties.communityAPI+"/communities/").subscribe( communitiesResults => { if(communitiesResults!=null) { @@ -61,6 +66,13 @@ export class ClaimContextSearchFormComponent { this.communityLogos[community.communityId] = community; } } + this.communityIds = communitiesResults.filter(community => { + return community.claim == "all" || + Session.isCommunityCurator(this.user) || + Session.isClaimsCurator(this.user) || + (community.claim == "membersOnly" && Session.isSubscribedTo("community", community.communityId,this.user)) || + (community.claim == "managersOnly" && Session.isManager("community", community.communityId,this.user)) + }).map(community => community.communityId); this.getCommunities(); } }, @@ -68,6 +80,10 @@ export class ClaimContextSearchFormComponent { this.getCommunities(); } )); + + }, error => { + + })); } ngOnDestroy() { @@ -77,7 +93,7 @@ export class ClaimContextSearchFormComponent { } }); } - constructor(private _contextService: ContextsService, private router: Router, private _communitiesService: CommunitiesService) { + constructor(private _contextService: ContextsService, private router: Router, private _communitiesService: CommunitiesService, private userManagementService: UserManagementService,) { } @@ -172,15 +188,16 @@ export class ClaimContextSearchFormComponent { } else { this.loading = true; - this.subscriptions.push(this._contextService.getPublicCommunitiesByState().subscribe( + this.subscriptions.push(this._contextService.getCommunitiesByState().subscribe( data => { - this.communities = data; - console.log(this.communities) + this.communities = data.filter(community => { + return this.communityIds.indexOf(community.id) != -1 + }); if (this.communities.length > 0) { - this.communities.sort((n1, n2) => n1.label > n2.label); + this.communities.sort((n1, n2) => n1.title > n2.title); } this.loading = false; - if (this.communityId != null) { + if (this.communityId != null && this.communityIds.indexOf(this.communityId) != -1) { //preselect community this.selectedCommunityId = this.communityId; for (let i = 0; i < this.communities.length; i++) { diff --git a/connect/communities/communities.service.ts b/connect/communities/communities.service.ts index c16b439a..05f427a6 100644 --- a/connect/communities/communities.service.ts +++ b/connect/communities/communities.service.ts @@ -56,6 +56,8 @@ export class CommunitiesService { result['description'] = resData.description; result['date'] = resData.creationDate; result['status'] = 'all'; + result['claim'] = resData.claim; + result['membership'] = resData.membership; if (resData.hasOwnProperty('status')) { result['status'] = resData.status; result.validateStatus();