mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
server/users: let administrators add new users
* Added functionality for administrators to directly add users to the application * Added permission users:create:any to handle level that users are allowed to create other users * Moved old permission users:create to users:create:self
This commit is contained in:
@ -26,7 +26,11 @@ def get_users(
|
||||
@rest.routes.post('/users/?')
|
||||
def create_user(
|
||||
ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
|
||||
auth.verify_privilege(ctx.user, 'users:create')
|
||||
if ctx.user.user_id is None:
|
||||
auth.verify_privilege(ctx.user, 'users:create:self')
|
||||
else:
|
||||
auth.verify_privilege(ctx.user, 'users:create:any')
|
||||
|
||||
name = ctx.get_param_as_string('name')
|
||||
password = ctx.get_param_as_string('password')
|
||||
email = ctx.get_param_as_string('email', default='')
|
||||
@ -40,6 +44,7 @@ def create_user(
|
||||
ctx.get_file('avatar', default=b''))
|
||||
ctx.session.add(user)
|
||||
ctx.session.commit()
|
||||
|
||||
return _serialize(ctx, user, force_show_email=True)
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@ from szurubooru.func import users
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def inject_config(config_injector):
|
||||
config_injector({'privileges': {'users:create': 'regular'}})
|
||||
config_injector({'privileges': {'users:create:self': 'regular'}})
|
||||
|
||||
|
||||
def test_creating_user(user_factory, context_factory, fake_datetime):
|
||||
|
Reference in New Issue
Block a user