feat(console): set primary domain, fix org create permission (#688)

* feat: set primary domain, fix org perm

* lint
This commit is contained in:
Max Peintner
2020-09-02 12:35:06 +02:00
committed by GitHub
parent 4b183633ab
commit 779879f6ae
9 changed files with 44 additions and 4 deletions
+1 -1
View File
@@ -84,7 +84,7 @@ const routes: Routes = [
.then(m => m.UserGrantCreateModule),
canActivate: [RoleGuard],
data: {
roles: ['project.user.grant.write'],
roles: ['user.grant.write'],
},
},
],
+1 -1
View File
@@ -28,7 +28,7 @@
{{temporg?.name ? temporg.name : 'NO NAME'}}
</button>
<ng-template appHasRole [appHasRole]="['(org.create)?(iam.write)?']">
<ng-template appHasRole [appHasRole]="['org.create','iam.write']">
<button mat-menu-item [routerLink]="[ '/org/create' ]">
<mat-icon class="avatar">add</mat-icon>
{{'MENU.NEWORG' | translate}}
@@ -13,6 +13,8 @@
<i matTooltip="verified" *ngIf="domain.verified" class="verified las la-check-circle"></i>
<i matTooltip="primary" *ngIf="domain.primary" class="primary las la-star"></i>
<a *ngIf="!domain.primary" class="primaryset"
(click)="setPrimary(domain)">{{'ORG.DOMAINS.SETPRIMARY' | translate}}</a>
<span class="fill-space"></span>
<button [disabled]="(canwrite$ | async) == false" matTooltip="Remove domain" color="warn"
@@ -25,6 +25,15 @@
}
}
.primaryset {
font-size: 13px;
cursor: pointer;
&:hover {
text-decoration: underline;
}
}
.verified,
.primary {
color: #5282c1;
@@ -84,6 +84,15 @@ export class OrgDetailComponent implements OnInit, OnDestroy {
});
}
public setPrimary(domain: OrgDomainView.AsObject): void {
this.mgmtService.setMyPrimaryOrgDomain(domain.domain).then(() => {
this.toast.showInfo('ORG.TOAST.SETPRIMARY', true);
this.getData();
}).catch((error) => {
this.toast.showError(error);
});
}
public changeState(event: MatButtonToggleChange | any): void {
if (event.value === OrgState.ORGSTATE_ACTIVE) {
this.mgmtService.ReactivateMyOrg().then(() => {
@@ -128,6 +128,10 @@ export class GrpcAuthService {
});
}
/**
* returns true if user has one of the provided roles
* @param roles roles of the user
*/
public isAllowed(roles: string[] | RegExp[]): Observable<boolean> {
if (roles && roles.length > 0) {
return this.zitadelPermissions.pipe(switchMap(zroles => {
@@ -138,6 +142,11 @@ export class GrpcAuthService {
}
}
/**
* returns true if user has one of the provided roles
* @param userRoles roles of the user
* @param requestedRoles required roles for accessing the respective component
*/
public hasRoles(userRoles: string[], requestedRoles: string[] | RegExp[]): boolean {
return requestedRoles.findIndex((regexp: any) => {
return userRoles.findIndex(role => {
+7
View File
@@ -63,6 +63,7 @@ import {
PasswordLockoutPolicyID,
PasswordLockoutPolicyUpdate,
PasswordRequest,
PrimaryOrgDomainRequest,
Project,
ProjectCreateRequest,
ProjectGrant,
@@ -254,6 +255,12 @@ export class ManagementService {
return this.grpcService.mgmt.searchMyOrgDomains(req);
}
public async setMyPrimaryOrgDomain(domain: string): Promise<Empty> {
const req: PrimaryOrgDomainRequest = new PrimaryOrgDomainRequest();
req.setDomain(domain);
return this.grpcService.mgmt.setMyPrimaryOrgDomain(req);
}
public async GenerateMyOrgDomainValidation(domain: string, type: OrgDomainValidationType):
Promise<OrgDomainValidationResponse> {
const req: OrgDomainValidationRequest = new OrgDomainValidationRequest();