SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit e8662b56 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Merged in jorrandewit (pull request #1)

First pull request :-)
parents ebf46b9c 8719d4d7
No related branches found
No related tags found
No related merge requests found
...@@ -14,3 +14,4 @@ SCIPOST_JOURNALS ...@@ -14,3 +14,4 @@ SCIPOST_JOURNALS
UPLOADS UPLOADS
docs/_build docs/_build
local_files
\ No newline at end of file
...@@ -7,6 +7,10 @@ higher. Python dependencies are listed in `requirements.txt`. ...@@ -7,6 +7,10 @@ higher. Python dependencies are listed in `requirements.txt`.
## Getting started ## Getting started
### Database
Make sure that Postgres is installed and running, and that a database and user are set up for it. A
good guide how to do this can be found [here](https://djangogirls.gitbooks.io/django-girls-tutorial-extensions/content/optional_postgresql_installation/) (NOTE: stop before the 'Update settings' part).
### Python version ### Python version
Make sure you're using Python 3.5. If you need to use multiple versions of Python, use [pyenv](https://github.com/yyuu/pyenv). Make sure you're using Python 3.5. If you need to use multiple versions of Python, use [pyenv](https://github.com/yyuu/pyenv).
...@@ -24,10 +28,6 @@ Now install dependencies: ...@@ -24,10 +28,6 @@ Now install dependencies:
(scipostenv) $ pip install -r requirements.txt (scipostenv) $ pip install -r requirements.txt
``` ```
### Database
Make sure that Postgres is installed and running, and that a database and user are set up for it. A
good guide how to do this can be found [here](https://djangogirls.gitbooks.io/django-girls-tutorial-extensions/content/optional_postgresql_installation/) (NOTE: stop before the 'Update settings' part).
### Host-specific settings ### Host-specific settings
In this project, host-specific settings are defined in the `scipost-host-settings.json` file in the directory *above* the project root. The structure is as follows: In this project, host-specific settings are defined in the `scipost-host-settings.json` file in the directory *above* the project root. The structure is as follows:
...@@ -67,6 +67,12 @@ To make sure everything is setup and configured well, run: ...@@ -67,6 +67,12 @@ To make sure everything is setup and configured well, run:
(scipostenv) $ ./manage.py check (scipostenv) $ ./manage.py check
``` ```
### Create and run migrations
Now that everything is setup, we can setup the datastructures.
```shell
(scipostenv) $ ./manage.py migrate
```
### Create a superuser ### Create a superuser
In order to use the admin site, you'll need a superuser. In order to use the admin site, you'll need a superuser.
```shell ```shell
...@@ -74,16 +80,10 @@ In order to use the admin site, you'll need a superuser. ...@@ -74,16 +80,10 @@ In order to use the admin site, you'll need a superuser.
``` ```
### Create groups and permissions ### Create groups and permissions
Groups and their respective permissions are created using the management command Groups and their respective permissions are created using the management command. Since users depend on the *Contributor* object to work properly, setup the first (admin) user using the `-u` and `-a` arguments.
```shell
(scipostenv) $ ./manage.py add_groups_and_permissions
```
### Create and run migrations
Now that everything is setup, we can setup the datastructures.
```shell ```shell
(scipostenv) $ ./manage.py migrate (scipostenv) $ ./manage.py add_groups_and_permissions -u=<username> -a
``` ```
### Run development server ### Run development server
......
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import Group, Permission from django.contrib.auth.models import Group, Permission, User
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from scipost.models import Contributor from scipost.models import Contributor
class Command(BaseCommand): class Command(BaseCommand):
help = 'Defines groups and permissions' help = 'Defines groups and permissions'
def add_arguments(self, parser):
""" Append arguments optionally for setup of Contributor roles """
parser.add_argument('-u', '--setup-user', metavar='<username>', type=str, required=False, help='Username to make registered contributor')
parser.add_argument('-a', '--make-admin', required=False, action='store_true', help='Grant admin permissions to user (superuser only)')
parser.add_argument('-t', '--make-tester', required=False, action='store_true', help='Grant test permissions to user')
def handle(self, *args, **options): def handle(self, *args, **options):
""" Append all user Groups and setup a Contributor roles to user """
# Create Groups # Create Groups
SciPostAdmin, created = Group.objects.get_or_create(name='SciPost Administrators') SciPostAdmin, created = Group.objects.get_or_create(name='SciPost Administrators')
AdvisoryBoard, created = Group.objects.get_or_create(name='Advisory Board') AdvisoryBoard, created = Group.objects.get_or_create(name='Advisory Board')
...@@ -196,4 +204,27 @@ class Command(BaseCommand): ...@@ -196,4 +204,27 @@ class Command(BaseCommand):
can_draft_registration_invitations, can_draft_registration_invitations,
) )
self.stdout.write(self.style.SUCCESS('Successfully created groups and permissions')) self.stdout.write(self.style.SUCCESS('Successfully created groups and permissions.'))
if options['setup_user']:
# Username is given, check options
try:
user = User.objects.get(username=str(options['setup_user']))
user.groups.add(RegisteredContributors)
self.stdout.write(self.style.SUCCESS('Successfully setup %s as contributor.' % user))
except User.DoesNotExist:
self.stdout.write(self.style.WARNING('User <%s> not found.' % options['update_user']))
return
if user.is_superuser and options['make_admin']:
# Setup admin contributor
user.groups.add(SciPostAdmin)
self.stdout.write(self.style.SUCCESS('Successfully made %s admin.' % user))
elif options['make_admin']:
# Make admin failed, user not a superuser
self.stdout.write(self.style.WARNING('User %s is not a superuser.' % user))
if options['make_tester']:
# Setup test contributor
user.groups.add(Testers)
self.stdout.write(self.style.SUCCESS('Successfully made %s tester.' % user))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment