mirror of
https://github.com/wassname/flask-security.git
synced 2026-07-01 16:50:07 +08:00
Convenience method for finding or creating a role
`datastore. find_or_create_role("admin")` will now always return a role
with the name admin; useful for initialisation,
This commit is contained in:
@@ -146,6 +146,13 @@ class UserDatastore(object):
|
||||
role = self.role_model(**kwargs)
|
||||
return self.put(role)
|
||||
|
||||
def find_or_create_role(self, name, **kwargs):
|
||||
"""Returns a role matching the given name or creates it with any
|
||||
additionally provided parameters
|
||||
"""
|
||||
kwrags["name"] = name
|
||||
return self.find_role(name) or self.create_role(**kwargs)
|
||||
|
||||
def create_user(self, **kwargs):
|
||||
"""Creates and returns a new user from the given parameters."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user