fix: login text changes (#4269)

* fix: omit empty (zero) dates

* overwrite current date on save

* update date on reset

* smtp

* disable reset

Co-authored-by: Max Peintner <max@caos.ch>
This commit is contained in:
Livio Spring 2022-09-02 10:29:06 +02:00 committed by GitHub
parent bee616c11a
commit adb5394ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 26 deletions

View File

@ -62,10 +62,9 @@
</div>
<div class="actions">
<!-- *ngIf="totalCustomPolicy && totalCustomPolicy.isDefault === false" -->
<button
class="reset-button"
[disabled]="(canWrite$ | async) === false"
[disabled]="(canWrite$ | async) === false || isDefault"
(click)="resetDefault()"
color="warn"
type="submit"
@ -76,7 +75,7 @@
<button
class="save-button"
[disabled]="(canWrite$ | async) === false"
(click)="saveCurrentMessage()"
(click)="saveCurrentTexts()"
color="primary"
type="submit"
mat-raised-button

View File

@ -5,14 +5,14 @@ import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
import { BehaviorSubject, from, interval, Observable, of, Subject, Subscription } from 'rxjs';
import { map, pairwise, startWith, takeUntil } from 'rxjs/operators';
import {
GetCustomLoginTextsRequest as AdminGetCustomLoginTextsRequest,
GetDefaultLoginTextsRequest as AdminGetDefaultLoginTextsRequest,
SetCustomLoginTextsRequest as AdminSetCustomLoginTextsRequest,
GetCustomLoginTextsRequest as AdminGetCustomLoginTextsRequest,
GetDefaultLoginTextsRequest as AdminGetDefaultLoginTextsRequest,
SetCustomLoginTextsRequest as AdminSetCustomLoginTextsRequest,
} from 'src/app/proto/generated/zitadel/admin_pb';
import {
GetCustomLoginTextsRequest,
GetDefaultLoginTextsRequest,
SetCustomLoginTextsRequest,
GetCustomLoginTextsRequest,
GetDefaultLoginTextsRequest,
SetCustomLoginTextsRequest,
} from 'src/app/proto/generated/zitadel/management_pb';
import { AdminService } from 'src/app/services/admin.service';
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
@ -24,6 +24,8 @@ import { WarnDialogComponent } from '../../warn-dialog/warn-dialog.component';
import { PolicyComponentServiceType } from '../policy-component-types.enum';
import { mapRequestValues } from './helper';
const MIN_INTERVAL_SECONDS = 10; // if the difference of a newer version to the current exceeds this time, a refresh button is shown.
/* eslint-disable */
const KeyNamesArray = [
'emailVerificationDoneText',
@ -120,6 +122,8 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
locale: new UntypedFormControl('en'),
});
public isDefault: boolean = false;
public canWrite$: Observable<boolean> = this.authService.isAllowed([
this.serviceType === PolicyComponentServiceType.ADMIN
? 'iam.policy.write'
@ -138,7 +142,7 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
.subscribe((pair) => {
this.checkForUnsaved(pair[0].currentSubMap).then((wantsToSave) => {
if (wantsToSave) {
this.saveCurrentMessage()
this.saveCurrentTexts()
.then(() => {
this.loadData();
})
@ -200,7 +204,6 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
return (this.service as ManagementService).getCustomLoginTexts(req).then((res) => {
if (res.customText) {
this.currentPolicyChangeDate = res.customText.details?.changeDate;
// delete res.customText.details;
return Object.assign({}, res.customText);
} else {
return {};
@ -219,6 +222,8 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
.then((policy) => {
this.loading = false;
if (policy) {
this.isDefault = policy.isDefault ?? false;
this.totalCustomPolicy = policy;
this.getCustomInitMessageTextMap$.next(policy[this.currentSubMap]);
}
@ -280,7 +285,7 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
}
}
public saveCurrentMessage(): Promise<any> {
public saveCurrentTexts(): Promise<any> {
const entirePayload = this.updateRequest.toObject();
this.getCustomInitMessageTextMap$.next((entirePayload as any)[this.currentSubMap]);
@ -289,6 +294,8 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
return (this.service as ManagementService)
.setCustomLoginText(this.updateRequest)
.then(() => {
this.updateCurrentPolicyDate();
this.isDefault = false;
this.toast.showInfo('POLICY.MESSAGE_TEXTS.TOAST.UPDATED', true);
setTimeout(() => {
this.patchSingleCurrentMap();
@ -299,12 +306,33 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
return (this.service as AdminService)
.setCustomLoginText(this.updateRequest)
.then(() => {
this.updateCurrentPolicyDate();
this.isDefault = false;
this.toast.showInfo('POLICY.MESSAGE_TEXTS.TOAST.UPDATED', true);
})
.catch((error) => this.toast.showError(error));
}
}
private updateCurrentPolicyDate(): void {
const ts = new Timestamp();
const milliseconds = new Date().getTime();
const seconds = Math.abs(milliseconds / 1000);
const nanos = (milliseconds - seconds * 1000) * 1000 * 1000;
ts.setSeconds(seconds);
ts.setNanos(nanos);
if (this.currentPolicyChangeDate) {
const oldDate = new Date(
this.currentPolicyChangeDate.seconds * 1000 + this.currentPolicyChangeDate.nanos / 1000 / 1000,
);
const newDate = ts.toDate();
if (newDate.getTime() > oldDate.getTime()) {
this.currentPolicyChangeDate = ts.toObject();
}
}
}
public resetDefault(): void {
const dialogRef = this.dialog.open(WarnDialogComponent, {
data: {
@ -323,6 +351,8 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
(this.service as ManagementService)
.resetCustomLoginTextToDefault(this.locale)
.then(() => {
this.updateCurrentPolicyDate();
this.isDefault = true;
setTimeout(() => {
this.loadData();
}, 1000);
@ -334,6 +364,7 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
(this.service as AdminService)
.resetCustomLoginTextToDefault(this.locale)
.then(() => {
this.updateCurrentPolicyDate();
setTimeout(() => {
this.loadData();
}, 1000);
@ -359,7 +390,7 @@ export class LoginTextsComponent implements OnInit, OnDestroy {
if (this.newerPolicyChangeDate && this.currentPolicyChangeDate) {
const ms = toDate(this.newerPolicyChangeDate).getTime() - toDate(this.currentPolicyChangeDate).getTime();
// show button if changes are newer than 10s
return ms / 1000 > 10;
return ms / 1000 > MIN_INTERVAL_SECONDS;
} else {
return false;
}

View File

@ -1524,7 +1524,7 @@
"DELETE_DESCRIPTION": "You are about to delete an identity provider. The resulting changes are irrevocable. Do you really want to do this?",
"DELETE_SELECTION_TITLE": "Delete Idp",
"DELETE_SELECTION_DESCRIPTION": "You are about to delete an identity provider. The resulting changes are irrevocable. Do you really want to do this?",
"EMPTY": "No IPD available",
"EMPTY": "No IDP available",
"OIDC": {
"GENERAL": "General Information",
"TITLE": "OIDC Configuration",

View File

@ -1524,7 +1524,7 @@
"DELETE_DESCRIPTION": "Vous êtes sur le point de supprimer un fournisseur d'identité. Les changements qui en résultent sont irrévocables. Voulez-vous vraiment le faire ?",
"DELETE_SELECTION_TITLE": "Supprimer Idp",
"DELETE_SELECTION_DESCRIPTION": "Vous êtes sur le point de supprimer un fournisseur d'identité. Les changements qui en résultent sont irrévocables. Voulez-vous vraiment le faire ?",
"EMPTY": "Aucun IPD disponible",
"EMPTY": "Aucun IDP disponible",
"OIDC": {
"GENERAL": "Informations générales",
"TITLE": "Configuration de l'OIDC",

View File

@ -11,19 +11,25 @@ import (
)
func DomainToChangeDetailsPb(objectDetail *domain.ObjectDetails) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
details := &object_pb.ObjectDetails{
Sequence: objectDetail.Sequence,
ChangeDate: timestamppb.New(objectDetail.EventDate),
ResourceOwner: objectDetail.ResourceOwner,
}
if !objectDetail.EventDate.IsZero() {
details.ChangeDate = timestamppb.New(objectDetail.EventDate)
}
return details
}
func DomainToAddDetailsPb(objectDetail *domain.ObjectDetails) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
details := &object_pb.ObjectDetails{
Sequence: objectDetail.Sequence,
CreationDate: timestamppb.New(objectDetail.EventDate),
ResourceOwner: objectDetail.ResourceOwner,
}
if !objectDetail.EventDate.IsZero() {
details.CreationDate = timestamppb.New(objectDetail.EventDate)
}
return details
}
func ToViewDetailsPb(
@ -32,12 +38,17 @@ func ToViewDetailsPb(
changeDate time.Time,
resourceOwner string,
) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
details := &object_pb.ObjectDetails{
Sequence: sequence,
CreationDate: timestamppb.New(creationDate),
ChangeDate: timestamppb.New(changeDate),
ResourceOwner: resourceOwner,
}
if !creationDate.IsZero() {
details.CreationDate = timestamppb.New(creationDate)
}
if !changeDate.IsZero() {
details.ChangeDate = timestamppb.New(changeDate)
}
return details
}
func ChangeToDetailsPb(
@ -45,11 +56,14 @@ func ChangeToDetailsPb(
changeDate time.Time,
resourceOwner string,
) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
details := &object_pb.ObjectDetails{
Sequence: sequence,
ChangeDate: timestamppb.New(changeDate),
ResourceOwner: resourceOwner,
}
if !changeDate.IsZero() {
details.ChangeDate = timestamppb.New(changeDate)
}
return details
}
func AddToDetailsPb(
@ -57,11 +71,14 @@ func AddToDetailsPb(
creationDate time.Time,
resourceOwner string,
) *object_pb.ObjectDetails {
return &object_pb.ObjectDetails{
details := &object_pb.ObjectDetails{
Sequence: sequence,
CreationDate: timestamppb.New(creationDate),
ResourceOwner: resourceOwner,
}
if !creationDate.IsZero() {
details.CreationDate = timestamppb.New(creationDate)
}
return details
}
func ToListDetails(