text
stringlengths
0
234
Stmt.Execute (Result);
if Result /= 1 then
if Result /= 0 then
raise ADO.Objects.UPDATE_ERROR;
else
raise ADO.Objects.LAZY_LOCK;
end if;
end if;
Function Definition: function Get_Owner_Permissions (Manager : in Workspace_Module) return Permission_Index_Array is
Function Body: use Ada.Strings.Unbounded;
begin
return Security.Permissions.Get_Permission_Array (To_String (Manager.Owner_Permissions));
end Get_Owner_Permissions;
-- Get the workspace module.
function Get_Workspace_Module return Workspace_Module_Access is
function Get is new AWA.Modules.Get (Workspace_Module, Workspace_Module_Access, NAME);
begin
return Get;
end Get_Workspace_Module;
-- ------------------------------
-- Get the current workspace associated with the current user.
-- If the user has not workspace, create one.
-- ------------------------------
procedure Get_Workspace (Session : in out ADO.Sessions.Master_Session;
Context : in AWA.Services.Contexts.Service_Context_Access;
Workspace : out AWA.Workspaces.Models.Workspace_Ref) is
User : constant AWA.Users.Models.User_Ref := Context.Get_User;
WS : AWA.Workspaces.Models.Workspace_Ref;
Member : AWA.Workspaces.Models.Workspace_Member_Ref;
Query : ADO.SQL.Query;
Found : Boolean;
Plugin : constant Workspace_Module_Access := Get_Workspace_Module;
begin
if User.Is_Null then
Log.Error ("There is no current user. The workspace cannot be identified");
Workspace := AWA.Workspaces.Models.Null_Workspace;
return;
end if;
-- Find the workspace associated with the current user.
Query.Add_Param (User.Get_Id);
Query.Set_Filter ("o.owner_id = ?");
WS.Find (Session, Query, Found);
if Found then
Workspace := WS;
return;
end if;
-- Check that the user has the permission to create a new workspace.
AWA.Permissions.Check (Permission => ACL_Create_Workspace.Permission,
Entity => User);
-- Create a workspace for this user.
WS.Set_Owner (User);
WS.Set_Create_Date (Ada.Calendar.Clock);
WS.Save (Session);
-- Create the member instance for this user.
Member.Set_Workspace (WS);
Member.Set_Member (User);
Member.Set_Role ("Owner");
Member.Set_Join_Date (ADO.Nullable_Time '(Is_Null => False, Value => WS.Get_Create_Date));
Member.Save (Session);
-- And give full control of the workspace for this user
Add_Permission (Session => Session,
User => User.Get_Id,
Entity => WS,
Workspace => WS.Get_Id,
List => Plugin.Get_Owner_Permissions);
Workspace := WS;
end Get_Workspace;
-- ------------------------------
-- Create a workspace for the user.
-- ------------------------------
procedure Create_Workspace (Module : in Workspace_Module;
Workspace : out AWA.Workspaces.Models.Workspace_Ref) is
Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current;
User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;
DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
WS : AWA.Workspaces.Models.Workspace_Ref;
Member : AWA.Workspaces.Models.Workspace_Member_Ref;
begin
if User.Is_Null then
Log.Error ("There is no current user. The workspace cannot be identified");
Workspace := AWA.Workspaces.Models.Null_Workspace;
return;
end if;
-- Check that the user has the permission to create a new workspace.
AWA.Permissions.Check (Permission => ACL_Create_Workspace.Permission,
Entity => User);
DB.Begin_Transaction;