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

This commit is contained in:
argirok 2023-08-01 12:25:46 +03:00
parent 8310eddd92
commit 116ead698b
2 changed files with 26 additions and 7 deletions

View File

@ -7,8 +7,8 @@ import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
import {EnvProperties} from '../../utils/properties/env-properties'; import {EnvProperties} from '../../utils/properties/env-properties';
import {Subscriber} from "rxjs"; import {Subscriber} from "rxjs";
import {OpenaireEntities} from "../../utils/properties/searchFields"; import {OpenaireEntities} from "../../utils/properties/searchFields";
import {CommunityService} from "../../connect/community/community.service";
import {CommunitiesService} from "../../connect/communities/communities.service"; import {CommunitiesService} from "../../connect/communities/communities.service";
import {UserManagementService} from "../../services/user-management.service";
declare var UIkit: any; declare var UIkit: any;
@ -49,9 +49,14 @@ export class ClaimContextSearchFormComponent {
keyword = ""; keyword = "";
subscriptions = []; subscriptions = [];
communityLogos = {}; communityLogos = {};
communityIds = [];
user = null;
ngOnInit() { ngOnInit() {
this.entitiesSelectOptions = this.showOptions.selectOptions; this.entitiesSelectOptions = this.showOptions.selectOptions;
//get community logos //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( this.subscriptions.push(this._communitiesService.getCommunities(this.properties, this.properties.communityAPI+"/communities/").subscribe(
communitiesResults => { communitiesResults => {
if(communitiesResults!=null) { if(communitiesResults!=null) {
@ -61,6 +66,13 @@ export class ClaimContextSearchFormComponent {
this.communityLogos[community.communityId] = community; 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(); this.getCommunities();
} }
}, },
@ -69,6 +81,10 @@ export class ClaimContextSearchFormComponent {
} }
)); ));
}, error => {
}));
} }
ngOnDestroy() { ngOnDestroy() {
this.subscriptions.forEach(subscription => { this.subscriptions.forEach(subscription => {
@ -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 { } else {
this.loading = true; this.loading = true;
this.subscriptions.push(this._contextService.getPublicCommunitiesByState().subscribe( this.subscriptions.push(this._contextService.getCommunitiesByState().subscribe(
data => { data => {
this.communities = data; this.communities = data.filter(community => {
console.log(this.communities) return this.communityIds.indexOf(community.id) != -1
});
if (this.communities.length > 0) { 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; this.loading = false;
if (this.communityId != null) { if (this.communityId != null && this.communityIds.indexOf(this.communityId) != -1) {
//preselect community //preselect community
this.selectedCommunityId = this.communityId; this.selectedCommunityId = this.communityId;
for (let i = 0; i < this.communities.length; i++) { for (let i = 0; i < this.communities.length; i++) {

View File

@ -56,6 +56,8 @@ export class CommunitiesService {
result['description'] = resData.description; result['description'] = resData.description;
result['date'] = resData.creationDate; result['date'] = resData.creationDate;
result['status'] = 'all'; result['status'] = 'all';
result['claim'] = resData.claim;
result['membership'] = resData.membership;
if (resData.hasOwnProperty('status')) { if (resData.hasOwnProperty('status')) {
result['status'] = resData.status; result['status'] = resData.status;
result.validateStatus(); result.validateStatus();