gws.base.auth.user¶
User objects and conversion of provider records to users.
Source code: gws.base.auth.user
Module Contents¶
- class gws.base.auth.user.AdminUser(provider, roles)¶
Bases:
UserLogged-in user with the
adminrole, allowed everything.- acl_bit(access, obj)¶
Get the access decision for an object itself, without parents.
- Parameters:
access – Access mode.
obj – The object.
- Returns:
gws.c.ALLOWorgws.c.DENYif the object’s permissions decide for one of the user’s roles,Noneotherwise.
- gws.base.auth.user.from_dict(provider: gws.AuthProvider, d: dict) gws.User¶
Restore a user from a dict created by
to_dict.Returns the guest user if the roles contain
guest, anAdminUserif they containadminand anAuthorizedUserotherwise.- Parameters:
provider – The authentication provider of the user.
d – The dict.
- Returns:
The user.
- gws.base.auth.user.from_record(provider: gws.AuthProvider, user_rec: dict) gws.User¶
Create a user from a record returned by a provider.
A provider can return an arbitrary dict of values. The entries
authToken,displayName,email,localUid,loginName,mfaSecretandmfaUid(or their lowercase forms) are copied to the user.rolesandattributesare copied as well, other entries are stored in the user’sdatadict, with common LDAP attribute aliases (for examplecnandcommonName) filled in both ways.The role
allis always added. A record with the roleguestreturns the guest user, one withadmincreates anAdminUser; all other users get the roleuser.loginNameandemailfall back tologinandemailin the data,localUidto the login name,displayNameto the login name.- Parameters:
provider – The authentication provider.
user_rec – The record.
- Returns:
The user.
- Raises:
gws.Error – If the record has neither a local uid nor a login name.
- class gws.base.auth.user.GuestUser(provider, roles)¶
Bases:
UserGuest user, used for requests without a login.
- isGuest = True¶
The user is the guest user.
- class gws.base.auth.user.NobodyUser(provider, roles)¶
Bases:
UserUser that is denied everything.
- acl_bit(access, obj)¶
Get the access decision for an object itself, without parents.
- Parameters:
access – Access mode.
obj – The object.
- Returns:
gws.c.ALLOWorgws.c.DENYif the object’s permissions decide for one of the user’s roles,Noneotherwise.
- class gws.base.auth.user.Props(*args, **kwargs)¶
Bases:
gws.PropsObject properties.
- attributes: dict¶
- class gws.base.auth.user.SystemUser(provider, roles)¶
Bases:
UserSystem user, allowed everything.
- acl_bit(access, obj)¶
Get the access decision for an object itself, without parents.
- Parameters:
access – Access mode.
obj – The object.
- Returns:
gws.c.ALLOWorgws.c.DENYif the object’s permissions decide for one of the user’s roles,Noneotherwise.
- gws.base.auth.user.to_dict(usr) dict¶
Convert a user to a dict.
- Parameters:
usr – The user.
- Returns:
A dict with the user fields,
attributes,data,rolesanduid.
- class gws.base.auth.user.User(provider, roles)¶
Bases:
gws.UserBase user.
Holds the user fields, roles and attributes, and implements the permission checks. Subclasses for special users override the permission decision.
- attributes¶
Public user attributes, sent to the client.
- authProvider¶
The provider that created the user.
- data¶
Private user data from the provider.
- isGuest = False¶
The user is the guest user.
- roles¶
User roles.
- uid = ''¶
Global user uid, made of the provider uid and the local uid.
- acl_bit(access, obj)¶
Get the access decision for an object itself, without parents.
- Parameters:
access – Access mode.
obj – The object.
- Returns:
gws.c.ALLOWorgws.c.DENYif the object’s permissions decide for one of the user’s roles,Noneotherwise.
- acquire(uid=None, classref=None, access=None)¶
Get an object by uid, if the user can access it.
- Parameters:
uid – Object uid.
classref – Class reference. If provided, the object must match it.
access – Access mode,
Access.readif omitted.
- Returns:
The object, or
Noneif it does not exist or the user may not access it.
- can(access, obj, *context)¶
Check if the user can access an object.
If the object’s permissions do not decide, the context objects are checked in turn, then the parents of the last checked object.
- Parameters:
access – Access mode.
obj – The object.
*context – Further objects to check, before the parents.
- Returns:
Trueif access is granted.
- can_create(obj, *context)¶
Check if the user has the
createpermission on an object.- Parameters:
obj – The object.
*context – Further objects to check, before the parents.
- Returns:
Trueif access is granted.
- can_delete(obj, *context)¶
Check if the user has the
deletepermission on an object.- Parameters:
obj – The object.
*context – Further objects to check, before the parents.
- Returns:
Trueif access is granted.
- can_edit(obj, *context)¶
Check if the user has any of the
write,createordeletepermissions on an object.- Parameters:
obj – The object.
*context – Further objects to check, before the parents.
- Returns:
Trueif access is granted.
- can_read(obj, *context)¶
Check if the user has the
readpermission on an object.- Parameters:
obj – The object.
*context – Further objects to check, before the parents.
- Returns:
Trueif access is granted.
- can_use(obj, *context)¶
Check if the user can use an object, which requires the
readpermission.- Parameters:
obj – The object.
*context – Further objects to check, before the parents.
- Returns:
Trueif access is granted.
- can_write(obj, *context)¶
Check if the user has the
writepermission on an object.- Parameters:
obj – The object.
*context – Further objects to check, before the parents.
- Returns:
Trueif access is granted.
- has_role(role)¶
Check if the user has a role.
- Parameters:
role – Role name.
- Returns:
Trueif the user has the role.
- props(user)¶
Generate a
Propsstruct for this object.Do not call this method directly, use
gws.props_ofinstead, which also checks permissions.- Parameters:
user – The user for which the props should be generated.
- Returns:
A
Propsobject or a dict. Nested objects are converted to props as well.
- require(uid=None, classref=None, access=None)¶
Get an object by uid and fail if it is not found or not accessible.
- Parameters:
uid – Object uid.
classref – Class reference. If provided, the object must match it.
access – Access mode,
Access.readif omitted.
- Returns:
The object.
- Raises:
NotFoundError – If the object does not exist.
ForbiddenError – If the user may not access the object.
- require_layer(uid=None)¶
Get a layer the user can read.
- Parameters:
uid – Layer uid.
- Returns:
The layer.
- Raises:
NotFoundError – If the layer does not exist.
ForbiddenError – If the user may not read the layer.
- require_project(uid=None)¶
Get a project the user can read.
- Parameters:
uid – Project uid.
- Returns:
The project.
- Raises:
NotFoundError – If the project does not exist.
ForbiddenError – If the user may not read the project.