Fix issues about tags action.

This commit is contained in:
kunw 2017-05-02 17:49:21 +08:00
parent f7a4a21066
commit bcb1dff59d
2 changed files with 33 additions and 13 deletions

View File

@ -94,6 +94,7 @@ const harborRoutes: Routes = [
{
path: 'tags/:id/:repo',
component: TagRepositoryComponent,
canActivate: [MemberGuard],
resolve: {
projectResolver: ProjectRoutingResolver
}

View File

@ -33,20 +33,39 @@ export class MemberGuard implements CanActivate, CanActivateChild {
let projectId = route.params['id'];
this.sessionService.setProjectMembers([]);
return new Promise((resolve, reject) => {
this.projectService.checkProjectMember(projectId)
let user = this.sessionService.getCurrentUser();
if(user === null) {
this.sessionService.retrieveUser().then(currentUser=>{
return resolve(this.checkMemberStatus(state.url, projectId));
}).catch(err=>resolve(true));
} else {
return resolve(this.checkMemberStatus(state.url, projectId));
}
});
}
checkMemberStatus(url: string, projectId: number): Promise<boolean> {
return new Promise<boolean>((resolve, reject)=>{
this.projectService.checkProjectMember(projectId)
.subscribe(
res=>{
this.sessionService.setProjectMembers(res);
return resolve(true)
},
error => {
//Add exception for repository in project detail router activation.
if(state.url.endsWith('repository')) {
return resolve(true);
}
this.router.navigate([CommonRoutes.HARBOR_DEFAULT]);
return resolve(false);
});
res=>{
this.sessionService.setProjectMembers(res);
return resolve(true);
},
error => {
//Add exception for repository in project detail router activation.
if(url.endsWith('repository')) {
return resolve(true);
}
this.projectService.getProject(projectId)
.subscribe(project=>{
if(project.public === 1) {
return resolve(true);
}
this.router.navigate([CommonRoutes.HARBOR_DEFAULT]);
return resolve(false);
});
});
});
}