mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-23 21:28:47 +00:00
feat(console): message and login texts, privacy policy (#2016)
* message texts wrapper components * message-text sub, i18n, grid * fix routing * pack * pack * update material * audit * fix mgmt service for labelplcy * map conv * edit text from map * request map * fetch data, mgmt admin service * warn box, i18n * resetbtn * login texts * login text requests * reset, default, i18n * disabled, features, message text setter, service * locale switcher * policy grid * password reset, domain claimed i18n * lint files * fix admin service, i18n, lang setter * fix scss duplicate * privacy policy, cleanup grid, fix message, login texts (#2031) * policy grid everywhere 🦒 * cleanup home * log login text request * patch all data * refresh toggle * fix: add dialog for unsaved changes (#2057) * logintexts dialog * check for dialog on pairwise operation * fix: patch value to local state after save * fix: i18n and custom login texts (#2060) * fix: i18n and custom login texts * fix: tos and privacy texts * fix frontend * fix: tos and privacy texts and tests * fix: i18n, tos and privacy texts and tests * fix frontend maps * i18n * add ResetCustomLoginTextToDefault in admin api and fix template remove in handlers * resetlogintexttodefault Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
co-authored by
Livio Amstutz
parent
26e4e607bc
commit
2e684684de
@@ -0,0 +1,20 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { PrivacyPolicyComponent } from './privacy-policy.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: PrivacyPolicyComponent,
|
||||
data: {
|
||||
animation: 'DetailPage',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class PrivacyPolicyRoutingModule { }
|
||||
@@ -0,0 +1,37 @@
|
||||
<app-detail-layout [backRouterLink]="[ serviceType === PolicyComponentServiceType.ADMIN ? '/iam/policies' : '/org']"
|
||||
[title]="'POLICY.PRIVACY_POLICY.TITLE' | translate"
|
||||
[description]="'POLICY.PRIVACY_POLICY.DESCRIPTION' | translate">
|
||||
|
||||
<cnsl-info-section class="warn"
|
||||
*ngIf="serviceType == PolicyComponentServiceType.MGMT && (['privacy_policy'] | hasFeature | async) == false"
|
||||
type="WARN">
|
||||
{{'FEATURES.NOTAVAILABLE' | translate: ({value:
|
||||
'privacy_policy'})}}
|
||||
</cnsl-info-section>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="content" >
|
||||
<form *ngIf="form" [formGroup]="form">
|
||||
<cnsl-form-field class="formfield">
|
||||
<cnsl-label>{{ 'POLICY.PRIVACY_POLICY.TOSLINK' | translate }}</cnsl-label>
|
||||
<input cnslInput name="tosLink" formControlName="tosLink" />
|
||||
</cnsl-form-field>
|
||||
|
||||
<cnsl-form-field class="formfield">
|
||||
<cnsl-label>{{ 'POLICY.PRIVACY_POLICY.POLICYLINK' | translate }}</cnsl-label>
|
||||
<input cnslInput name="privacyLink" formControlName="privacyLink" />
|
||||
</cnsl-form-field>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button *ngIf="!privacyPolicy?.isDefault" class="reset-button" [disabled]="serviceType == PolicyComponentServiceType.MGMT && (['privacy_policy'] | hasFeature | async) == false" (click)="resetDefault()" color="warn" type="submit"
|
||||
mat-stroked-button><i class="las la-history"></i> {{ 'ACTIONS.RESETDEFAULT' | translate }}</button>
|
||||
<button class="save-button" [disabled]="serviceType == PolicyComponentServiceType.MGMT && (['privacy_policy'] | hasFeature | async) == false" (click)="saveCurrentMessage()" color="primary" type="submit"
|
||||
mat-raised-button>{{ 'ACTIONS.SAVE' | translate }}</button>
|
||||
</div>
|
||||
|
||||
<app-policy-grid [currentPolicy]="currentPolicy" [type]="serviceType" tagForFilter="text"></app-policy-grid>
|
||||
|
||||
</app-detail-layout>
|
||||
@@ -0,0 +1,81 @@
|
||||
.spinner-wr {
|
||||
margin: .5rem 0;
|
||||
}
|
||||
|
||||
.top-actions {
|
||||
display: flex;
|
||||
margin: 0 -.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.keys {
|
||||
flex: 1;
|
||||
margin: 0 .5rem;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
.language {
|
||||
margin: 0 .5rem;
|
||||
min-width: 150px;
|
||||
|
||||
.lighter {
|
||||
font-size: 12px;
|
||||
color: var(--grey);
|
||||
padding: 0 .5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.centerline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding-top: 1rem;
|
||||
}
|
||||
|
||||
.chips {
|
||||
display: flex;
|
||||
margin: 0 -.25rem;
|
||||
|
||||
.chip {
|
||||
border-radius: 50vw;
|
||||
padding: 2px .5rem;
|
||||
font-size: 12px;
|
||||
background: #cbf4c9;
|
||||
color: #0e6245;
|
||||
margin: .25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 10;
|
||||
}
|
||||
}
|
||||
|
||||
.divider {
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
background-color: rgba(#81868a, .5);
|
||||
margin: 1.5rem 0 0 0;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin: 0 -.25rem;
|
||||
|
||||
.save-button,
|
||||
.reset-button {
|
||||
display: block;
|
||||
margin: 0 .25rem 3rem .25rem;
|
||||
}
|
||||
|
||||
.reset-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
i {
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { LoginPolicyComponent } from './login-policy.component';
|
||||
|
||||
describe('LoginPolicyComponent', () => {
|
||||
let component: LoginPolicyComponent;
|
||||
let fixture: ComponentFixture<LoginPolicyComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [LoginPolicyComponent],
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(LoginPolicyComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,147 @@
|
||||
import { Component, Injector, OnDestroy, Type } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import {
|
||||
GetPrivacyPolicyResponse as AdminGetPrivacyPolicyResponse,
|
||||
UpdatePrivacyPolicyRequest,
|
||||
} from 'src/app/proto/generated/zitadel/admin_pb';
|
||||
import {
|
||||
AddCustomPrivacyPolicyRequest,
|
||||
GetPrivacyPolicyResponse,
|
||||
UpdateCustomPrivacyPolicyRequest,
|
||||
} from 'src/app/proto/generated/zitadel/management_pb';
|
||||
import { PrivacyPolicy } from 'src/app/proto/generated/zitadel/policy_pb';
|
||||
import { AdminService } from 'src/app/services/admin.service';
|
||||
import { ManagementService } from 'src/app/services/mgmt.service';
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
|
||||
import { CnslLinks } from '../../links/links.component';
|
||||
import { GridPolicy, PRIVACY_POLICY } from '../../policy-grid/policies';
|
||||
import { WarnDialogComponent } from '../../warn-dialog/warn-dialog.component';
|
||||
import { PolicyComponentServiceType } from '../policy-component-types.enum';
|
||||
|
||||
@Component({
|
||||
selector: 'app-privacy-policy',
|
||||
templateUrl: './privacy-policy.component.html',
|
||||
styleUrls: ['./privacy-policy.component.scss'],
|
||||
})
|
||||
export class PrivacyPolicyComponent implements OnDestroy {
|
||||
public service!: ManagementService | AdminService;
|
||||
public PolicyComponentServiceType: any = PolicyComponentServiceType;
|
||||
public serviceType: PolicyComponentServiceType = PolicyComponentServiceType.MGMT;
|
||||
|
||||
public nextLinks: CnslLinks[] = [];
|
||||
private sub: Subscription = new Subscription();
|
||||
|
||||
public privacyPolicy!: PrivacyPolicy.AsObject;
|
||||
public form!: FormGroup;
|
||||
public currentPolicy: GridPolicy = PRIVACY_POLICY;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private injector: Injector,
|
||||
private dialog: MatDialog,
|
||||
private toast: ToastService,
|
||||
private fb: FormBuilder,
|
||||
) {
|
||||
|
||||
this.form = this.fb.group({
|
||||
tosLink: ['', []],
|
||||
privacyLink: ['', []],
|
||||
});
|
||||
|
||||
this.route.data.pipe(switchMap(data => {
|
||||
this.serviceType = data.serviceType;
|
||||
switch (this.serviceType) {
|
||||
case PolicyComponentServiceType.MGMT:
|
||||
this.service = this.injector.get(ManagementService as Type<ManagementService>);
|
||||
this.loadData();
|
||||
break;
|
||||
case PolicyComponentServiceType.ADMIN:
|
||||
this.service = this.injector.get(AdminService as Type<AdminService>);
|
||||
this.loadData();
|
||||
break;
|
||||
}
|
||||
|
||||
return this.route.params;
|
||||
})).subscribe();
|
||||
}
|
||||
|
||||
public async loadData(): Promise<any> {
|
||||
const getData = ():
|
||||
Promise<AdminGetPrivacyPolicyResponse.AsObject | GetPrivacyPolicyResponse.AsObject> => {
|
||||
return (this.service as AdminService).getPrivacyPolicy();
|
||||
};
|
||||
|
||||
getData().then(resp => {
|
||||
if (resp.policy) {
|
||||
this.privacyPolicy = resp.policy;
|
||||
this.form.patchValue(this.privacyPolicy);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public saveCurrentMessage(): void {
|
||||
console.log(this.form.get('privacyLink')?.value, this.form.get('tosLink')?.value);
|
||||
if (this.serviceType === PolicyComponentServiceType.MGMT) {
|
||||
if ((this.privacyPolicy as PrivacyPolicy.AsObject).isDefault) {
|
||||
const req = new AddCustomPrivacyPolicyRequest();
|
||||
req.setPrivacyLink(this.form.get('privacyLink')?.value);
|
||||
req.setTosLink(this.form.get('tosLink')?.value);
|
||||
(this.service as ManagementService).addCustomPrivacyPolicy(req).then(() => {
|
||||
this.toast.showInfo('POLICY.PRIVACY_POLICY.SAVED', true);
|
||||
}).catch(error => this.toast.showError(error));
|
||||
} else {
|
||||
const req = new UpdateCustomPrivacyPolicyRequest();
|
||||
req.setPrivacyLink(this.form.get('privacyLink')?.value);
|
||||
req.setTosLink(this.form.get('tosLink')?.value);
|
||||
(this.service as ManagementService).updateCustomPrivacyPolicy(req).then(() => {
|
||||
this.toast.showInfo('POLICY.PRIVACY_POLICY.SAVED', true);
|
||||
}).catch(error => this.toast.showError(error));
|
||||
}
|
||||
|
||||
} else if (this.serviceType === PolicyComponentServiceType.ADMIN) {
|
||||
const req = new UpdatePrivacyPolicyRequest();
|
||||
req.setPrivacyLink(this.form.get('privacyLink')?.value);
|
||||
req.setTosLink(this.form.get('tosLink')?.value);
|
||||
|
||||
(this.service as AdminService).updatePrivacyPolicy(req).then(() => {
|
||||
this.toast.showInfo('POLICY.PRIVACY_POLICY.SAVED', true);
|
||||
}).catch(error => this.toast.showError(error));
|
||||
}
|
||||
}
|
||||
|
||||
public resetDefault(): void {
|
||||
const dialogRef = this.dialog.open(WarnDialogComponent, {
|
||||
data: {
|
||||
icon: 'las la-history',
|
||||
confirmKey: 'ACTIONS.RESTORE',
|
||||
cancelKey: 'ACTIONS.CANCEL',
|
||||
titleKey: 'POLICY.PRIVACY_POLICY.RESET_TITLE',
|
||||
descriptionKey: 'POLICY.PRIVACY_POLICY.RESET_DESCRIPTION',
|
||||
},
|
||||
width: '400px',
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(resp => {
|
||||
if (resp) {
|
||||
if (this.serviceType === PolicyComponentServiceType.MGMT) {
|
||||
(this.service as ManagementService).resetPrivacyPolicyToDefault().then(() => {
|
||||
setTimeout(() => {
|
||||
this.loadData();
|
||||
}, 1000);
|
||||
}).catch(error => {
|
||||
this.toast.showError(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ngOnDestroy(): void {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { TextFieldModule } from '@angular/cdk/text-field';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
import { HasRoleModule } from '../../../directives/has-role/has-role.module';
|
||||
import { DetailLayoutModule } from '../../../modules/detail-layout/detail-layout.module';
|
||||
import { InputModule } from '../../../modules/input/input.module';
|
||||
import { HasFeaturePipeModule } from '../../../pipes/has-feature-pipe/has-feature-pipe.module';
|
||||
import { HasRolePipeModule } from '../../../pipes/has-role-pipe/has-role-pipe.module';
|
||||
import { FormFieldModule } from '../../form-field/form-field.module';
|
||||
import { InfoSectionModule } from '../../info-section/info-section.module';
|
||||
import { PolicyGridModule } from '../../policy-grid/policy-grid.module';
|
||||
import { WarnDialogModule } from '../../warn-dialog/warn-dialog.module';
|
||||
import { PrivacyPolicyRoutingModule } from './privacy-policy-routing.module';
|
||||
import { PrivacyPolicyComponent } from './privacy-policy.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [PrivacyPolicyComponent],
|
||||
imports: [
|
||||
PrivacyPolicyRoutingModule,
|
||||
MatSelectModule,
|
||||
CommonModule,
|
||||
InfoSectionModule,
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
InputModule,
|
||||
FormFieldModule,
|
||||
MatButtonModule,
|
||||
HasFeaturePipeModule,
|
||||
MatIconModule,
|
||||
HasRoleModule,
|
||||
HasRolePipeModule,
|
||||
MatTooltipModule,
|
||||
TranslateModule,
|
||||
MatTooltipModule,
|
||||
DetailLayoutModule,
|
||||
MatProgressSpinnerModule,
|
||||
TextFieldModule,
|
||||
MatDialogModule,
|
||||
WarnDialogModule,
|
||||
PolicyGridModule,
|
||||
],
|
||||
})
|
||||
export class PrivacyPolicyModule { }
|
||||
Reference in New Issue
Block a user