2020-03-27 21:14:28 +00:00
|
|
|
''' starter data '''
|
2020-10-01 19:48:55 +00:00
|
|
|
from django.contrib.auth.models import Group, Permission
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
|
2020-09-21 15:10:37 +00:00
|
|
|
from bookwyrm.models import Connector, User
|
|
|
|
from bookwyrm.settings import DOMAIN
|
2020-02-24 16:16:49 +00:00
|
|
|
|
|
|
|
|
2020-10-01 19:48:55 +00:00
|
|
|
groups = ['admin', 'moderator', 'editor']
|
|
|
|
for group in groups:
|
|
|
|
Group.objects.create(name=group)
|
|
|
|
|
|
|
|
permissions = [{
|
|
|
|
'codename': 'edit_instance_settings',
|
|
|
|
'name': 'change the instance info',
|
|
|
|
'groups': ['admin',]
|
|
|
|
}, {
|
|
|
|
'codename': 'set_user_group',
|
|
|
|
'name': 'change what group a user is in',
|
|
|
|
'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
|
|
|
|
|
2020-02-24 16:16:49 +00:00
|
|
|
|
2020-03-27 21:14:28 +00:00
|
|
|
|
2020-03-27 23:36:52 +00:00
|
|
|
Connector.objects.create(
|
|
|
|
identifier=DOMAIN,
|
2020-05-03 19:59:06 +00:00
|
|
|
name='Local',
|
2020-05-03 20:12:42 +00:00
|
|
|
local=True,
|
2020-03-28 19:55:53 +00:00
|
|
|
connector_file='self_connector',
|
2020-05-03 19:59:06 +00:00
|
|
|
base_url='https://%s' % DOMAIN,
|
|
|
|
books_url='https://%s/book' % DOMAIN,
|
2020-03-27 23:36:52 +00:00
|
|
|
covers_url='https://%s/images/covers' % DOMAIN,
|
|
|
|
search_url='https://%s/search?q=' % DOMAIN,
|
2020-05-03 19:59:06 +00:00
|
|
|
priority=1,
|
2020-03-27 23:36:52 +00:00
|
|
|
)
|
2020-10-01 19:48:55 +00:00
|
|
|
|
|
|
|
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=',
|
|
|
|
)
|