Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: possibility to check for multiple permissions #590

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export class DataListGridComponent extends DataSortBase implements OnInit, DoChe
@Input() emptyResultsMessage: string | undefined
@Input() fallbackImage = 'placeholder.png'
@Input() layout: 'grid' | 'list' = 'grid'
@Input() viewPermission: string | undefined
@Input() editPermission: string | undefined
@Input() deletePermission: string | undefined
@Input() viewPermission: string | string[] | undefined
@Input() editPermission: string | string[] | undefined
@Input() deletePermission: string | string[] | undefined
@Input() deleteActionVisibleField: string | undefined
@Input() deleteActionEnabledField: string | undefined
@Input() viewActionVisibleField: string | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon

@Input() emptyResultsMessage: string | undefined
@Input() name = ''
@Input() deletePermission: string | undefined
@Input() viewPermission: string | undefined
@Input() editPermission: string | undefined
@Input() deletePermission: string | string[] | undefined
@Input() viewPermission: string | string[] | undefined
@Input() editPermission: string | string[] | undefined
@Input() deleteActionVisibleField: string | undefined
@Input() deleteActionEnabledField: string | undefined
@Input() viewActionVisibleField: string | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class DataViewComponent implements DoCheck, OnInit, AfterContentInit {
dataTableComponentState$ = new ReplaySubject<DataTableComponentState>(1)
dataListGridComponentState$ = new ReplaySubject<DataListGridComponentState>(1)

@Input() deletePermission: string | undefined
@Input() editPermission: string | undefined
@Input() viewPermission: string | undefined
@Input() deletePermission: string | string[] | undefined
@Input() editPermission: string | string[] | undefined
@Input() viewPermission: string | string[] | undefined
@Input() deleteActionVisibleField: string | undefined
@Input() deleteActionEnabledField: string | undefined
@Input() viewActionVisibleField: string | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export class InteractiveDataViewComponent implements OnInit, AfterContentInit {
dataViewComponentState$ = new ReplaySubject<DataViewComponentState>(1)
filterViewComponentState$ = new ReplaySubject<FilterViewComponentState>(1)

@Input() searchConfigPermission: string | undefined
@Input() deletePermission: string | undefined
@Input() editPermission: string | undefined
@Input() viewPermission: string | undefined
@Input() searchConfigPermission: string | string[] | undefined
@Input() deletePermission: string | string[] | string[] | undefined
@Input() editPermission: string | string[] | undefined
@Input() viewPermission: string | string[] | undefined
@Input() deleteActionVisibleField: string | undefined
@Input() deleteActionEnabledField: string | undefined
@Input() viewActionVisibleField: string | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('PageHeaderComponent', () => {
let component: PageHeaderComponent
let fixture: ComponentFixture<PageHeaderComponent>
let pageHeaderHarness: PageHeaderHarness
let userServiceSpy: jest.SpyInstance<boolean, [permissionKey: string], any>
let userServiceSpy: jest.SpyInstance<boolean, [permissionKey: string | string[]], any>

beforeEach(async () => {
await TestBed.configureTestingModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class SearchHeaderComponent implements AfterContentInit, AfterViewInit {
this._actions = value
this.updateHeaderActions()
}
@Input() searchConfigPermission: string | undefined
@Input() searchConfigPermission: string | string[] | undefined
@Input() searchButtonDisabled = false
@Input() resetButtonDisabled = false
@Input() pageName: string | undefined = getLocation().applicationPath
Expand Down
2 changes: 1 addition & 1 deletion libs/angular-accelerator/src/lib/model/data-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface DataAction {
id?: string
labelKey?: string
icon?: string
permission: string
permission: string | string[]
classes?: string[]
disabled?: boolean
actionVisibleField?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BehaviorSubject } from 'rxjs'
export class MockUserService {
lang$ = new BehaviorSubject<string>('en')
/* eslint-disable @typescript-eslint/no-unused-vars */
hasPermission(permissionKey: string): boolean {
hasPermission(permissionKey: string | string[]): boolean {
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export class UserService implements OnDestroy {
this.profile$.destroy()
}

hasPermission(permissionKey: string): boolean {
hasPermission(permissionKey: string | string[]): boolean {
if (Array.isArray(permissionKey)) {
return permissionKey.every((key) => this.hasPermission(key))
}
const oldConceptResult = this.permissions$.getValue()
? this.permissions$.getValue()?.includes(permissionKey)
: false
Expand Down
Loading