[develop | DONE | ADDED] create CommunityAccess guard, replace isCommunity guard
This commit is contained in:
parent
9d54e942b7
commit
73b9a03d60
|
@ -2,7 +2,7 @@ import {NgModule} from '@angular/core';
|
|||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {OpenaireErrorPageComponent} from './error/errorPage.component';
|
||||
import {PageURLResolverComponent} from "./openaireLibrary/utils/pageURLResolver.component";
|
||||
import {IsCommunity} from "./openaireLibrary/connect/communityGuard/isCommunity.guard";
|
||||
import {CommunityAccessGuard} from "./utils/communityAccess.guard";
|
||||
|
||||
const routes: Routes = [
|
||||
// ORCID Pages
|
||||
|
@ -40,7 +40,7 @@ const routes: Routes = [
|
|||
{
|
||||
path: 'content',
|
||||
loadChildren: () => import('./content/contentPage.module').then(m => m.ContentPageModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'sdgs',
|
||||
|
@ -55,22 +55,22 @@ const routes: Routes = [
|
|||
{
|
||||
path: 'organizations',
|
||||
loadChildren: () => import('./htmlPages/organizations/organizationsPage.module').then(m => m.OrganizationsPageModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'publications',
|
||||
loadChildren: () => import('./htmlPages/publications/publications-page.module').then(m => m.PublicationsPageModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'projects',
|
||||
loadChildren: () => import('./htmlPages/projects/projectsPage.module').then(m => m.ProjectsPageModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'national-bulletins',
|
||||
loadChildren: () => import('./htmlPages/nationalBulletins/nationalBulletinsPage.module').then(m => m.NaionalBulletinPageModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'faqs',
|
||||
|
@ -88,24 +88,24 @@ const routes: Routes = [
|
|||
// {
|
||||
// path: '',
|
||||
// loadChildren: () => import('./htmlPages/featured/featuredPage.module').then(m => m.FeaturedPageModule),
|
||||
// data: {hasQuickContact: false}, canActivateChild: [IsCommunity],
|
||||
// data: {hasQuickContact: false}, canActivateChild: [CommunityAccessGuard],
|
||||
// },
|
||||
// {
|
||||
// path: '**',
|
||||
// loadChildren: () => import('./htmlPages/featured/featuredPage.module').then(m => m.FeaturedPageModule),
|
||||
// data: {hasQuickContact: false}, canActivateChild: [IsCommunity],
|
||||
// data: {hasQuickContact: false}, canActivateChild: [CommunityAccessGuard],
|
||||
// },
|
||||
// ]
|
||||
// },
|
||||
{
|
||||
path: 'curators',
|
||||
loadChildren: () => import('./curators/curators.module').then(m => m.CuratorsModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'subjects',
|
||||
loadChildren: () => import('./subjects/subjects.module').then(m => m.SubjectsModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'myCommunities',
|
||||
|
@ -114,7 +114,7 @@ const routes: Routes = [
|
|||
{
|
||||
path: 'develop',
|
||||
loadChildren: () => import('./develop/develop.module').then(m => m.DevelopModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
/** Testing Page for help contents */
|
||||
{path: 'helper-test', loadChildren: () => import('./helper-test/helper-test.module').then(m => m.HelperTestModule)},
|
||||
|
@ -122,41 +122,41 @@ const routes: Routes = [
|
|||
{
|
||||
path: 'search/result',
|
||||
loadChildren: () => import('./landingPages/result/libResult.module').then(m => m.LibResultModule),
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/publication',
|
||||
loadChildren: () => import('./landingPages/publication/libPublication.module').then(m => m.LibPublicationModule),
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/dataset',
|
||||
loadChildren: () => import('./landingPages/dataset/libDataset.module').then(m => m.LibDatasetModule),
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/software',
|
||||
loadChildren: () => import('./landingPages/software/libSoftware.module').then(m => m.LibSoftwareModule),
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/other', loadChildren: () => import('./landingPages/orp/libOrp.module').then(m => m.LibOrpModule),
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/project',
|
||||
loadChildren: () => import('./landingPages/project/libProject.module').then(m => m.LibProjectModule),
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/dataprovider',
|
||||
loadChildren: () => import('././landingPages/dataProvider/libDataProvider.module').then(m => m.LibDataProviderModule),
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/organization',
|
||||
loadChildren: () => import('./landingPages/organization/libOrganization.module').then(m => m.LibOrganizationModule),
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false, hasMenuSearchBar: true}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
/** Search Pages */
|
||||
{path: 'search/find', redirectTo: 'search/find/research-outcomes', pathMatch: 'full'},
|
||||
|
@ -168,86 +168,86 @@ const routes: Routes = [
|
|||
{
|
||||
path: 'search/find/research-outcomes',
|
||||
loadChildren: () => import('./searchPages/simple/searchResearchResults.module').then(m => m.OpenaireSearchResearchResultsModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/find/publications',
|
||||
component: PageURLResolverComponent,
|
||||
data: {hasQuickContact: false},
|
||||
canActivate: [IsCommunity]
|
||||
canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/find/datasets',
|
||||
component: PageURLResolverComponent,
|
||||
data: {hasQuickContact: false},
|
||||
canActivate: [IsCommunity]
|
||||
canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/find/software',
|
||||
component: PageURLResolverComponent,
|
||||
data: {hasQuickContact: false},
|
||||
canActivate: [IsCommunity]
|
||||
canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/find/other',
|
||||
component: PageURLResolverComponent,
|
||||
data: {hasQuickContact: false},
|
||||
canActivate: [IsCommunity]
|
||||
canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/find/projects',
|
||||
loadChildren: () => import('./searchPages/simple/searchProjects.module').then(m => m.LibSearchProjectsModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/find/dataproviders',
|
||||
loadChildren: () => import('./searchPages/simple/searchDataProviders.module').then(m => m.LibSearchDataProvidersModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
/** Advanced Search Pages */
|
||||
{
|
||||
path: 'search/advanced/research-outcomes',
|
||||
loadChildren: () => import('./searchPages/advanced/searchResearchResults.module').then(m => m.OpenaireAdvancedSearchResearchResultsModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/advanced/publications',
|
||||
component: PageURLResolverComponent,
|
||||
data: {hasQuickContact: false},
|
||||
canActivate: [IsCommunity]
|
||||
canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/advanced/datasets',
|
||||
component: PageURLResolverComponent,
|
||||
data: {hasQuickContact: false},
|
||||
canActivate: [IsCommunity]
|
||||
canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/advanced/software',
|
||||
component: PageURLResolverComponent,
|
||||
data: {hasQuickContact: false},
|
||||
canActivate: [IsCommunity]
|
||||
canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/advanced/other',
|
||||
component: PageURLResolverComponent,
|
||||
data: {hasQuickContact: false},
|
||||
canActivate: [IsCommunity]
|
||||
canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/advanced/organizations',
|
||||
loadChildren: () => import('./searchPages/advanced/advancedSearchOrganizations.module').then(m => m.LibAdvancedSearchOrganizationsModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/advanced/dataproviders',
|
||||
loadChildren: () => import('./searchPages/advanced/advancedSearchDataProviders.module').then(m => m.LibAdvancedSearchDataProvidersModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'search/advanced/projects',
|
||||
loadChildren: () => import('./searchPages/advanced/advancedSearchProjects.module').then(m => m.LibAdvancedSearchProjectsModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
/** Deposit Pages */
|
||||
{ path: 'participate/deposit-datasets',
|
||||
|
@ -271,37 +271,37 @@ const routes: Routes = [
|
|||
{
|
||||
path: 'participate/deposit/learn-how',
|
||||
loadChildren: () => import('./deposit/deposit.module').then(m => m.LibDepositModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'participate/deposit/search',
|
||||
loadChildren: () => import('./deposit/searchDataprovidersToDeposit.module').then(m => m.LibSearchDataprovidersToDepositModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'participate/deposit/zenodo',
|
||||
loadChildren: () => import('./deposit/zenodo/shareInZenodo.module').then(m => m.ShareInZenodoModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
/** Linking Pages */
|
||||
{
|
||||
path: 'myclaims', loadChildren: () => import('./claims/myClaims/myClaims.module').then(m => m.LibMyClaimsModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'participate/claim',
|
||||
loadChildren: () => import('./claims/linking/linkingGeneric.module').then(m => m.LibLinkingGenericModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'participate/direct-claim',
|
||||
loadChildren: () => import('./claims/directLinking/directLinking.module').then(m => m.LibDirectLinkingModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
{
|
||||
path: 'preview',
|
||||
loadChildren: () => import('./demo/demo.module').then(m => m.DemoModule),
|
||||
data: {hasQuickContact: false}, canActivate: [IsCommunity]
|
||||
data: {hasQuickContact: false}, canActivate: [CommunityAccessGuard]
|
||||
},
|
||||
/** help pages - do not exist in Admin portal/api/db */
|
||||
{
|
||||
|
|
|
@ -308,11 +308,13 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||
initAdminToolCommunity(communityId) {
|
||||
if (communityId) {
|
||||
this.properties.adminToolsPortalType = "community";
|
||||
this.properties.adminToolsCommunity = communityId;
|
||||
if (this.document) {
|
||||
this.initLayout(communityId);
|
||||
}
|
||||
} else {
|
||||
this.properties.adminToolsPortalType = "connect";
|
||||
this.properties.adminToolsCommunity = "connect";
|
||||
if (this.document) {
|
||||
this.initLayout(this.communityId?this.communityId:'connect');
|
||||
}
|
||||
|
|
|
@ -22,12 +22,12 @@ import {PageURLResolverModule} from "./openaireLibrary/utils/pageURLResolver.mod
|
|||
import {Schema2jsonldModule} from "./openaireLibrary/sharedComponents/schema2jsonld/schema2jsonld.module";
|
||||
import {DEFAULT_TIMEOUT, TimeoutInterceptor} from "./openaireLibrary/timeout-interceptor.service";
|
||||
import {ErrorInterceptorService} from "./openaireLibrary/error-interceptor.service";
|
||||
import {IsCommunity} from "./openaireLibrary/connect/communityGuard/isCommunity.guard";
|
||||
import {SubscribeService} from "./openaireLibrary/utils/subscribe/subscribe.service";
|
||||
import {RoleVerificationModule} from "./openaireLibrary/role-verification/role-verification.module";
|
||||
import {QuickContactModule} from "./openaireLibrary/sharedComponents/quick-contact/quick-contact.module";
|
||||
import {AlertModalModule} from "./openaireLibrary/utils/modal/alertModal.module";
|
||||
import {CustomizationService} from "./openaireLibrary/services/customization.service";
|
||||
import {CommunityAccessGuard} from "./utils/communityAccess.guard";
|
||||
|
||||
@NgModule({
|
||||
|
||||
|
@ -49,7 +49,7 @@ import {CustomizationService} from "./openaireLibrary/services/customization.ser
|
|||
declarations: [AppComponent, OpenaireErrorPageComponent],
|
||||
exports: [AppComponent],
|
||||
providers: [
|
||||
CommunitiesService, CustomizationService, IsCommunity, SubscribeService,
|
||||
CommunitiesService, CustomizationService, CommunityAccessGuard, SubscribeService,
|
||||
{provide: APP_ID, useValue: 'serverApp'},
|
||||
{
|
||||
provide: HTTP_INTERCEPTORS,
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
||||
import {forkJoin, Observable} from 'rxjs';
|
||||
import {CommunityService} from "../openaireLibrary/connect/community/community.service";
|
||||
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
|
||||
import {ConnectHelper} from "../openaireLibrary/connect/connectHelper";
|
||||
import {properties} from "../../environments/environment";
|
||||
import {map, take} from "rxjs/operators";
|
||||
import {LoginErrorCodes} from "../openaireLibrary/login/utils/guardHelper.class";
|
||||
import {Session} from "../openaireLibrary/login/utils/helper.class";
|
||||
|
||||
@Injectable()
|
||||
export class CommunityAccessGuard {
|
||||
|
||||
constructor(private router: Router,
|
||||
private communityService: CommunityService, private userManagementService: UserManagementService) {
|
||||
}
|
||||
|
||||
check(path: string): Observable<boolean> | boolean {
|
||||
let community = ConnectHelper.getCommunityFromDomain(properties.domain);
|
||||
if (!community) {
|
||||
this.router.navigate([properties.errorLink], {queryParams: {page: path}});
|
||||
return false;
|
||||
}
|
||||
return forkJoin([
|
||||
this.userManagementService.getUserInfo().pipe(take(1)),
|
||||
this.communityService.getCommunity(community).pipe(take(1))
|
||||
]).pipe(
|
||||
map(([user, communityInfo]) => {
|
||||
console.log(user, communityInfo)
|
||||
if (communityInfo) {
|
||||
console.log(communityInfo.status)
|
||||
if (communityInfo.isPublic()) {
|
||||
return true;
|
||||
} else if (communityInfo.isPrivate()) {
|
||||
this.router.navigate([properties.errorLink], {queryParams: {page: path}});
|
||||
return false;
|
||||
} else {
|
||||
if (!user) {
|
||||
this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
'errorCode': LoginErrorCodes.NOT_LOGIN,
|
||||
'redirectUrl': path
|
||||
}
|
||||
})
|
||||
return false;
|
||||
}
|
||||
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user) || Session.isManager('community', community, user) || Session.isSubscribedTo('community', community, user)) {
|
||||
console.log("user: has access")
|
||||
return true;
|
||||
} else {
|
||||
this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
'errorCode': LoginErrorCodes.NOT_AUTHORIZED,
|
||||
'redirectUrl': path
|
||||
}
|
||||
})
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
this.router.navigate([properties.errorLink], {queryParams: {page: path}});
|
||||
return false;
|
||||
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
return this.check(state.url);
|
||||
}
|
||||
|
||||
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||
return this.check(state.url);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue