1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.DataAccess.ADOHelper;
|
---|
6 | using HeuristicLab.Security.Contracts.BusinessObjects;
|
---|
7 | using HeuristicLab.Security.DataAccess;
|
---|
8 | using HeuristicLab.Security.ADODataAccess.TableAdapterWrapper;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Security.ADODataAccess {
|
---|
11 | class PermissionAdapter: DataAdapterBase<
|
---|
12 | dsSecurityTableAdapters.PermissionTableAdapter,
|
---|
13 | Permission,
|
---|
14 | dsSecurity.PermissionRow>,
|
---|
15 | IPermissionAdapter {
|
---|
16 | public PermissionAdapter() :
|
---|
17 | base(new PermissionAdapterWrapper()) {
|
---|
18 | }
|
---|
19 |
|
---|
20 | private GrantedPermissionsAdapterWrapper grantedPermissionsAdapter;
|
---|
21 |
|
---|
22 | private GrantedPermissionsAdapterWrapper GrantedPermissionsAdapter {
|
---|
23 | get {
|
---|
24 | if (grantedPermissionsAdapter == null)
|
---|
25 | grantedPermissionsAdapter = new GrantedPermissionsAdapterWrapper();
|
---|
26 |
|
---|
27 | grantedPermissionsAdapter.Session = Session as Session;
|
---|
28 |
|
---|
29 | return grantedPermissionsAdapter;
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected override dsSecurity.PermissionRow ConvertObj(Permission perm,
|
---|
34 | dsSecurity.PermissionRow row) {
|
---|
35 | if (row != null && perm != null) {
|
---|
36 | row.PermissionId = perm.Id;
|
---|
37 | row.Name = perm.Name;
|
---|
38 | row.Description = perm.Description;
|
---|
39 | row.Plugin = perm.Plugin;
|
---|
40 |
|
---|
41 | return row;
|
---|
42 | } else {
|
---|
43 | return null;
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | protected override Permission ConvertRow(dsSecurity.PermissionRow row,
|
---|
48 | Permission perm) {
|
---|
49 | if (row != null && perm != null) {
|
---|
50 | perm.Id = row.PermissionId;
|
---|
51 | if (!row.IsNameNull())
|
---|
52 | perm.Name = row.Name;
|
---|
53 | else
|
---|
54 | perm.Name = String.Empty;
|
---|
55 |
|
---|
56 | if (!row.IsDescriptionNull())
|
---|
57 | perm.Description = row.Description;
|
---|
58 | else
|
---|
59 | perm.Description = String.Empty;
|
---|
60 |
|
---|
61 | if (!row.IsPluginNull())
|
---|
62 | perm.Plugin = row.Plugin;
|
---|
63 | else
|
---|
64 | perm.Plugin = String.Empty;
|
---|
65 |
|
---|
66 | return perm;
|
---|
67 | } else {
|
---|
68 | return null;
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | #region IPermissionAdapter Members
|
---|
73 |
|
---|
74 | #endregion
|
---|
75 |
|
---|
76 | #region IPermissionAdapter Members
|
---|
77 |
|
---|
78 | public GrantedPermission getPermission(Guid permissionOwnerId, Guid permissionId, Guid entityId) {
|
---|
79 | dsSecurity.GrantedPermissionsRow row =
|
---|
80 | GrantedPermissionsAdapter.FindByPermissionPermissionOwnerEntityId(
|
---|
81 | permissionId, permissionOwnerId, entityId);
|
---|
82 |
|
---|
83 | if (row != null) {
|
---|
84 | GrantedPermission perm = new GrantedPermission();
|
---|
85 | perm.PermissionId = row.PermissionId;
|
---|
86 | perm.PermissionOwnerId = row.PermissionOwnerId;
|
---|
87 | perm.EntityId = row.EntityId;
|
---|
88 |
|
---|
89 | return perm;
|
---|
90 | } else {
|
---|
91 | return null;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | public bool grantPermission(Guid permissionOwnerId, Guid permissionId, Guid entityId) {
|
---|
96 | if (getPermission(permissionOwnerId, permissionId, entityId) == null) {
|
---|
97 | GrantedPermission perm = new GrantedPermission();
|
---|
98 | perm.PermissionId = permissionId;
|
---|
99 | perm.PermissionOwnerId = permissionOwnerId;
|
---|
100 | perm.EntityId = entityId;
|
---|
101 |
|
---|
102 | return GrantedPermissionsAdapter.InsertNewRow(perm) != null;
|
---|
103 | } else {
|
---|
104 | return false;
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | public bool revokePermission(Guid permissionOwnerId, Guid permissionId, Guid entityId) {
|
---|
109 | GrantedPermission perm =
|
---|
110 | getPermission(permissionOwnerId, permissionId, entityId);
|
---|
111 |
|
---|
112 | if (perm != null) {
|
---|
113 | return GrantedPermissionsAdapter.DeleteRow(perm);
|
---|
114 | } else {
|
---|
115 | return false;
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | #endregion
|
---|
120 | }
|
---|
121 | }
|
---|