Ignore:
Timestamp:
Oct 8, 2012, 8:48:16 AM (12 years ago)
Author:
chronos
Message:
  • Upraveno: TWebSession zobecněno pro možnost implementace více modulů s obsluhou vstupní stránky.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CoolWeb/Modules/UUser.pas

    r100 r103  
    3131    function GetIdByNamePassword(Name: string; PassWord: string): Integer;
    3232    procedure Load;
     33    function CheckPermission(Module, Operation: string; ItemType: string = '';
     34      ItemId: Integer = 0): Boolean;
     35    function CheckGroupPermission(Group, Operation: Integer): Boolean;
    3336  end;
    3437
     
    215218end;
    216219
     220function TWebUser.CheckPermission(Module, Operation: string;
     221  ItemType: string = ''; ItemId: Integer = 0): Boolean;
     222var
     223  DbRows: TDbRows;
     224  DbRows2: TDbRows;
     225  OperationId: Integer;
     226begin
     227  Result := False;
     228  try
     229    DbRows := TDbRows.Create;
     230    Database.Query(DbRows, 'SELECT `Id` FROM `PermissionOperation` WHERE `Module`="' + Module + '"' +
     231    ' AND `Operation` = "' + Operation + '" AND `Item` = "' + ItemType + '"' +
     232    ' AND `ItemId` = ' + IntToStr(ItemId));
     233    if DbRows.Count > 0 then
     234    try
     235      DbRows2 := TDbRows.Create;
     236      OperationId := StrToInt(DbRows[0].Values['Id']);
     237
     238      // Check user-operation relation
     239      Database.Select(DbRows2, 'PermissionUserAssignment', 'Id',
     240        '`User` = ' + IntToStr(Id) + ' AND `AssignedOperation` = ' + IntToStr(OperationId));
     241      if DbRows2.Count > 0 then begin
     242        Result := True;
     243        Exit;
     244      end;
     245
     246      // Check user-group relation
     247      Database.Select(DbRows2, 'PermissionUserAssignment', 'AssignedGroup',
     248        '`User` = ' + IntToStr(Id) + ' AND `AssignedGroup` IS NOT NULL');
     249      if DbRows2.Count > 0 then begin
     250        if CheckGroupPermission(StrToInt(DbRows2[0].Values['AssignedGroup']), OperationId) then begin
     251          Result := True;
     252          Exit;
     253        end;
     254      end;
     255    finally
     256      DbRows2.Free;
     257    end;
     258  finally
     259    DBRows.Free;
     260  end;
     261end;
     262
     263function TWebUser.CheckGroupPermission(Group, Operation: Integer): Boolean;
     264var
     265  DbRows2: TDbRows;
     266begin
     267  Result := False;
     268  try
     269      DbRows2 := TDbRows.Create;
     270
     271      // Check group-operation relation
     272      Database.Select(DbRows2, 'PermissionGroupAssignment', 'Id',
     273        '`User` = ' + IntToStr(Id) + ' AND `AssignedOperation` = ' + IntToStr(Operation));
     274      if DbRows2.Count > 0 then begin
     275        Result := True;
     276        Exit;
     277      end;
     278
     279      // Check group-group relation
     280      Database.Select(DbRows2, 'PermissionGroupAssignment', 'AssignedGroup',
     281        '`User` = ' + IntToStr(Id) + ' AND `AssignedGroup` IS NOT NULL');
     282      if DbRows2.Count > 0 then begin
     283        if CheckGroupPermission(StrToInt(DbRows2[0].Values['AssignedGroup']), Operation) then begin
     284          Result := True;
     285          Exit;
     286        end;
     287      end;
     288    finally
     289      DbRows2.Free;
     290    end;
     291end;
     292
    217293end.
    218294
Note: See TracChangeset for help on using the changeset viewer.