Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit af9c2dc

Browse files
committed
Add authorization to New Data Catalog button
1 parent 136e24d commit af9c2dc

File tree

6 files changed

+84
-17
lines changed

6 files changed

+84
-17
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Injectable } from '@angular/core';
2+
import { Observable } from 'rxjs';
3+
import { filter, mapTo } from 'rxjs/operators';
4+
import { UserPermissionDataService } from 'components/auth/user-permission-data.service';
5+
import { EntityAuthorizationService } from 'components/authorization/entity-authorization.service';
6+
import config from '../app.constants';
7+
8+
@Injectable()
9+
export class DataCatalogAuthorizationService extends EntityAuthorizationService {
10+
// TODO Find a way to not have to inject the service in the child service, only the parent service.
11+
static parameters = [UserPermissionDataService];
12+
constructor(protected userPermissionDataService: UserPermissionDataService) {
13+
super(userPermissionDataService);
14+
}
15+
16+
getEntityType(): string {
17+
return config.entityTypes.DATA_CATALOG.value;
18+
}
19+
20+
getCreateActionPermissionType(): string {
21+
return config.actionPermissionTypes.CREATE_DATA_CATALOG.value;
22+
}
23+
24+
// TODO Remove when DataCatalog can be made private
25+
/** @override */
26+
canRead(catalogId: string): Observable<boolean> {
27+
return this.userPermissionDataService.permissions().pipe(
28+
filter(auth => !!auth),
29+
mapTo(true)
30+
);
31+
}
32+
}
Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { Router } from '@angular/router';
3-
import { PageTitleService } from 'components/page-title/page-title.service';
3+
import { Subscription } from 'rxjs';
44
import { DataCatalog } from 'models/entities/data-catalog.model';
5+
import { NotificationService } from 'components/notification/notification.service';
6+
import { PageTitleService } from 'components/page-title/page-title.service';
57
import { DataCatalogService } from '../data-catalog.service';
6-
import { UserPermissionDataService } from 'components/auth/user-permission-data.service';
8+
import { DataCatalogAuthorizationService } from './../data-catalog-authorization.service';
79

810
@Component({
911
selector: 'data-catalog-list',
1012
template: require('./data-catalog-list.html'),
1113
styles: [require('./data-catalog-list.scss')],
1214
})
13-
export class DataCatalogListComponent implements OnInit {
14-
private canCreateDataCatalog = false; // used in html
15+
export class DataCatalogListComponent implements OnInit, OnDestroy {
16+
private canCreateDataCatalog = false;
17+
private canCreateDataCatalogSub: Subscription;
1518

16-
static parameters = [Router, PageTitleService, UserPermissionDataService, DataCatalogService];
19+
static parameters = [
20+
Router,
21+
NotificationService,
22+
PageTitleService,
23+
DataCatalogService,
24+
DataCatalogAuthorizationService,
25+
];
1726
constructor(
1827
private router: Router,
28+
private notificationService: NotificationService,
1929
private pageTitleService: PageTitleService,
20-
private permissionDataService: UserPermissionDataService,
21-
private catalogService: DataCatalogService // used in html
30+
private catalogService: DataCatalogService, // used in html
31+
private catalogAuthorizationService: DataCatalogAuthorizationService
2232
) {}
2333

2434
ngOnInit() {
2535
this.pageTitleService.setTitle('Data Catalogs');
26-
this.permissionDataService
27-
.permissions()
28-
.subscribe(
29-
permissions => (this.canCreateDataCatalog = permissions.canCreateDataCatalog()),
30-
err => console.error(err)
31-
); // unsubscribe in destructor
36+
37+
this.canCreateDataCatalogSub = this.catalogAuthorizationService.canCreate().subscribe(
38+
canCreate => {
39+
this.canCreateDataCatalog = canCreate;
40+
},
41+
err => console.error(err)
42+
);
43+
}
44+
45+
ngOnDestroy() {
46+
if (this.canCreateDataCatalogSub) {
47+
this.canCreateDataCatalogSub.unsubscribe();
48+
}
3249
}
3350

3451
onEntityClick(catalog: DataCatalog) {
@@ -37,9 +54,11 @@ export class DataCatalogListComponent implements OnInit {
3754
}
3855
}
3956

40-
onCreateNewDataCatalog(): void {
57+
newDataCatalog(): void {
4158
if (this.canCreateDataCatalog) {
4259
this.router.navigate(['/', 'data-catalogs', 'new']);
60+
} else {
61+
this.notificationService.info('Not available to Users yet.');
4362
}
4463
}
4564
}

client/app/data-catalog/data-catalog-list/data-catalog-list.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<div class="app-primary-header app-data-catalog-list-header">
22
<h1 class="app-primary-header-title">Data Catalogs</h1>
3-
<a [disabled]="!canCreateDataCatalog" mat-raised-button color="warn" class="app-data-catalog-list-new-data-catalog-btn" (click)="onCreateNewDataCatalog()" aria-label="Create a new tool">New Data Catalog</a>
3+
<a
4+
mat-raised-button
5+
color="warn"
6+
class="app-data-catalog-list-new-data-catalog-btn"
7+
(click)="newDataCatalog()"
8+
aria-label="Create a new tool"
9+
><mat-icon class="app-data-catalog-list-new-data-catalog-btn-icon" *ngIf="!canCreateDataCatalog">lock</mat-icon>New Data Catalog</a
10+
>
411
</div>
512

613
<div class="app-data-catalogs-list">

client/app/data-catalog/data-catalog-list/data-catalog-list.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "../../../styles/general";
2+
13
.app-data-catalog-list {
24
display: flex;
35
flex-flow: row nowrap;
@@ -15,3 +17,8 @@
1517
.app-data-catalog-list-new-data-catalog-btn {
1618
margin-right: 20px;
1719
}
20+
21+
.app-data-catalog-list-new-data-catalog-btn-icon {
22+
@include mat-icon-size(20px);
23+
padding-right: 5px;
24+
}

client/app/data-catalog/data-catalog.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ClipboardModule } from 'ngx-clipboard';
2020
import { MessagingModule } from 'components/messaging/messaging.module';
2121
import { DataCatalogThreadComponent } from './data-catalog-thread/data-catalog-thread.component';
2222
import { DataCatalogThreadNewComponent } from './data-catalog-thread-new/data-catalog-thread-new.component';
23+
import { DataCatalogAuthorizationService } from './data-catalog-authorization.service';
2324

2425
export const ROUTES: Routes = [
2526
{
@@ -75,7 +76,7 @@ export const ROUTES: Routes = [
7576
DataCatalogThreadComponent,
7677
DataCatalogThreadNewComponent,
7778
],
78-
providers: [SocketService, DataCatalogService],
79+
providers: [SocketService, DataCatalogService, DataCatalogAuthorizationService],
7980
exports: [],
8081
})
8182
export class DataCatalogModule {}

client/app/tool/tool-authorization.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class ToolAuthorizationService extends EntityAuthorizationService {
2121
return config.actionPermissionTypes.CREATE_TOOL.value;
2222
}
2323

24+
// TODO Remove when Tool can be made private
2425
/** @override */
2526
canRead(toolId: string): Observable<boolean> {
2627
return this.userPermissionDataService.permissions().pipe(

0 commit comments

Comments
 (0)