source: Network/HTTP/Modules/UPermission.pas

Last change on this file was 35, checked in by george, 14 years ago
  • Přidáno: Třídy pro běh web serveru, asociativní pole, dávkový přenos paketů.
File size: 4.4 KB
Line 
1unit UPermission;
2
3{$mode Delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, UWebObject, UCommon, USqlDatabase, UStringListEx;
9
10type
11 { TPermissionACL }
12
13 TPermissionACL = class
14 procedure Add(ARO, ACO: Integer);
15 procedure Copy(SourceARO, DestARO: Integer);
16 procedure Delete(ARO: Integer);
17 end;
18
19 { TPermissionACO }
20
21 TPermissionACO = class(TWebObject)
22 ACL: TPermissionACL;
23 procedure Delete(ACO: Integer);
24 procedure Add(Module, Action, Item: Integer);
25 end;
26
27 { TPermissionARO }
28
29 TPermissionARO = class(TWebObject)
30 ACL: TPermissionACL;
31 procedure Delete(ARO: Integer);
32 procedure Add(Group, User: Integer);
33 end;
34
35 { TPermission }
36
37 TPermission = class(TWebObject)
38 private
39 public
40 constructor Create;
41 destructor Destroy; override;
42 procedure RebuildCache;
43 function AppendFilter(SourceSQL: string; User, Action, ObjectId: Integer): string;
44 function GetARO(User, Group: Integer): Integer;
45 function GetACO(AObject, Row: Integer): Integer;
46 function Check(ARO, ACO, Action: Integer): Boolean;
47 function GetAROListForUser(User: Integer): TStringListEx;
48 function GetAROListForGroup(Group: Integer): TStringListEx;
49 end;
50
51implementation
52
53
54{ TPermission }
55
56constructor TPermission.Create;
57begin
58
59end;
60
61destructor TPermission.Destroy;
62begin
63 inherited Destroy;
64end;
65
66procedure TPermission.RebuildCache;
67begin
68
69end;
70
71function TPermission.AppendFilter(SourceSQL: string; User, Action, ObjectId: Integer): string;
72var
73 AROList: TStringListEx;
74begin
75 AROList := GetAROListForUser(User);
76 Result := 'SELECT `T`.* FROM (' + SourceSQL + ') AS `T` JOIN `PermissionACL` ON `PermissionACL`.`ARO` IN (' +
77 AROList.Implode(',') + ') AND `PermissionACL`.`Action` = ' + IntToStr(Action) +
78 ' JOIN `PermissionACO` ON `PermissionACO`.`Id` = `PermissionACL`.`ACO` AND `PermissionACO`.`Item` = `T`.`Id` AND `PermissionACO`.`Object` = ' +
79 IntToStr(ObjectId) + ' GROUP BY `T`.`Id`';
80 AROList.Destroy;
81end;
82
83function TPermission.GetARO(User, Group: Integer): Integer;
84begin
85
86end;
87
88function TPermission.GetACO(AObject, Row: Integer): Integer;
89begin
90
91end;
92
93function TPermission.Check(ARO, ACO, Action: Integer): Boolean;
94//var
95// ItemFilter: string;
96begin
97// if Item <> 0 then ItemFilter := ' AND (Item=' + IntToStr(Item) + ')'
98// else ItemFilter := ' AND (Item IS NULL)';
99
100end;
101
102function TPermission.GetAROListForUser(User: Integer): TStringListEx;
103var
104 DbRows: TDbRows;
105 I: Integer;
106 GroupItems: TStringListEx;
107begin
108 Result := TStringListEx.Create;
109 DbRows := Database.Query('SELECT * FROM `PermissionARO` WHERE `User`=' + IntToStr(User));
110 for I := 0 to DbRows.Count - 1 do begin
111 Result.Add(DbRows[I].Values['Id']);
112 end;
113 DbRows.Destroy;
114
115 // Append group items
116 DbRows := Database.Query('SELECT * FROM `UserGroupAssignment` WHERE `User`=' + IntToStr(User));
117 for I := 0 to DbRows.Count - 1 do begin
118 GroupItems := GetAROListForGroup(StrToInt(DbRows[I].Values['ParentGroup']));
119 Result.AddStrings(GroupItems);
120 GroupItems.Destroy;
121 end;
122 DbRows.Destroy;
123end;
124
125function TPermission.GetAROListForGroup(Group: Integer): TStringListEx;
126var
127 DbRows: TDbRows;
128 I: Integer;
129 GroupItems: TStringListEx;
130begin
131 Result := TStringListEx.Create;
132 DbRows := Database.Query('SELECT * FROM `PermissionARO` WHERE `Group`=' + IntToStr(Group));
133 for I := 0 to DbRows.Count - 1 do begin
134 Result.Add(DbRows[I].Values['Id']);
135 end;
136 DbRows.Destroy;
137
138 // Append subgroup items
139 DbRows := Database.Query('SELECT * FROM `UserGroupAssignment` WHERE `Group`=' + IntToStr(Group));
140 for I := 0 to DbRows.Count - 1 do begin
141 GroupItems := GetAROListForGroup(StrToInt(DbRows[I].Values['ParentGroup']));
142 Result.AddStrings(GroupItems);
143 GroupItems.Destroy;
144 end;
145 DbRows.Destroy;
146end;
147
148{ TPermissionACL }
149
150procedure TPermissionACL.Add(ARO, ACO: Integer);
151begin
152
153end;
154
155procedure TPermissionACL.Copy(SourceARO, DestARO: Integer);
156begin
157
158end;
159
160procedure TPermissionACL.Delete(ARO: Integer);
161begin
162
163end;
164
165{ TPermissionARO }
166
167procedure TPermissionARO.Delete(ARO: Integer);
168begin
169end;
170
171procedure TPermissionARO.Add(Group, User: Integer);
172begin
173
174end;
175
176{ TPermissionACO }
177
178procedure TPermissionACO.Delete(ACO: Integer);
179begin
180end;
181
182procedure TPermissionACO.Add(Module, Action, Item: Integer);
183begin
184
185end;
186
187end.
Note: See TracBrowser for help on using the repository browser.