Skip to content

Commit d4dedb8

Browse files
committed
Grant permission
1 parent ff13e2e commit d4dedb8

File tree

2 files changed

+126
-17
lines changed

2 files changed

+126
-17
lines changed

src/adabas/admin.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,35 @@ export class AdabasAdmin {
228228
}
229229
}
230230
// Get the Adabas RBAC permission list of the Adabas database
231+
assignRole(user: string,role:string): Promise<any> {
232+
var def = {
233+
Definition: [
234+
{
235+
Assignment: 'grant',
236+
User: user,
237+
Role: role,
238+
},
239+
],
240+
};
241+
const getConfig = {
242+
headers: authHeader("application/json"),
243+
useCredentails: true,
244+
};
245+
try {
246+
return axios
247+
.put(config.Url() + "/adabas/database/" + this.status.Dbid + "/permission/" ,def, getConfig);
248+
}
249+
catch (error: any) {
250+
if (error.response) {
251+
if (error.response.status == 401 || error.response.status == 403) {
252+
userService.logout();
253+
location.reload();
254+
}
255+
}
256+
throw error;
257+
}
258+
}
259+
// Get the Adabas RBAC permission list of the Adabas database
231260
grantRBAC(def: any): Promise<any> {
232261
const getConfig = {
233262
headers: authHeader("application/json"),

src/components/PermissionList.vue

Lines changed: 97 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@
3434
<Url :url="'/adabas/database' + url + '/file'" />
3535
</b-col>
3636
</b-row>
37+
<b-row>
38+
<b-col sm="2">
39+
<b-button v-b-modal.modal-create variant="outline-primary"
40+
>Create resource</b-button
41+
> </b-col
42+
><b-col sm="2">
43+
<b-button v-b-modal.modal-grant variant="outline-primary"
44+
>Grant resource</b-button
45+
> </b-col
46+
><b-col sm="2">
47+
<b-button v-b-modal.modal-assign variant="outline-primary"
48+
>Assign role</b-button
49+
>
50+
</b-col>
51+
<b-col sm="6" class="text-right">
52+
<b-button variant="outline-primary">Refresh</b-button>
53+
</b-col>
54+
</b-row>
3755
<b-row
3856
><b-col sm="10">
3957
<b-tabs content-class="mt-3">
@@ -118,20 +136,7 @@
118136
class="mt-3"
119137
></b-form-select> </b-col></b-row
120138
><b-row>
121-
<b-col sm="2">
122-
<b-button
123-
v-b-modal.modal-create
124-
variant="outline-primary"
125-
>Create resource</b-button
126-
> </b-col
127-
><b-col sm="2">
128-
<b-button
129-
v-b-modal.modal-grant
130-
variant="outline-primary"
131-
>Grant resource</b-button
132-
>
133-
</b-col>
134-
<b-col sm="8">
139+
<b-col sm="12">
135140
<b-form-group
136141
label="Filter"
137142
label-cols-sm="3"
@@ -213,25 +218,71 @@
213218
id="modal-grant"
214219
size="lg"
215220
title="Create Adabas Role-Base resource"
216-
@ok="createResource"
221+
@ok="grantResource"
217222
no-stacking
218223
>
219224
<p>Create Adabas Role-based Access resource</p>
220225
<b-container>
221226
<b-row>
222227
<b-col sm="2">Object:</b-col>
223-
<b-col sm="9">
228+
<b-col sm="4">
224229
<b-form-select
225230
v-model="newObject"
226231
:options="objects"
227232
></b-form-select> </b-col
233+
><b-col sm="5">
234+
<b-form-input
235+
type="number"
236+
v-model="fnr"
237+
placeholder="Adabas File"
238+
></b-form-input></b-col
228239
></b-row>
229240
<b-row>
230241
<b-col sm="2">Operation:</b-col>
231242
<b-col sm="9">
232243
<b-form-select
233244
v-model="newOperation"
234245
:options="operations"
246+
></b-form-select>
247+
</b-col>
248+
</b-row>
249+
<b-row>
250+
<b-col sm="2">Assign to Role:</b-col>
251+
<b-col sm="9">
252+
<b-form-select
253+
v-model="newRole"
254+
:options="roles"
255+
></b-form-select> </b-col
256+
></b-row>
257+
</b-container>
258+
<template #modal-footer="{ ok, cancel, hide }">
259+
<b>Custom Footer</b>
260+
<!-- Emulate built in modal footer ok and cancel button actions -->
261+
<b-button size="sm" variant="success" @click="ok()"> Grant </b-button>
262+
<b-button size="sm" variant="danger" @click="cancel()">
263+
Revoke
264+
</b-button>
265+
<!-- Button with custom close trigger value -->
266+
<b-button size="sm" variant="outline-secondary" @click="hide('forget')">
267+
Forget it
268+
</b-button>
269+
</template>
270+
</b-modal>
271+
<b-modal
272+
id="modal-assign"
273+
size="lg"
274+
title="Assignn Adabas Role-Base resource to user"
275+
@ok="assignUser"
276+
no-stacking
277+
>
278+
<p>Assign Adabas Role-based Access resource</p>
279+
<b-container>
280+
<b-row>
281+
<b-col sm="2">Assign to User:</b-col>
282+
<b-col sm="9">
283+
<b-form-select
284+
v-model="newName"
285+
:options="users"
235286
></b-form-select> </b-col
236287
></b-row>
237288
<b-row>
@@ -243,6 +294,18 @@
243294
></b-form-select> </b-col
244295
></b-row>
245296
</b-container>
297+
<template #modal-footer="{ ok, cancel, hide }">
298+
<b>Custom Footer</b>
299+
<!-- Emulate built in modal footer ok and cancel button actions -->
300+
<b-button size="sm" variant="success" @click="ok()"> Grant </b-button>
301+
<b-button size="sm" variant="danger" @click="cancel()">
302+
Revoke
303+
</b-button>
304+
<!-- Button with custom close trigger value -->
305+
<b-button size="sm" variant="outline-secondary" @click="hide('forget')">
306+
Forget it
307+
</b-button>
308+
</template>
246309
</b-modal>
247310
<StatusBar />
248311
</div>
@@ -278,6 +341,7 @@ export default class PermissionList extends Vue {
278341
operations: [],
279342
objects: [],
280343
roles: [],
344+
users: [],
281345
fields: ['Operation', 'Object', 'Role'],
282346
userRoleFields: ['User', 'Role'],
283347
options: ['User', 'Role', 'Object', 'Operation'],
@@ -290,6 +354,7 @@ export default class PermissionList extends Vue {
290354
newRole: '',
291355
newObject: '',
292356
newOperation: '',
357+
fnr: undefined as number | undefined,
293358
};
294359
}
295360
created(): void {
@@ -318,7 +383,7 @@ export default class PermissionList extends Vue {
318383
}
319384
if (this.$data.operations.length == 0) {
320385
this.$data.db.resourceList('operation').then((response: any) => {
321-
this.$data.operations = [];
386+
this.$data.operations = ['any'];
322387
response.forEach((element: any) => {
323388
this.$data.operations.push(element.Operation);
324389
});
@@ -332,6 +397,15 @@ export default class PermissionList extends Vue {
332397
});
333398
});
334399
}
400+
if (this.$data.users.length == 0) {
401+
this.$data.db.resourceList('user').then((response: any) => {
402+
this.$data.users = [];
403+
response.forEach((element: any) => {
404+
console.log("USER: "+JSON.stringify(element)+'->'+element.User);
405+
this.$data.users.push(element.User);
406+
});
407+
});
408+
}
335409
336410
await this.$data.db.permissionList().then((response: any) => {
337411
this.$data.permission = response;
@@ -366,6 +440,12 @@ export default class PermissionList extends Vue {
366440
},
367441
],
368442
};
443+
if (this.$data.fnr) {
444+
var s = '000000000' + this.$data.fnr;
445+
s = s.substr(s.length - 8);
446+
447+
def.Definition[0].Object = 'FILE.' + s;
448+
}
369449
this.$data.db.grantRBAC(def);
370450
}
371451
reloadResource() {

0 commit comments

Comments
 (0)