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 {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++) {

View File

@ -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();