mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-20 23:26:42 +00:00
Adds required permissions and groups
This commit is contained in:
parent
ab21d2051a
commit
d78c271107
1 changed files with 61 additions and 15 deletions
74
init_db.py
74
init_db.py
|
@ -1,24 +1,60 @@
|
||||||
''' starter data '''
|
''' starter data '''
|
||||||
|
from django.contrib.auth.models import Group, Permission
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
from bookwyrm.models import Connector, User
|
from bookwyrm.models import Connector, User
|
||||||
from bookwyrm.settings import DOMAIN
|
from bookwyrm.settings import DOMAIN
|
||||||
|
|
||||||
User.objects.create_user('mouse', 'mouse.reeve@gmail.com', 'password123')
|
|
||||||
User.objects.create_user(
|
|
||||||
'rat', 'rat@rat.com', 'ratword',
|
|
||||||
manually_approves_followers=True
|
|
||||||
)
|
|
||||||
|
|
||||||
User.objects.get(id=1).followers.add(User.objects.get(id=2))
|
groups = ['admin', 'moderator', 'editor']
|
||||||
|
for group in groups:
|
||||||
|
Group.objects.create(name=group)
|
||||||
|
|
||||||
Connector.objects.create(
|
permissions = [{
|
||||||
identifier='openlibrary.org',
|
'codename': 'edit_instance_settings',
|
||||||
name='OpenLibrary',
|
'name': 'change the instance info',
|
||||||
connector_file='openlibrary',
|
'groups': ['admin',]
|
||||||
base_url='https://openlibrary.org',
|
}, {
|
||||||
books_url='https://openlibrary.org',
|
'codename': 'set_user_group',
|
||||||
covers_url='https://covers.openlibrary.org',
|
'name': 'change what group a user is in',
|
||||||
search_url='https://openlibrary.org/search?q=',
|
'groups': ['admin', 'moderator']
|
||||||
|
}, {
|
||||||
|
'codename': 'control_federation',
|
||||||
|
'name': 'control who to federate with',
|
||||||
|
'groups': ['admin', 'moderator']
|
||||||
|
}, {
|
||||||
|
'codename': 'create_invites',
|
||||||
|
'name': 'issue invitations to join',
|
||||||
|
'groups': ['admin', 'moderator']
|
||||||
|
}, {
|
||||||
|
'codename': 'moderate_user',
|
||||||
|
'name': 'deactivate or silence a user',
|
||||||
|
'groups': ['admin', 'moderator']
|
||||||
|
}, {
|
||||||
|
'codename': 'moderate_post',
|
||||||
|
'name': 'delete other users\' posts',
|
||||||
|
'groups': ['admin', 'moderator']
|
||||||
|
}, {
|
||||||
|
'codename': 'edit_book',
|
||||||
|
'name': 'edit book info',
|
||||||
|
'groups': ['admin', 'moderator', 'editor']
|
||||||
|
}]
|
||||||
|
|
||||||
|
content_type = ContentType.objects.get_for_model(User)
|
||||||
|
for permission in permissions:
|
||||||
|
permission_obj = Permission.objects.create(
|
||||||
|
codename=permission['codename'],
|
||||||
|
name=permission['name'],
|
||||||
|
content_type=content_type,
|
||||||
)
|
)
|
||||||
|
# add the permission to the appropriate groups
|
||||||
|
for group_name in permission['groups']:
|
||||||
|
Group.objects.get(name=group_name).permissions.add(permission_obj)
|
||||||
|
|
||||||
|
# while the groups and permissions shouldn't be changed because the code
|
||||||
|
# depends on them, what permissions go with what groups should be editable
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Connector.objects.create(
|
Connector.objects.create(
|
||||||
identifier=DOMAIN,
|
identifier=DOMAIN,
|
||||||
|
@ -31,3 +67,13 @@ Connector.objects.create(
|
||||||
search_url='https://%s/search?q=' % DOMAIN,
|
search_url='https://%s/search?q=' % DOMAIN,
|
||||||
priority=1,
|
priority=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Connector.objects.create(
|
||||||
|
identifier='openlibrary.org',
|
||||||
|
name='OpenLibrary',
|
||||||
|
connector_file='openlibrary',
|
||||||
|
base_url='https://openlibrary.org',
|
||||||
|
books_url='https://openlibrary.org',
|
||||||
|
covers_url='https://covers.openlibrary.org',
|
||||||
|
search_url='https://openlibrary.org/search?q=',
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue