text stringlengths 0 234 |
|---|
-- Create a workspace for this user. |
WS.Set_Owner (User); |
WS.Set_Create_Date (Ada.Calendar.Clock); |
WS.Save (DB); |
-- 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 (DB); |
-- And give full control of the workspace for this user |
Add_Permission (Session => DB, |
User => User.Get_Id, |
Entity => WS, |
Workspace => WS.Get_Id, |
List => Module.Get_Owner_Permissions); |
Workspace := WS; |
DB.Commit; |
end Create_Workspace; |
-- ------------------------------ |
-- Load the invitation from the access key and verify that the key is still valid. |
-- ------------------------------ |
procedure Load_Invitation (Module : in Workspace_Module; |
Key : in String; |
Invitation : in out AWA.Workspaces.Models.Invitation_Ref'Class; |
Inviter : in out AWA.Users.Models.User_Ref) is |
pragma Unreferenced (Module); |
use type Ada.Calendar.Time; |
Ctx : constant ASC.Service_Context_Access := AWA.Services.Contexts.Current; |
DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx); |
Query : ADO.SQL.Query; |
DB_Key : AWA.Users.Models.Access_Key_Ref; |
Found : Boolean; |
begin |
Log.Debug ("Loading invitation from key {0}", Key); |
Query.Set_Filter ("o.access_key = :key"); |
Query.Bind_Param ("key", Key); |
DB_Key.Find (DB, Query, Found); |
if not Found then |
Log.Info ("Invitation key {0} does not exist"); |
raise Not_Found; |
end if; |
if DB_Key.Get_Expire_Date < Ada.Calendar.Clock then |
Log.Info ("Invitation key {0} has expired"); |
raise Not_Found; |
end if; |
Query.Set_Filter ("o.invitee_id = :user"); |
Query.Bind_Param ("user", DB_Key.Get_User.Get_Id); |
Invitation.Find (DB, Query, Found); |
if not Found then |
Log.Warn ("Invitation key {0} has been withdawn"); |
raise Not_Found; |
end if; |
Inviter := AWA.Users.Models.User_Ref (Invitation.Get_Inviter); |
end Load_Invitation; |
-- ------------------------------ |
-- Accept the invitation identified by the access key. |
-- ------------------------------ |
procedure Accept_Invitation (Module : in Workspace_Module; |
Key : in String) is |
use type Ada.Calendar.Time; |
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); |
Query : ADO.SQL.Query; |
DB_Key : AWA.Users.Models.Access_Key_Ref; |
Found : Boolean; |
Invitation : AWA.Workspaces.Models.Invitation_Ref; |
Invitee_Id : ADO.Identifier; |
Workspace_Id : ADO.Identifier; |
Member : AWA.Workspaces.Models.Workspace_Member_Ref; |
User_Member : AWA.Workspaces.Models.Workspace_Member_Ref; |
Now : constant Ada.Calendar.Time := Ada.Calendar.Clock; |
begin |
Log.Debug ("Accept invitation with key {0}", Key); |
Ctx.Start; |
-- Get the access key and verify its validity. |
Query.Set_Filter ("o.access_key = :key"); |
Query.Bind_Param ("key", Key); |
DB_Key.Find (DB, Query, Found); |
if not Found then |
Log.Info ("Invitation key {0} does not exist", Key); |
raise Not_Found; |
end if; |
if DB_Key.Get_Expire_Date < Now then |
Log.Info ("Invitation key {0} has expired", Key); |
raise Not_Found; |
end if; |
-- Find the invitation associated with the access key. |
Invitee_Id := DB_Key.Get_User.Get_Id; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.