Skip to content

Commit

Permalink
Refactor/permissions part 3 (#3801)
Browse files Browse the repository at this point in the history
* Show table

* Added routing to components and refactored edit

* Refactored to watt data table

* chore: add license

* poke

* Schema

* No need for page component

* Refactor and PR feedback

* chore: add license

* poke

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
mimse and github-actions[bot] authored Dec 2, 2024
1 parent d2c6526 commit 32e8348
Show file tree
Hide file tree
Showing 20 changed files with 542 additions and 506 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,25 @@ type ExchangeEventStatusReportResponse {
waitingForExternalResponse: Int!
}

"A connection to a list of items."
type FilteredPermissionsConnection {
"Information to aid in pagination."
pageInfo: PageInfo!
"A list of edges."
edges: [FilteredPermissionsEdge!]
"A flattened list of the nodes."
nodes: [Permission!]
permissionRelationsUrl: String
}

"An edge in a connection."
type FilteredPermissionsEdge {
"A cursor for use in pagination."
cursor: String!
"The item at the end of the edge."
node: Permission!
}

"A connection to a list of items."
type FilteredUserRolesConnection {
"Information to aid in pagination."
Expand Down Expand Up @@ -628,6 +647,7 @@ type Query {
organizations: [Organization!]!
searchOrganizationInCVR(cvr: String!): CVROrganizationResult!
permissionById(id: Int!): Permission!
filteredPermissions(filter: String "Returns the first _n_ elements from the list." first: Int "Returns the elements in the list that come after the specified cursor." after: String "Returns the last _n_ elements from the list." last: Int "Returns the elements in the list that come before the specified cursor." before: String order: [PermissionDtoSortInput!]): FilteredPermissionsConnection
permissions(searchTerm: String!): Permissions!
permissionAuditLogs(id: Int!): [PermissionAuditedChangeAuditLogDto!]!
permissionsByEicFunction(eicFunction: EicFunction!): [PermissionDetailsDto!]!
Expand Down Expand Up @@ -1022,6 +1042,13 @@ input MergeMarketParticipantsInput {
mergeDate: DateTime!
}

input PermissionDtoSortInput {
id: SortEnumType
name: SortEnumType
description: SortEnumType
created: SortEnumType
}

input ReActivateUserInput {
userId: UUID!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ public async Task<PermissionDto> GetPermissionByIdAsync(
[Service] IMarketParticipantClient_V1 client) =>
await client.PermissionGetAsync(id);

[UsePaging]
[UseSorting]
public async Task<IEnumerable<PermissionDto>> GetFilteredPermissionsAsync(
string? filter,
[Service] IMarketParticipantClient_V1 client) =>
(await client.PermissionGetAsync())
.Where(p =>
filter is null ||
p.Name.Contains(filter, StringComparison.CurrentCultureIgnoreCase) ||
p.Description.Contains(filter, StringComparison.CurrentCultureIgnoreCase));

public async Task<PermissionsDto> GetPermissionsAsync(
string searchTerm,
[Service] IMarketParticipantClient_V1 client) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2020 Energinet DataHub A/S
//
// Licensed under the Apache License, Version 2.0 (the "License2");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Energinet.DataHub.WebApi.Clients.MarketParticipant.v1;
using Energinet.DataHub.WebApi.GraphQL.Resolvers;

namespace Energinet.DataHub.WebApi.GraphQL.Types.Permission;

[ExtendObjectType("FilteredPermissionsConnection")]
public class FilteredPermissionsExtension
{
public string? GetPermissionRelationsUrl(
[Service] IHttpContextAccessor httpContextAccessor,
[Service] LinkGenerator linkGenerator) =>
linkGenerator.GetUriByAction(
httpContextAccessor.HttpContext!,
"GetPermissionRelations",
"MarketParticipantPermissions");
}
1 change: 1 addition & 0 deletions libs/dh/admin/data-access-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './lib/dh-admin-role.types';
export * from './lib/types/user-details.type';
export * from './lib/types/user.type';
export * from './lib/types/user-role.type';
export * from './lib/types/permission.type';
54 changes: 54 additions & 0 deletions libs/dh/admin/data-access-api/src/lib/types/permission.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//#region License
/**
* @license
* Copyright 2020 Energinet DataHub A/S
*
* Licensed under the Apache License, Version 2.0 (the "License2");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//#endregion
/**
* @license
* Copyright 2020 Energinet DataHub A/S
*
* Licensed under the Apache License, Version 2.0 (the "License2");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { ResultOf } from '@graphql-typed-document-node/core';

import {
GetFilteredPermissionsDocument,
GetPermissionDetailsDocument,
} from '@energinet-datahub/dh/shared/domain/graphql';

export type Permissions = NonNullable<
ResultOf<typeof GetFilteredPermissionsDocument>['filteredPermissions']
>['nodes'];

export type Permission = NonNullable<Permissions>[0];

export type DhPermissionDetailsUserRole = ResultOf<
typeof GetPermissionDetailsDocument
>['permissionById']['userRoles'][0];

export type DhPermissionDetailsMarketRole = ResultOf<
typeof GetPermissionDetailsDocument
>['permissionById']['assignableTo'][number];
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
query GetFilteredPermissions(
$after: String
$before: String
$first: Int
$last: Int
$filter: String
$order: [PermissionDtoSortInput!]
) {
filteredPermissions(
after: $after
before: $before
first: $first
last: $last
order: $order
filter: $filter
) {
pageInfo {
startCursor
endCursor
}
permissionRelationsUrl
nodes {
id
name
description
}
totalCount
}
}
2 changes: 1 addition & 1 deletion libs/dh/admin/feature-permissions-new/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
* limitations under the License.
*/
//#endregion
export { DhPermissionsPageComponent as default } from './lib/page.component';
export { DhPermissionsTableComponent as default } from './lib/table.component';
export { DhPermissionDetailComponent } from './lib/details/detail.component';
export { DhPermissionEditComponent } from './lib/details/edit.component';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*transloco="let t; read: 'admin.userManagement.permissionDetail'"
#drawer
size="large"
[loading]="isLoading()"
(closed)="onClose()"
>
<watt-drawer-heading>
Expand All @@ -36,46 +35,52 @@ <h2>{{ selectedPermission?.name }}</h2>
</watt-drawer-actions>

<watt-drawer-content>
@if (drawer.isOpen && selectedPermission) {
<watt-tabs>
<watt-tab [label]="t('information')">
<watt-card variant="solid">
<watt-description-list variant="stack">
<watt-description-list-item
[label]="t('permissionName')"
[value]="selectedPermission.name"
<dh-result [loading]="loading()" [hasError]="hasError()">
@if (drawer.isOpen && selectedPermission) {
<watt-tabs>
<watt-tab [label]="t('information')">
<watt-card variant="solid">
<watt-description-list variant="stack">
<watt-description-list-item
[label]="t('permissionName')"
[value]="selectedPermission.name"
/>
<watt-description-list-item
[label]="t('permissionDescription')"
[value]="selectedPermission.description"
/>
</watt-description-list>
</watt-card>
</watt-tab>
<watt-tab [label]="t('tabs.userRoles.tabLabel')">
@defer {
<dh-admin-permission-roles
[selectedPermission]="selectedPermission"
[loading]="loading()"
[hasError]="hasError()"
/>
<watt-description-list-item
[label]="t('permissionDescription')"
[value]="selectedPermission.description"
}
</watt-tab>
<watt-tab [label]="t('tabs.marketRoles.tabLabel')">
@defer {
<dh-admin-permission-market-roles
[loading]="loading()"
[hasError]="hasError()"
[selectedPermission]="selectedPermission"
/>
</watt-description-list>
</watt-card>
</watt-tab>
<watt-tab [label]="t('tabs.userRoles.tabLabel')">
<dh-admin-permission-roles [selectedPermission]="selectedPermission" />
</watt-tab>
<watt-tab [label]="t('tabs.marketRoles.tabLabel')">
<dh-admin-permission-market-roles [selectedPermission]="selectedPermission" />
</watt-tab>
<watt-tab
*dhPermissionRequired="['user-roles:manage']"
[label]="t('tabs.history.tabLabel')"
>
<dh-admin-permission-audit-logs [selectedPermission]="selectedPermission" />
</watt-tab>
</watt-tabs>
}

@if (hasError()) {
<vater-flex direction="column" offset="m" justify="center">
<watt-empty-state
icon="custom-power"
[title]="'shared.error.title' | transloco"
[message]="'shared.error.message' | transloco"
></watt-empty-state>
</vater-flex>
}
}
</watt-tab>
<watt-tab
*dhPermissionRequired="['user-roles:manage']"
[label]="t('tabs.history.tabLabel')"
>
@defer {
<dh-admin-permission-audit-logs [selectedPermission]="selectedPermission" />
}
</watt-tab>
</watt-tabs>
}
</dh-result>
</watt-drawer-content>
</watt-drawer>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ import {
ChangeDetectionStrategy,
} from '@angular/core';

import { TranslocoDirective, TranslocoPipe } from '@ngneat/transloco';
import { RouterOutlet } from '@angular/router';

import { TranslocoDirective } from '@ngneat/transloco';

import {
WattDescriptionListComponent,
WattDescriptionListItemComponent,
} from '@energinet-datahub/watt/description-list';

import { WattCardComponent } from '@energinet-datahub/watt/card';
import { VaterFlexComponent } from '@energinet-datahub/watt/vater';
import { WattButtonComponent } from '@energinet-datahub/watt/button';
import { WattEmptyStateComponent } from '@energinet-datahub/watt/empty-state';
import { WattDrawerComponent, WATT_DRAWER } from '@energinet-datahub/watt/drawer';
import { WattTabsComponent, WattTabComponent } from '@energinet-datahub/watt/tabs';

import { lazyQuery } from '@energinet-datahub/dh/shared/util-apollo';
import { DhResultComponent } from '@energinet-datahub/dh/shared/ui-util';
import { DhNavigationService } from '@energinet-datahub/dh/shared/navigation';
import { GetPermissionDetailsDocument } from '@energinet-datahub/dh/shared/domain/graphql';
import { DhPermissionRequiredDirective } from '@energinet-datahub/dh/shared/feature-authorization';

import { DhAdminPermissionRolesComponent } from './tabs/admin-permission-roles.component';
import { DhPermissionAuditLogsComponent } from './tabs/audit-logs.component';
import { DhAdminPermissionRolesComponent } from './tabs/admin-permission-roles.component';
import { DhAdminPermissionMarketRolesComponent } from './tabs/market-roles.component';
import { RouterOutlet } from '@angular/router';

@Component({
selector: 'dh-permission-detail',
Expand All @@ -57,20 +57,17 @@ import { RouterOutlet } from '@angular/router';
templateUrl: './detail.component.html',
imports: [
RouterOutlet,
TranslocoPipe,
TranslocoDirective,

WATT_DRAWER,
WattTabComponent,
WattCardComponent,
WattTabsComponent,
WattButtonComponent,
WattEmptyStateComponent,
WattDescriptionListComponent,
WattDescriptionListItemComponent,

VaterFlexComponent,

DhResultComponent,
DhPermissionRequiredDirective,
DhPermissionAuditLogsComponent,
DhAdminPermissionRolesComponent,
Expand All @@ -88,7 +85,7 @@ export class DhPermissionDetailComponent {

permission = computed(() => this.query.data()?.permissionById);

isLoading = this.query.loading;
loading = this.query.loading;
hasError = this.query.hasError;

constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
UpdatePermissionDocument,
GetPermissionEditDocument,
GetPermissionDetailsDocument,
GetPermissionAuditLogsDocument,
} from '@energinet-datahub/dh/shared/domain/graphql';

import {
Expand Down Expand Up @@ -156,7 +157,11 @@ export class DhPermissionEditComponent {
}

const result = await this.updatePermission.mutate({
refetchQueries: [GetPermissionsDocument, GetPermissionDetailsDocument],
refetchQueries: [
GetPermissionsDocument,
GetPermissionDetailsDocument,
GetPermissionAuditLogsDocument,
],
variables: {
input: {
id: parseInt(this.id()),
Expand Down
Loading

0 comments on commit 32e8348

Please sign in to comment.