KartaWeb. Authorize behaviour
(Karta v1.0.0)
What the admin pages may show and do, decided on the server from the
signed-in user's scope (Karta.Accounts.Scope), never from the browser.
Loading what the path names (on_mount), at the page's first render
and again when its LiveView connects; controllers call load!/3:
:organisationassigns the organisation oforganisation_idwhen the scope may see it;:serverand:domainalso assign the server (server_id) or the domain (domain_id) of that organisation;:messagealso assigns the accepted message (message_id) of that server;:instancenames no record and assigns nothing: it lets an instance administrator in and raisesKartaWeb.NotFoundErrorfor everyone else (the instance's own pages, such as the IP pools).
Anything else (an unknown or malformed id, an organisation the user does
not belong to, a server of another organisation, a message of another
server) raises KartaWeb.NotFoundError: a 404, the same whether or not
it exists.
Every event is checked (on_mount :events, for all signed-in pages):
the page declares the action each event needs (permission/1), and
the event goes on only when the scope allows that action in the page's
organisation. The scope is read again from the database for every event
(KartaWeb.UserAuth), so a role taken away, a session ended or a user
disabled counts at the next click. An event a page does not declare is
refused. Records an event names (a member, a key) are looked up within
the page's organisation or server, never by id alone.
Summary
Types
What an event needs: an action of Karta.Accounts.Scope in the page's
organisation, :create_organisation or :admin (instance
administrators), :signed_in (anyone signed in), or nil (refused).
Callbacks
The permission an event of the page needs.
Functions
True when the page's scope (assigns.current_scope) has the permission
in the page's organisation (assigns.organisation, when there is one).
Pages use it to decide what to show; events are checked with it too.
allowed?/2 for templates: can?(@current_scope, @organisation, :manage_servers).
What the path parameters name, loaded for the scope (see the module doc):
%{organisation: ...}, with server:, domain: or server: and
message:. Raises KartaWeb.NotFoundError for anything the scope may
not see.
Types
@type permission() :: Karta.Accounts.Scope.action() | :create_organisation | :admin | :signed_in | nil
What an event needs: an action of Karta.Accounts.Scope in the page's
organisation, :create_organisation or :admin (instance
administrators), :signed_in (anyone signed in), or nil (refused).
Callbacks
@callback permission(event :: String.t()) :: permission()
The permission an event of the page needs.
Functions
@spec allowed?(map(), permission()) :: boolean()
True when the page's scope (assigns.current_scope) has the permission
in the page's organisation (assigns.organisation, when there is one).
Pages use it to decide what to show; events are checked with it too.
@spec can?( Karta.Accounts.Scope.t() | nil, Karta.Accounts.Organisation.t() | nil, permission() ) :: boolean()
allowed?/2 for templates: can?(@current_scope, @organisation, :manage_servers).
@spec load!( Karta.Accounts.Scope.t(), map(), :organisation | :server | :domain | :message ) :: map()
What the path parameters name, loaded for the scope (see the module doc):
%{organisation: ...}, with server:, domain: or server: and
message:. Raises KartaWeb.NotFoundError for anything the scope may
not see.