mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 12:57:34 +00:00
WIP: chore(ci): test nx
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { ActionConditionPipe } from './action-condition-pipe.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [ActionConditionPipe],
|
||||
imports: [CommonModule],
|
||||
exports: [ActionConditionPipe],
|
||||
})
|
||||
export class ActionConditionPipeModule {}
|
@@ -0,0 +1,29 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Condition } from '@zitadel/proto/zitadel/action/v2beta/execution_pb';
|
||||
|
||||
@Pipe({
|
||||
name: 'condition',
|
||||
})
|
||||
export class ActionConditionPipe implements PipeTransform {
|
||||
transform(condition?: Condition): string {
|
||||
if (!condition?.conditionType?.case) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const conditionType = condition.conditionType.value;
|
||||
|
||||
if ('name' in conditionType) {
|
||||
// Applies for function condition
|
||||
return `function: ${conditionType.name}`;
|
||||
}
|
||||
|
||||
const { condition: innerCondition } = conditionType;
|
||||
|
||||
if (typeof innerCondition.value === 'string') {
|
||||
// Applies for service, method condition of Request/ResponseCondition, event, and group of EventCondition
|
||||
return `${innerCondition.case}: ${innerCondition.value}`;
|
||||
}
|
||||
|
||||
return `all`;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { DurationToSecondsPipe } from './duration-to-seconds.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [DurationToSecondsPipe],
|
||||
imports: [CommonModule],
|
||||
exports: [DurationToSecondsPipe],
|
||||
})
|
||||
export class DurationToSecondsPipeModule {}
|
@@ -0,0 +1,23 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Duration } from 'google-protobuf/google/protobuf/duration_pb';
|
||||
|
||||
@Pipe({
|
||||
name: 'durationToSeconds',
|
||||
})
|
||||
export class DurationToSecondsPipe implements PipeTransform {
|
||||
transform(value?: Duration.AsObject, ...args: unknown[]): unknown {
|
||||
if (value) {
|
||||
return this.durationToSeconds(value);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
private durationToSeconds(date: Duration.AsObject): any {
|
||||
if (date?.seconds !== undefined && date?.nanos !== undefined) {
|
||||
const ms = date.seconds * 1000 + date.nanos / 1000 / 1000;
|
||||
const secs = ms / 1000;
|
||||
return `${secs.toFixed(2)} sec`;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { HasRolePipe } from './has-role.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [HasRolePipe],
|
||||
imports: [CommonModule],
|
||||
exports: [HasRolePipe],
|
||||
})
|
||||
export class HasRolePipeModule {}
|
14
apps/console/src/app/pipes/has-role-pipe/has-role.pipe.ts
Normal file
14
apps/console/src/app/pipes/has-role-pipe/has-role.pipe.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
|
||||
|
||||
@Pipe({
|
||||
name: 'hasRole',
|
||||
})
|
||||
export class HasRolePipe implements PipeTransform {
|
||||
constructor(private authService: GrpcAuthService) {}
|
||||
|
||||
public transform(values: string[], requresAll: boolean = false): Observable<boolean> {
|
||||
return this.authService.isAllowed(values, requresAll);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { LocalizedDatePipe } from './localized-date.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [LocalizedDatePipe],
|
||||
imports: [CommonModule],
|
||||
exports: [LocalizedDatePipe],
|
||||
})
|
||||
export class LocalizedDatePipeModule {}
|
@@ -0,0 +1,39 @@
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import moment from 'moment';
|
||||
import { supportedLanguages } from 'src/app/utils/language';
|
||||
|
||||
@Pipe({
|
||||
name: 'localizedDate',
|
||||
})
|
||||
export class LocalizedDatePipe implements PipeTransform {
|
||||
constructor(private translateService: TranslateService) {}
|
||||
|
||||
public transform(value: any, pattern?: string): any {
|
||||
if (pattern && pattern === 'fromNow') {
|
||||
moment.locale(this.translateService.currentLang ?? 'en');
|
||||
|
||||
let date = moment(value);
|
||||
if (moment().diff(date, 'days') <= 2) {
|
||||
return date.fromNow(); // '2 days ago' etc.
|
||||
} else {
|
||||
return this.getDateInRegularFormat(value);
|
||||
}
|
||||
}
|
||||
if (pattern && pattern === 'regular') {
|
||||
moment.locale(this.translateService.currentLang ?? 'en');
|
||||
return this.getDateInRegularFormat(value);
|
||||
} else {
|
||||
const lang = supportedLanguages.includes(this.translateService.currentLang) ? this.translateService.currentLang : 'en';
|
||||
const datePipe: DatePipe = new DatePipe(lang);
|
||||
return datePipe.transform(value, pattern ?? 'mediumDate');
|
||||
}
|
||||
}
|
||||
|
||||
private getDateInRegularFormat(value: any): string {
|
||||
const localeData = moment(value).localeData();
|
||||
const format = localeData.longDateFormat('L');
|
||||
return moment(value).format(`${format}, HH:mm`);
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { LocalizedDatePipeModule } from '../localized-date-pipe/localized-date-pipe.module';
|
||||
import { TimestampToDatePipeModule } from '../timestamp-to-date-pipe/timestamp-to-date-pipe.module';
|
||||
import { MilestonePipe } from './milestonePipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [MilestonePipe],
|
||||
imports: [CommonModule, TimestampToDatePipeModule, LocalizedDatePipeModule],
|
||||
exports: [MilestonePipe],
|
||||
})
|
||||
export class MilestonePipeModule {}
|
22
apps/console/src/app/pipes/milestone-pipe/milestonePipe.ts
Normal file
22
apps/console/src/app/pipes/milestone-pipe/milestonePipe.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { LocalizedDatePipe } from '../localized-date-pipe/localized-date.pipe';
|
||||
import { TimestampToDatePipe } from '../timestamp-to-date-pipe/timestamp-to-date.pipe';
|
||||
import { Milestone } from '../../proto/generated/zitadel/milestone/v1/milestone_pb';
|
||||
|
||||
@Pipe({
|
||||
name: 'milestone',
|
||||
})
|
||||
export class MilestonePipe implements PipeTransform {
|
||||
constructor(private translateService: TranslateService) {}
|
||||
|
||||
public transform(milestone?: Milestone.AsObject): any {
|
||||
if (milestone && milestone.reachedDate) {
|
||||
const timestampToDate = new TimestampToDatePipe().transform(milestone.reachedDate);
|
||||
const datePipeOutput = new LocalizedDatePipe(this.translateService).transform(timestampToDate);
|
||||
return `done on ${datePipeOutput}`;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
11
apps/console/src/app/pipes/origin-pipe/origin-pipe.module.ts
Normal file
11
apps/console/src/app/pipes/origin-pipe/origin-pipe.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { OriginPipe } from './origin.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [OriginPipe],
|
||||
imports: [CommonModule],
|
||||
exports: [OriginPipe],
|
||||
})
|
||||
export class OriginPipeModule {}
|
10
apps/console/src/app/pipes/origin-pipe/origin.pipe.ts
Normal file
10
apps/console/src/app/pipes/origin-pipe/origin.pipe.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'origin',
|
||||
})
|
||||
export class OriginPipe implements PipeTransform {
|
||||
public transform(value: string): boolean {
|
||||
return new RegExp(/^((https?:\/\/).*?([\w\d-]*\.[\w\d]+))($|\/.*$)/gm).test(value);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { RedirectPipe } from './redirect.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [RedirectPipe],
|
||||
imports: [CommonModule],
|
||||
exports: [RedirectPipe],
|
||||
})
|
||||
export class RedirectPipeModule {}
|
36
apps/console/src/app/pipes/redirect-pipe/redirect.pipe.ts
Normal file
36
apps/console/src/app/pipes/redirect-pipe/redirect.pipe.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'redirect',
|
||||
})
|
||||
export class RedirectPipe implements PipeTransform {
|
||||
public transform(uri: string, isNative: boolean): boolean {
|
||||
if (isNative) {
|
||||
if (
|
||||
uri.startsWith('http://localhost/') ||
|
||||
uri.startsWith('http://localhost:') ||
|
||||
uri.startsWith('http://127.0.0.1') ||
|
||||
uri.startsWith('http://[::1]') ||
|
||||
uri.startsWith('http://[0:0:0:0:0:0:0:1]') ||
|
||||
uri.startsWith('https://localhost/') ||
|
||||
uri.startsWith('https://localhost:') ||
|
||||
uri.startsWith('https://127.0.0.1') ||
|
||||
uri.startsWith('https://[::1]') ||
|
||||
uri.startsWith('https://[0:0:0:0:0:0:0:1]')
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (!uri.startsWith('https://') && !uri.startsWith('http://')) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (uri.startsWith('https://')) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
apps/console/src/app/pipes/regexp-pipe/regexp-pipe.module.ts
Normal file
11
apps/console/src/app/pipes/regexp-pipe/regexp-pipe.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { RegexpPipe } from './regexp.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [RegexpPipe],
|
||||
imports: [CommonModule],
|
||||
exports: [RegexpPipe],
|
||||
})
|
||||
export class RegExpPipeModule {}
|
10
apps/console/src/app/pipes/regexp-pipe/regexp.pipe.ts
Normal file
10
apps/console/src/app/pipes/regexp-pipe/regexp.pipe.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'regexp',
|
||||
})
|
||||
export class RegexpPipe implements PipeTransform {
|
||||
public transform(value: string): RegExp {
|
||||
return new RegExp(value);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { RoleTransformPipe } from './role-transform.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [RoleTransformPipe],
|
||||
imports: [CommonModule],
|
||||
exports: [RoleTransformPipe],
|
||||
})
|
||||
export class RoleTransformPipeModule {}
|
@@ -0,0 +1,27 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'roletransform',
|
||||
})
|
||||
export class RoleTransformPipe implements PipeTransform {
|
||||
public transform(value: string | string[]): string {
|
||||
if (typeof value === 'string') {
|
||||
return getNewString(value);
|
||||
} else if (typeof value === 'object' && value.length) {
|
||||
return (
|
||||
value
|
||||
.map((s) => getNewString(s))
|
||||
// .slice(0, -1)
|
||||
.join(', ')
|
||||
);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getNewString(value: string): string {
|
||||
const splitted = value.toLowerCase().split('_');
|
||||
const uppercased = splitted.map((s) => `${s.substring(0, 1).toUpperCase()}${s.substring(1, s.length)}`);
|
||||
return uppercased.join(' ');
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { TimestampToDatePipe } from './timestamp-to-date.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [TimestampToDatePipe],
|
||||
imports: [CommonModule],
|
||||
exports: [TimestampToDatePipe],
|
||||
})
|
||||
export class TimestampToDatePipeModule {}
|
@@ -0,0 +1,15 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Timestamp as BufTimestamp } from '@bufbuild/protobuf/wkt';
|
||||
import { Timestamp } from 'src/app/proto/generated/google/protobuf/timestamp_pb';
|
||||
|
||||
@Pipe({
|
||||
name: 'timestampToDate',
|
||||
})
|
||||
export class TimestampToDatePipe implements PipeTransform {
|
||||
transform(date: BufTimestamp | Timestamp.AsObject | undefined): Date | undefined {
|
||||
if (date?.seconds && date.nanos) {
|
||||
return new Date(Number(date.seconds) * 1000 + date.nanos / 1000 / 1000);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { TimestampToRetentionPipe } from './timestamp-to-retention.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [TimestampToRetentionPipe],
|
||||
imports: [CommonModule],
|
||||
exports: [TimestampToRetentionPipe],
|
||||
})
|
||||
export class TimestampToRetentionPipeModule {}
|
@@ -0,0 +1,23 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Duration } from 'google-protobuf/google/protobuf/duration_pb';
|
||||
|
||||
@Pipe({
|
||||
name: 'timestampToRetention',
|
||||
})
|
||||
export class TimestampToRetentionPipe implements PipeTransform {
|
||||
transform(value?: Duration.AsObject, ...args: unknown[]): unknown {
|
||||
if (value) {
|
||||
return this.retentionFromTimestamp(value);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
private retentionFromTimestamp(date: Duration.AsObject): any {
|
||||
if (date?.seconds !== undefined && date?.nanos !== undefined) {
|
||||
const ms = date.seconds * 1000 + date.nanos / 1000 / 1000;
|
||||
const mins = ms / 1000 / 60;
|
||||
return +(mins / 60 / 24).toFixed(2);
|
||||
}
|
||||
}
|
||||
}
|
11
apps/console/src/app/pipes/to-object/to-object.module.ts
Normal file
11
apps/console/src/app/pipes/to-object/to-object.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { ToObjectPipe } from './to-object.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [ToObjectPipe],
|
||||
imports: [CommonModule],
|
||||
exports: [ToObjectPipe],
|
||||
})
|
||||
export class ToObjectPipeModule {}
|
12
apps/console/src/app/pipes/to-object/to-object.pipe.ts
Normal file
12
apps/console/src/app/pipes/to-object/to-object.pipe.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { Struct } from 'google-protobuf/google/protobuf/struct_pb';
|
||||
import { Event } from 'src/app/proto/generated/zitadel/event_pb';
|
||||
|
||||
@Pipe({
|
||||
name: 'toobject',
|
||||
})
|
||||
export class ToObjectPipe implements PipeTransform {
|
||||
public transform(value: Event | Struct): any {
|
||||
return value.toObject();
|
||||
}
|
||||
}
|
11
apps/console/src/app/pipes/to-payload/to-payload.module.ts
Normal file
11
apps/console/src/app/pipes/to-payload/to-payload.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { ToPayloadPipe } from './to-payload.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [ToPayloadPipe],
|
||||
imports: [CommonModule],
|
||||
exports: [ToPayloadPipe],
|
||||
})
|
||||
export class ToPayloadPipeModule {}
|
17
apps/console/src/app/pipes/to-payload/to-payload.pipe.ts
Normal file
17
apps/console/src/app/pipes/to-payload/to-payload.pipe.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { JavaScriptValue } from 'google-protobuf/google/protobuf/struct_pb';
|
||||
import { Event } from 'src/app/proto/generated/zitadel/event_pb';
|
||||
|
||||
@Pipe({
|
||||
name: 'topayload',
|
||||
})
|
||||
export class ToPayloadPipe implements PipeTransform {
|
||||
public transform(value: Event): JavaScriptValue | string {
|
||||
const pl = value.getPayload();
|
||||
if (pl) {
|
||||
return pl.toJavaScript();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { TruncatePipePipe } from './truncate-pipe.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [TruncatePipePipe],
|
||||
imports: [CommonModule],
|
||||
exports: [TruncatePipePipe],
|
||||
})
|
||||
export class TruncatePipeModule {}
|
@@ -0,0 +1,12 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'truncate',
|
||||
})
|
||||
export class TruncatePipePipe implements PipeTransform {
|
||||
transform(value: string, ...args: unknown[]): unknown {
|
||||
const limit = args.length > 0 ? parseInt(args[0] as string, 10) : 20;
|
||||
const trail = args.length > 1 ? args[1] : '...';
|
||||
return value.length > limit ? value.substring(0, limit) + trail : value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user