Skip to content

Commit

Permalink
feat(ui): allow TTL definition in new consumer creation form (#6340)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin committed Oct 20, 2022
1 parent 4792e94 commit 3ff9f14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Input, OnInit,
} from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { AuthConsumer, AuthConsumerScopeDetail } from 'app/model/authentication.model';
import { AuthConsumer, AuthConsumerScopeDetail, AuthConsumerValidityPeriod } from 'app/model/authentication.model';
import { Group } from 'app/model/group.model';
import { AuthentifiedUser } from 'app/model/user.model';
import { AuthenticationService } from 'app/service/authentication/authentication.service';
Expand Down Expand Up @@ -84,6 +84,12 @@ export class ConsumerCreateModalComponent implements OnInit {

ngOnInit(): void {
this.newConsumer = new AuthConsumer();
this.newConsumer.validity_periods = new Array<AuthConsumerValidityPeriod>();
// Init a default validity period of 15 days
var ttl = new AuthConsumerValidityPeriod();
ttl.issued_at = new Date().toISOString();
ttl.duration = 15;
this.newConsumer.validity_periods.push(ttl);
this.signinToken = null;
this.selectedGroupKeys = null;
this.selectedScopeDetails = [];
Expand Down Expand Up @@ -131,6 +137,8 @@ export class ConsumerCreateModalComponent implements OnInit {

this.loading = true;
this._cd.markForCheck();
// transform validity_period.duration from days to nanosecond
this.newConsumer.validity_periods[0].duration = this.newConsumer.validity_periods[0].duration * 8.64e13
this._userService.createConsumer(this.user.username, this.newConsumer)
.pipe(finalize(() => {
this.loading = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
</nz-form-item>
</nz-col>
</nz-row>
<nz-row>
<nz-col [nzSpan]="10">
<nz-form-item>
<nz-form-label>TTL (in days)</nz-form-label>
<nz-form-control>
<input nz-input type="number" name="duration" min="1" max="365"
[(ngModel)]="newConsumer.validity_periods[0].duration">
</nz-form-control>
</nz-form-item>
</nz-col>
</nz-row>
</form>
</nz-collapse-panel>
<nz-collapse-panel [(nzActive)]="panels[formStepName.GROUPS]"
Expand Down

0 comments on commit 3ff9f14

Please sign in to comment.