Browse Source

Readonly webhooks.

pull/95/head
Sebastian Stehle 9 years ago
parent
commit
089c60b4f6
  1. 1
      src/Squidex.Domain.Apps.Read/Apps/Services/Implementations/CachingAppProvider.cs
  2. 2
      src/Squidex.Domain.Apps.Write/Apps/AppDomainObject.cs
  3. 2
      src/Squidex.Domain.Apps.Write/Apps/Commands/UpdateClient.cs
  4. 6
      src/Squidex/Controllers/Api/Apps/Models/ClientDto.cs
  5. 2
      src/Squidex/Controllers/Api/Apps/Models/UpdateAppClientDto.cs
  6. 10
      src/Squidex/app/features/settings/pages/clients/client.component.html
  7. 8
      src/Squidex/app/features/settings/pages/clients/client.component.scss
  8. 3
      src/Squidex/app/features/settings/pages/clients/client.component.ts
  9. 1
      src/Squidex/app/features/settings/pages/clients/clients-page.component.html
  10. 18
      src/Squidex/app/features/settings/pages/clients/clients-page.component.ts
  11. 2
      src/Squidex/app/features/webhooks/pages/webhooks-page.component.html
  12. 1
      src/Squidex/app/features/webhooks/pages/webhooks-page.component.ts
  13. 16
      src/Squidex/app/shared/services/app-clients.service.spec.ts
  14. 12
      src/Squidex/app/shared/services/app-clients.service.ts

1
src/Squidex.Domain.Apps.Read/Apps/Services/Implementations/CachingAppProvider.cs

@ -100,6 +100,7 @@ namespace Squidex.Domain.Apps.Read.Apps.Services.Implementations
} }
if (@event.Payload is AppClientAttached || if (@event.Payload is AppClientAttached ||
@event.Payload is AppClientChanged ||
@event.Payload is AppClientRenamed || @event.Payload is AppClientRenamed ||
@event.Payload is AppClientRevoked || @event.Payload is AppClientRevoked ||
@event.Payload is AppPlanChanged || @event.Payload is AppPlanChanged ||

2
src/Squidex.Domain.Apps.Write/Apps/AppDomainObject.cs

@ -132,7 +132,7 @@ namespace Squidex.Domain.Apps.Write.Apps
public AppDomainObject UpdateClient(UpdateClient command) public AppDomainObject UpdateClient(UpdateClient command)
{ {
Guard.Valid(command, nameof(command), () => "Cannot rename client"); Guard.Valid(command, nameof(command), () => "Cannot update client");
ThrowIfNotCreated(); ThrowIfNotCreated();

2
src/Squidex.Domain.Apps.Write/Apps/Commands/UpdateClient.cs

@ -28,7 +28,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Commands
if (string.IsNullOrWhiteSpace(Name) && IsReader == null) if (string.IsNullOrWhiteSpace(Name) && IsReader == null)
{ {
errors.Add(new ValidationError("Either name or IsReader must be defined.", nameof(Name), nameof(IsReader))); errors.Add(new ValidationError("Either name or reader state must be defined.", nameof(Name), nameof(IsReader)));
} }
} }
} }

6
src/Squidex/Controllers/Api/Apps/Models/ClientDto.cs

@ -29,5 +29,11 @@ namespace Squidex.Controllers.Api.Apps.Models
/// </summary> /// </summary>
[Required] [Required]
public string Name { get; set; } public string Name { get; set; }
/// <summary>
/// Determines if the client is a reader.
/// </summary>
[Required]
public bool IsReader { get; set; }
} }
} }

2
src/Squidex/Controllers/Api/Apps/Models/UpdateAppClientDto.cs

@ -21,6 +21,6 @@ namespace Squidex.Controllers.Api.Apps.Models
/// <summary> /// <summary>
/// Determines if the client is a reader. /// Determines if the client is a reader.
/// </summary> /// </summary>
public bool IsReader { get; set; } public bool? IsReader { get; set; }
} }
} }

10
src/Squidex/app/features/settings/pages/clients/client.component.html

@ -66,6 +66,16 @@
</button> </button>
</td> </td>
</tr> </tr>
<tr>
<td></td>
<td>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" [ngModel]="client.isReader" (ngModelChange)="changing.emit($event)" /> Reading only
</label>
</div>
</td>
</tr>
</table> </table>
</div> </div>

8
src/Squidex/app/features/settings/pages/clients/client.component.scss

@ -70,6 +70,14 @@ $color-editor: #eceeef;
padding: .4rem; padding: .4rem;
} }
.form-check {
padding: .5rem 0 0;
}
.form-check-label {
padding: 0;
}
.access-token { .access-token {
height: 18rem; height: 18rem;
font-size: 1rem; font-size: 1rem;

3
src/Squidex/app/features/settings/pages/clients/client.component.ts

@ -38,6 +38,9 @@ export class ClientComponent {
@Output() @Output()
public revoking = new EventEmitter(); public revoking = new EventEmitter();
@Output()
public changing = new EventEmitter<boolean>();
@Input() @Input()
public client: AppClientDto; public client: AppClientDto;

1
src/Squidex/app/features/settings/pages/clients/clients-page.component.html

@ -19,6 +19,7 @@
<div *ngFor="let client of appClients"> <div *ngFor="let client of appClients">
<sqx-client [client]="client" [appName]="appName() | async" <sqx-client [client]="client" [appName]="appName() | async"
(changing)="changeClient(client, $event)"
(renaming)="renameClient(client, $event)" (renaming)="renameClient(client, $event)"
(revoking)="revokeClient(client)"></sqx-client> (revoking)="revokeClient(client)"></sqx-client>
</div> </div>

18
src/Squidex/app/features/settings/pages/clients/clients-page.component.ts

@ -91,6 +91,18 @@ export class ClientsPageComponent extends AppComponentBase implements OnInit {
}); });
} }
public changeClient(client: AppClientDto, isReader: boolean) {
const request = new UpdateAppClientDto(undefined, isReader);
this.appNameOnce()
.switchMap(app => this.appClientsService.updateClient(app, client.id, request, this.version))
.subscribe(() => {
this.updateClients(this.appClients.replace(client, change(client, isReader)));
}, error => {
this.notifyError(error);
});
}
public resetClientForm() { public resetClientForm() {
this.addClientFormSubmitted = false; this.addClientFormSubmitted = false;
this.addClientForm.enable(); this.addClientForm.enable();
@ -123,6 +135,10 @@ export class ClientsPageComponent extends AppComponentBase implements OnInit {
} }
} }
function change(client: AppClientDto, isReader: boolean): AppClientDto {
return new AppClientDto(client.id, client.name, client.secret, isReader);
};
function rename(client: AppClientDto, name: string): AppClientDto { function rename(client: AppClientDto, name: string): AppClientDto {
return new AppClientDto(client.id, name, client.secret); return new AppClientDto(client.id, name, client.secret, client.isReader);
}; };

2
src/Squidex/app/features/webhooks/pages/webhooks-page.component.html

@ -42,7 +42,7 @@
</h3> </h3>
</td> </td>
<td class="client-delete"> <td class="client-delete">
<button type="button" class="btn btn-link btn-danger" (click)="deleteWebhook(webhook)"> <button type="button" class="btn btn-link btn-danger" (click)="deleteWebhook(w)">
<i class="icon-bin2"></i> <i class="icon-bin2"></i>
</button> </button>
</td> </td>

1
src/Squidex/app/features/webhooks/pages/webhooks-page.component.ts

@ -86,6 +86,7 @@ export class WebhooksPageComponent extends AppComponentBase implements OnInit {
this.notifyError(error); this.notifyError(error);
}); });
} }
public resetWebhookForm() { public resetWebhookForm() {
this.addWebhookFormSubmitted = false; this.addWebhookFormSubmitted = false;
this.addWebhookForm.enable(); this.addWebhookForm.enable();

16
src/Squidex/app/shared/services/app-clients.service.spec.ts

@ -55,19 +55,21 @@ describe('AppClientsService', () => {
{ {
id: 'client1', id: 'client1',
name: 'Client 1', name: 'Client 1',
secret: 'secret1' secret: 'secret1',
isReader: true
}, },
{ {
id: 'client2', id: 'client2',
name: 'Client 2', name: 'Client 2',
secret: 'secret2' secret: 'secret2',
isReader: true
} }
]); ]);
expect(clients).toEqual( expect(clients).toEqual(
[ [
new AppClientDto('client1', 'Client 1', 'secret1'), new AppClientDto('client1', 'Client 1', 'secret1', true),
new AppClientDto('client2', 'Client 2', 'secret2') new AppClientDto('client2', 'Client 2', 'secret2', true)
]); ]);
})); }));
@ -87,10 +89,10 @@ describe('AppClientsService', () => {
expect(req.request.method).toEqual('POST'); expect(req.request.method).toEqual('POST');
expect(req.request.headers.get('If-Match')).toEqual('1'); expect(req.request.headers.get('If-Match')).toEqual('1');
req.flush({ id: 'client1', name: 'Client 1', secret: 'secret1' }); req.flush({ id: 'client1', name: 'Client 1', secret: 'secret1', isReader: true });
expect(client).toEqual( expect(client).toEqual(
new AppClientDto('client1', 'Client 1', 'secret1')); new AppClientDto('client1', 'Client 1', 'secret1', true));
})); }));
it('should make put request to rename client', it('should make put request to rename client',
@ -126,7 +128,7 @@ describe('AppClientsService', () => {
let accessTokenDto: AccessTokenDto | null = null; let accessTokenDto: AccessTokenDto | null = null;
appClientsService.createToken('my-app', new AppClientDto('myClientId', 'myClient', 'mySecret')).subscribe(result => { appClientsService.createToken('my-app', new AppClientDto('myClientId', 'myClient', 'mySecret', false)).subscribe(result => {
accessTokenDto = result; accessTokenDto = result;
}); });

12
src/Squidex/app/shared/services/app-clients.service.ts

@ -21,7 +21,8 @@ export class AppClientDto {
constructor( constructor(
public readonly id: string, public readonly id: string,
public readonly name: string, public readonly name: string,
public readonly secret: string public readonly secret: string,
public readonly isReader: boolean
) { ) {
} }
} }
@ -35,7 +36,8 @@ export class CreateAppClientDto {
export class UpdateAppClientDto { export class UpdateAppClientDto {
constructor( constructor(
public readonly name: string public readonly name?: string,
public readonly isReader?: boolean
) { ) {
} }
} }
@ -67,7 +69,8 @@ export class AppClientsService {
return new AppClientDto( return new AppClientDto(
item.id, item.id,
item.name, item.name,
item.secret); item.secret,
item.isReader);
}); });
}) })
.pretifyError('Failed to load clients. Please reload.'); .pretifyError('Failed to load clients. Please reload.');
@ -81,7 +84,8 @@ export class AppClientsService {
return new AppClientDto( return new AppClientDto(
response.id, response.id,
response.name, response.name,
response.secret); response.secret,
response.isReader);
}) })
.pretifyError('Failed to add client. Please reload.'); .pretifyError('Failed to add client. Please reload.');
} }

Loading…
Cancel
Save