#1 2023-09-14 06:40:04

damiand
Member
From: Greece
Registered: 2018-09-21
Posts: 94

How to update TAuthGroup AccessRights?

Hi, the following code (when running it as Admin) executes with no exceptions, but the AccessRights field is not updated from its default value:

  grp := TAuthGroup.CreateAndFillPrepare(MainForm.RestClient.Orm, 'ID=?', [3]);
  try
    if grp.FillOne then
    begin
      grp.SqlAccessRights.Edit(MainForm.RestClient.Model, TStatus,
              false, true, false, false);
      grp.SqlAccessRights.Edit(MainForm.RestClient.Model, TPerson,
              false, true, false, false);
      MainForm.RestClient.Update(grp);
    end;
  finally
    grp.Free
  end;

why?

Offline

#2 2023-09-14 07:08:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: How to update TAuthGroup AccessRights?

Because you don't have the rights to modify other user rights, I guess.

Try to debug on the server side to see what is happening.

Offline

#3 2023-09-15 06:40:16

damiand
Member
From: Greece
Registered: 2018-09-21
Posts: 94

Re: How to update TAuthGroup AccessRights?

Well, since the connected account is Admin and no update to the AccessRights property of the AuthGroup object was made before the Rest db update action, I did a debug on the client side, and found the following:

The TOrmAccessRights record (not an object, indeed), did not preserve the GET, PUT, POST, DELETE arrays between the call of the Edit method and a call of the toString method. To testify this, the following workaround code works fine!

var
  grp: TAuthGroup;
  oar: TOrmAccessRights;
  ars: RawUTF8;
begin
  grp := TAuthGroup.CreateAndFillPrepare(MainForm.RestClient.Orm, 'ID=?', [3]);
  try
    if grp.FillOne then
    begin
      oar := grp.SqlAccessRights;
      oar.Edit(MainForm.RestClient.Model, TStatus, false, true, false, false);
      oar.Edit(MainForm.RestClient.Model, TPerson, false, true, false, false);
      FormatUtf8('%,%,%,%,%', [byte(oar.AllowRemoteExecute),
        GetBitCsv(oar.GET, MAX_TABLES), GetBitCsv(oar.POST, MAX_TABLES),
        GetBitCsv(oar.PUT, MAX_TABLES), GetBitCsv(oar.DELETE, MAX_TABLES)], ars);
      grp.AccessRights := ars;
      MainForm.RestClient.Update(grp);
    end;
  finally
    grp.Free
  end;
end;

Offline

#4 2023-09-15 07:06:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: How to update TAuthGroup AccessRights?

This is a compiler limitation.

I think you can just write:

      oar := grp.OrmAccessRights;
      oar.Edit(MainForm.RestClient.Model, TStatus, false, true, false, false);
      oar.Edit(MainForm.RestClient.Model, TPerson, false, true, false, false);
      grp.OrmAccessRights := oar;

I have enhanced the documentation, and renamed SqlAccessRight as OrmAccessRight as it should be (in PUREMORMOT2 mode).
https://github.com/synopse/mORMot2/commit/73814dfd

Offline

#5 2023-09-15 09:21:42

damiand
Member
From: Greece
Registered: 2018-09-21
Posts: 94

Re: How to update TAuthGroup AccessRights?

Indeed @ab, you are right! Btw, the compiler is 32bit, Delphi XE.

Offline

Board footer

Powered by FluxBB