feat(console): integrate frontend (#95)

* feat: console frontend

* chore(dependabot): cycle and npm

* chore: rename citadel to zitadel, remove generated files

* chore: delete go files

* chore(frontend): ci steps

* chore: remove docker and envoy files

* chore: remove docker file

* chore: working dir

* chore: run proto build

* add console start

* chore: restructure folders

* chore: remove gui build

* statikFs

* generate proto for console

* add statik import

* import

* chore: try statik

* chore: path

* chore: path

* chore: script in root

* chore: order build steps

* chore: go get

* chore: folder traversal

* chore: non empty test file

* chore: gitignore

* chore: gitignore

* chore: statik path

* chore: switch to failing FE build

* fix: build

* fix: project-grant-test

* fix: rm test

* add statik.go

* go mod tidy

* chore: place test, seperate test from build

* chore: lint all the world

* chore: ci the world instead

* chore: tune docker

* chore: undo container test

* chore: fix run

* chore: docker build

* chore: test docker build

* chore: go build flags

* finaly

* fix caos_local

* go mod

Co-authored-by: Livio Amstutz <[email protected]>
Co-authored-by: Max Peintner <[email protected]>
This commit is contained in:
Florian Forster
2020-05-13 14:41:43 +02:00
committed by GitHub
co-authored by Livio Amstutz Max Peintner
parent 9e32740eb8
commit 92a294f5c8
375 changed files with 97826 additions and 52 deletions
@@ -0,0 +1,289 @@
import { Injectable } from '@angular/core';
import { Empty } from 'google-protobuf/google/protobuf/empty_pb';
import { Metadata } from 'grpc-web';
import { from, Observable, of } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { AuthServicePromiseClient } from '../proto/generated/auth_grpc_web_pb';
import {
MfaOtpResponse,
MultiFactors,
MyProjectOrgSearchQuery,
MyProjectOrgSearchRequest,
MyProjectOrgSearchResponse,
PasswordChange,
PasswordRequest,
UpdateUserAddressRequest,
UpdateUserEmailRequest,
UpdateUserPhoneRequest,
UpdateUserProfileRequest,
UserAddress,
UserEmail,
UserPhone,
UserProfile,
UserSessionViews,
VerifyMfaOtp,
VerifyUserPhoneRequest,
} from '../proto/generated/auth_pb';
import { GrpcBackendService } from './grpc-backend.service';
import { GrpcService, RequestFactory, ResponseMapper } from './grpc.service';
@Injectable({
providedIn: 'root',
})
export class AuthUserService {
private _roleCache: string[] = [];
constructor(private readonly grpcClient: GrpcService,
private grpcBackendService: GrpcBackendService,
) { }
public async request<TReq, TResp, TMappedResp>(
requestFn: RequestFactory<AuthServicePromiseClient, TReq, TResp>,
request: TReq,
responseMapper: ResponseMapper<TResp, TMappedResp>,
metadata?: Metadata,
): Promise<TMappedResp> {
const mappedRequestFn = requestFn(this.grpcClient.auth).bind(this.grpcClient.auth);
const response = await this.grpcBackendService.runRequest(
mappedRequestFn,
request,
metadata,
);
return responseMapper(response);
}
public async GetMyUserProfile(): Promise<UserProfile> {
return await this.request(
c => c.getMyUserProfile,
new Empty(),
f => f,
);
}
public async GetMyMfas(): Promise<MultiFactors> {
return await this.request(
c => c.getMyMfas,
new Empty(),
f => f,
);
}
public async SearchMyProjectOrgs(
limit: number,
offset: number,
queryList?: MyProjectOrgSearchQuery[],
): Promise<MyProjectOrgSearchResponse> {
const req: MyProjectOrgSearchRequest = new MyProjectOrgSearchRequest();
req.setOffset(offset);
req.setLimit(limit);
if (queryList) {
req.setQueriesList(queryList);
}
return await this.request(
c => c.searchMyProjectOrgs,
req,
f => f,
);
}
public async SaveMyUserProfile(profile: UserProfile.AsObject): Promise<UserProfile> {
const req = new UpdateUserProfileRequest();
req.setFirstName(profile.firstName);
req.setLastName(profile.lastName);
req.setNickName(profile.nickName);
req.setDisplayName(profile.displayName);
req.setPreferredLanguage(profile.preferredLanguage);
req.setGender(profile.gender);
return await this.request(
c => c.updateMyUserProfile,
req,
f => f,
);
}
public async getMyUserSessions(): Promise<UserSessionViews> {
return await this.request(
c => c.getMyUserSessions,
new Empty(),
f => f,
);
}
public async GetMyUserEmail(): Promise<UserEmail> {
return await this.request(
c => c.getMyUserEmail,
new Empty(),
f => f,
);
}
public async SaveMyUserEmail(email: UserEmail.AsObject): Promise<UserEmail> {
const req = new UpdateUserEmailRequest();
req.setEmail(email.email);
return await this.request(
c => c.changeMyUserEmail,
req,
f => f,
);
}
private async getMyzitadelPermissions(): Promise<any> {
return await this.request(
c => c.getMyZitadelPermissions,
new Empty(),
f => f,
);
}
public GetMyzitadelPermissions(): Observable<any> {
return from(this.getMyzitadelPermissions());
}
public hasRoles(userRoles: string[], requestedRoles: string[], each: boolean = false): boolean {
return each ?
requestedRoles.every(role => userRoles.includes(role)) :
requestedRoles.findIndex(role => {
return userRoles.findIndex(i => i.includes(role)) > -1;
// return userRoles.includes(role);
}) > -1;
}
public async GetMyUserPhone(): Promise<UserPhone> {
// return this.grpcClient.auth.getMyUserPhone(new Empty());
return await this.request(
c => c.getMyUserPhone,
new Empty(),
(f: UserPhone) => f,
);
}
public async SaveMyUserPhone(phone: UserPhone.AsObject): Promise<UserPhone> {
const req = new UpdateUserPhoneRequest();
req.setPhone(phone.phone);
return await this.request(
c => c.changeMyUserPhone,
req,
f => f,
);
}
public async GetMyUserAddress(): Promise<UserAddress> {
return await this.request(
c => c.getMyUserAddress,
new Empty(),
f => f,
);
}
public async ResendEmailVerification(): Promise<Empty> {
const req = new Empty();
return await this.request(
c => c.resendMyEmailVerificationMail,
req,
f => f,
);
}
public async ResendPhoneVerification(): Promise<Empty> {
const req = new Empty();
return await this.request(
c => c.resendMyPhoneVerificationCode,
req,
f => f,
);
}
public async SetMyPassword(id: string): Promise<Empty> {
const req = new PasswordRequest();
req.setPassword(id);
return await this.request(
c => c.setMyPassword,
req,
f => f,
);
}
public async ChangeMyPassword(oldPassword: string, newPassword: string): Promise<Empty> {
const req = new PasswordChange();
req.setOldPassword(oldPassword);
req.setNewPassword(newPassword);
return await this.request(
c => c.changeMyPassword,
req,
f => f,
);
}
public async AddMfaOTP(): Promise<MfaOtpResponse> {
return await this.request(
c => c.addMfaOTP,
new Empty(),
f => f,
);
}
public async RemoveMfaOTP(): Promise<Empty> {
return await this.request(
c => c.removeMfaOTP,
new Empty(),
f => f,
);
}
public async VerifyMfaOTP(code: string): Promise<MfaOtpResponse> {
const req = new VerifyMfaOtp();
req.setCode(code);
return await this.request(
c => c.verifyMfaOTP,
req,
f => f,
);
}
public async VerifyMyUserPhone(code: string): Promise<Empty> {
const req = new VerifyUserPhoneRequest();
req.setCode(code);
return await this.request(
c => c.verifyMyUserPhone,
req,
f => f,
);
}
public async SaveMyUserAddress(address: UserAddress.AsObject): Promise<UserAddress> {
const req = new UpdateUserAddressRequest();
req.setStreetAddress(address.streetAddress);
req.setPostalCode(address.postalCode);
req.setLocality(address.locality);
req.setRegion(address.region);
req.setCountry(address.country);
return await this.request(
c => c.updateMyUserAddress,
req,
f => f,
);
}
public isAllowed(roles: string[], each: boolean = false): Observable<boolean> {
if (roles && roles.length > 0) {
if (this._roleCache.length > 0) {
return of(this.hasRoles(this._roleCache, roles));
}
return this.GetMyzitadelPermissions().pipe(
switchMap(response => {
const userRoles = response.toObject().permissionsList;
this._roleCache = userRoles;
return of(this.hasRoles(userRoles, roles, each));
}),
);
} else {
return of(false);
}
}
}