Skip to content

Commit

Permalink
feat(permission): add dynamic permission managemnent support.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinin committed Oct 24, 2023
1 parent 74dbcc6 commit 8378bf3
Show file tree
Hide file tree
Showing 68 changed files with 2,909 additions and 326 deletions.
40 changes: 40 additions & 0 deletions apps/vue/src/api/permission-management/definitions/groups/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { defHttp } from '/@/utils/http/axios';
import {
PermissionGroupDefinitionDto,
PermissionGroupDefinitionCreateDto,
PermissionGroupDefinitionUpdateDto,
PermissionGroupDefinitionGetListInput,
} from './model';

export const CreateAsyncByInput = (input: PermissionGroupDefinitionCreateDto) => {
return defHttp.post<PermissionGroupDefinitionDto>({
url: '/api/permission-management/definitions/groups',
data: input,
});
};

export const DeleteAsyncByName = (name: string) => {
return defHttp.delete<void>({
url: `/api/permission-management/definitions/groups/${name}`,
});
};

export const GetAsyncByName = (name: string) => {
return defHttp.get<PermissionGroupDefinitionDto>({
url: `/api/permission-management/definitions/groups/${name}`,
});
};

export const GetListAsyncByInput = (input: PermissionGroupDefinitionGetListInput) => {
return defHttp.get<ListResultDto<PermissionGroupDefinitionDto>>({
url: '/api/permission-management/definitions/groups',
params: input,
});
};

export const UpdateAsyncByNameAndInput = (name: string, input: PermissionGroupDefinitionUpdateDto) => {
return defHttp.put<PermissionGroupDefinitionDto>({
url: `/api/permission-management/definitions/groups/${name}`,
data: input,
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
interface PermissionGroupDefinitionCreateOrUpdateDto extends IHasExtraProperties {
displayName: string;
}

export interface PermissionGroupDefinitionCreateDto extends PermissionGroupDefinitionCreateOrUpdateDto {
name: string;
}

export interface PermissionGroupDefinitionDto extends IHasExtraProperties {
name: string;
displayName: string;
isStatic: boolean;
}

export interface PermissionGroupDefinitionGetListInput {
filter?: string;
}

export type PermissionGroupDefinitionUpdateDto = PermissionGroupDefinitionCreateOrUpdateDto;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { defHttp } from '/@/utils/http/axios';
import {
PermissionDefinitionDto,
PermissionDefinitionCreateDto,
PermissionDefinitionUpdateDto,
PermissionDefinitionGetListInput,
} from './model';

export const CreateAsyncByInput = (input: PermissionDefinitionCreateDto) => {
return defHttp.post<PermissionDefinitionDto>({
url: '/api/permission-management/definitions',
data: input,
});
};

export const DeleteAsyncByName = (name: string) => {
return defHttp.delete<void>({
url: `/api/permission-management/definitions/${name}`,
});
};

export const GetAsyncByName = (name: string) => {
return defHttp.get<PermissionDefinitionDto>({
url: `/api/permission-management/definitions/${name}`,
});
};

export const GetListAsyncByInput = (input: PermissionDefinitionGetListInput) => {
return defHttp.get<ListResultDto<PermissionDefinitionDto>>({
url: '/api/permission-management/definitions',
params: input,
});
};

export const UpdateAsyncByNameAndInput = (name: string, input: PermissionDefinitionUpdateDto) => {
return defHttp.put<PermissionDefinitionDto>({
url: `/api/permission-management/definitions/${name}`,
data: input,
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export enum MultiTenancySides {
Tenant = 0x1,
Host = 0x2,
Both = 0x3,
}

interface PermissionDefinitionCreateOrUpdateDto extends IHasExtraProperties {
displayName: string;
parentName?: string;
isEnabled: boolean;
providers: string[];
stateCheckers: string;
}

export interface PermissionDefinitionCreateDto extends PermissionDefinitionCreateOrUpdateDto {
groupName: string;
name: string;
}

export interface PermissionDefinitionDto extends IHasExtraProperties {
groupName: string;
name: string;
displayName: string;
parentName?: string;
isEnabled: boolean;
isStatic: boolean;
providers: string[];
stateCheckers: string;
}

export interface PermissionDefinitionGetListInput {
filter?: string;
groupName?: string;
}

export type PermissionDefinitionUpdateDto = PermissionDefinitionCreateOrUpdateDto;
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { defAbpHttp } from '/@/utils/http/abp';
import { PermissionProvider, PermissionResult, UpdatePermissions } from './model/permissionModel';

enum Api {
Get = '/api/permission-management/permissions',
Update = '/api/permission-management/permissions',
}
import { PermissionProvider, PermissionResult, UpdatePermissions } from './model';

export const get = (provider: PermissionProvider) => {
return defAbpHttp.get<PermissionResult>({
url: Api.Get,
url: '/api/permission-management/permissions',
params: provider,
});
};

export const update = (provider: PermissionProvider, input: UpdatePermissions) => {
return defAbpHttp.put<void>({
url: Api.Update,
url: '/api/permission-management/permissions',
data: input,
params: provider,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IPermission } from '../../model/baseModel';
import { IPermission } from '/@/api/model/baseModel';

export class PermissionProvider {
providerName!: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Button v-if="props.allowDelete" danger @click="handleClean">{{ t('component.extra_property_dictionary.actions.clean') }}</Button>
</div>
<Card :title="t('component.extra_property_dictionary.title')">
<Table v-bind="state.table">
<Table sticky rowKey="key" :columns="getTableColumns" :data-source="state.table.dataSource" :scroll="{ x: 1500 }">
<template v-if="!props.disabled" #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<div :class="`${prefixCls}__action`">
Expand Down Expand Up @@ -47,21 +47,24 @@
</template>

<script lang="ts" setup>
import type { TableProps } from 'ant-design-vue';
import type { RuleObject } from 'ant-design-vue/lib/form';
import type { ColumnsType } from 'ant-design-vue/lib/table/interface';
import { cloneDeep } from 'lodash-es';
import { computed, reactive, ref, unref, watch } from 'vue';
import { DeleteOutlined, EditOutlined } from '@ant-design/icons-vue';
import { nextTick, reactive, ref, unref, watch } from 'vue';
import { Button, Card, Divider, Form, Input, Table, Modal } from 'ant-design-vue';
import { useDesign } from '/@/hooks/web/useDesign';
import { useI18n } from '/@/hooks/web/useI18n';
import { propTypes } from '/@/utils/propTypes';
const FormItem = Form.Item;
interface DataSource {
key: string;
value: string;
}
interface State {
editFlag: boolean,
table: TableProps,
modal: {
title?: string,
visible?: boolean,
Expand All @@ -75,6 +78,9 @@
model: any,
rules?: Dictionary<string, RuleObject>,
},
table: {
dataSource: DataSource[],
},
}
const emits = defineEmits(['change', 'update:value']);
Expand All @@ -90,6 +96,32 @@
const { prefixCls } = useDesign('extra-property-dictionary');
const { t } = useI18n();
const formRef = ref<any>();
const getTableColumns = computed(() => {
const columns: ColumnsType = [{
title: t('component.extra_property_dictionary.key'),
dataIndex: 'key',
align: 'left',
fixed: 'left',
width: 180,
},
{
title: t('component.extra_property_dictionary.value'),
dataIndex: 'value',
align: 'left',
fixed: 'left',
width: 'auto',
}];
return columns.concat(props.disabled
? []
: [{
width: 220,
title: t('component.extra_property_dictionary.actions.title'),
align: 'center',
dataIndex: 'action',
key: 'action',
fixed: 'right',
}]);
});
const state = reactive<State>({
editFlag: false,
modal: {
Expand All @@ -114,29 +146,8 @@
},
},
table: {
sticky: true,
rowKey: "key",
columns: [
{
title: t('component.extra_property_dictionary.key'),
dataIndex: 'key',
align: 'left',
fixed: 'left',
width: 180,
},
{
title: t('component.extra_property_dictionary.value'),
dataIndex: 'value',
align: 'left',
fixed: 'left',
width: 'auto',
}
],
dataSource: [],
scroll: {
x: 1500,
},
}
},
});
watch(
() => props.value,
Expand All @@ -156,33 +167,6 @@
immediate: true,
}
);
watch(
() => [props.allowEdit, props.allowDelete],
([allowEdit, allowDelete]) => {
if (allowEdit || allowDelete) {
nextTick(() => {
state.table.columns!.push({
width: 220,
title: t('component.extra_property_dictionary.actions.title'),
align: 'center',
dataIndex: 'action',
key: 'action',
fixed: 'right',
});
});
} else {
nextTick(() => {
const columns = state.table.columns ?? [];
const findIndex = columns.findIndex(x => x.key === 'action');
columns.splice(findIndex, 1);
state.table.columns = columns;
});
}
},
{
immediate: true,
}
)
function handleAddNew() {
state.form.model = {};
Expand Down
Loading

0 comments on commit 8378bf3

Please sign in to comment.