Skip to content

Commit

Permalink
feat(backend): add permission categories & migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
eilrix committed Apr 29, 2022
1 parent 72e869a commit 4ea0773
Show file tree
Hide file tree
Showing 28 changed files with 567 additions and 98 deletions.
11 changes: 10 additions & 1 deletion plugins/newsletter/src/backend/auth.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { TCustomPermission } from '@cromwell/core';
import { registerPermission } from '@cromwell/core-backend';
import { registerPermission, registerPermissionCategory } from '@cromwell/core-backend';

export const newsletterPermissions: Record<string, TCustomPermission> = {
stats: {
name: 'newsletter_stats',
title: 'Read Newsletter plugin statistics',
categoryName: 'newsletter_category',
},
export: {
name: 'newsletter_export',
title: 'Read Newsletter plugin data (list of subscribers)',
categoryName: 'newsletter_category',
},
}

registerPermissionCategory({
name: 'newsletter_category',
title: 'Newsletter plugin',
moduleName: '@cromwell/plugin-newsletter',
moduleTitle: 'Newsletter plugin',
});

Object.values(newsletterPermissions).forEach(registerPermission);
4 changes: 2 additions & 2 deletions system/admin-panel/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'react-resizable/css/styles.css';
import 'react-toastify/dist/ReactToastify.css';

import { getStoreItem, matchPermissions, onStoreChange, setStoreItem, TUser } from '@cromwell/core';
import { getGraphQLClient, getRestApiClient, TErrorInfo } from '@cromwell/core-frontend';
import { getGraphQLClient, getRestApiClient, TRestApiErrorInfo } from '@cromwell/core-frontend';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux-ts';
Expand Down Expand Up @@ -87,7 +87,7 @@ import { store } from './redux/store';
restClient?.onUnauthorized(onUnauthorized, onUnauthorizedCbId);
graphClient?.onUnauthorized(onUnauthorized, onUnauthorizedCbId);

const onRestApiError = (info: TErrorInfo) => {
const onRestApiError = (info: TRestApiErrorInfo) => {
if (info?.statusCode === 429) {
toast.error('Too many requests. Try again later');
} else {
Expand Down
2 changes: 1 addition & 1 deletion system/core/backend/src/_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ export * from './helpers/entity-meta';
export * from './helpers/connect-database';
export {
getCurrentRoles, getUserRole, DefaultPermissions, CustomPermissions,
registerPermission, getPermissions,
registerPermission, getPermissions, registerPermissionCategory,
} from './helpers/auth-roles-permissions';
Loading

0 comments on commit 4ea0773

Please sign in to comment.