mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-11 07:51:20 +00:00
Give the first ever user created in a new instance of baserow staff as they must be the admin user and currently there is no other easy way for users to configure or grant staff themselves.
This commit is contained in:
parent
d96e65b25f
commit
3e8c7f5084
4 changed files with 25 additions and 2 deletions
|
@ -104,6 +104,13 @@ class UserHandler:
|
|||
|
||||
user = User(first_name=name, email=email, username=email)
|
||||
user.set_password(password)
|
||||
|
||||
if not User.objects.exists():
|
||||
# This is the first ever user created in this baserow instance and
|
||||
# therefore the administrator user, lets give them staff rights so they
|
||||
# can set baserow wide settings.
|
||||
user.is_staff = True
|
||||
|
||||
user.save()
|
||||
|
||||
if group_invitation_token:
|
||||
|
|
|
@ -31,7 +31,7 @@ def test_create_user(client, data_fixture):
|
|||
assert 'password' not in response_json['user']
|
||||
assert response_json['user']['username'] == 'test@test.nl'
|
||||
assert response_json['user']['first_name'] == 'Test1'
|
||||
assert response_json['user']['is_staff'] is False
|
||||
assert response_json['user']['is_staff'] is True
|
||||
|
||||
response_failed = client.post(reverse('api:user:index'), {
|
||||
'name': 'Test1',
|
||||
|
|
|
@ -23,7 +23,6 @@ from baserow.core.user.exceptions import (
|
|||
)
|
||||
from baserow.core.user.handler import UserHandler
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
|
@ -102,6 +101,22 @@ def test_create_user(data_fixture):
|
|||
user_handler.create_user('Test1', 'test@test.nl', 'password')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_first_ever_created_user_is_staff(data_fixture):
|
||||
user_handler = UserHandler()
|
||||
|
||||
data_fixture.update_settings(allow_new_signups=True)
|
||||
|
||||
first_user = user_handler.create_user('First Ever User', 'test@test.nl',
|
||||
'password')
|
||||
assert first_user.first_name == 'First Ever User'
|
||||
assert first_user.is_staff
|
||||
|
||||
second_user = user_handler.create_user('Second User', 'test2@test.nl', 'password')
|
||||
assert second_user.first_name == 'Second User'
|
||||
assert not second_user.is_staff
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_create_user_with_invitation(data_fixture):
|
||||
plugin_mock = MagicMock()
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* Prevent websocket reconnect when the connection closes without error.
|
||||
* Added gunicorn worker test to the CI pipeline.
|
||||
* Show the number of filters and sorts active in the header of a grid view.
|
||||
* The first user to sign-up after installation now gets given staff status.
|
||||
|
||||
## Released (2021-03-01)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue