Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Update seed loading task and add user task
Browse files Browse the repository at this point in the history
- Update the `load_seed` task to also load the user seed file
- Add a new task to add user permissions
  • Loading branch information
robyoung committed Oct 3, 2013
1 parent c3aa256 commit 0f7c99f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from invoke import task
from os import getenv
from backdrop.core import database
from backdrop.core.user import UserConfig
from backdrop.write.api import app
from backdrop.core.bucket import BucketConfig
from backdrop.core.repository import BucketConfigRepository
from backdrop.core.repository import BucketConfigRepository,\
UserConfigRepository


def environment():
Expand Down Expand Up @@ -40,9 +42,23 @@ def create_bucket(name, datagroup, datatype, rawqueries=False, token=None,
repository.save(config)


@task
def allow_access(email, bucket):
"""Give a user access to a bucket."""
db = get_database()

repository = UserConfigRepository(db)

config = repository.retrieve(email) or UserConfig(email)

if bucket not in config.buckets:
config = UserConfig(email, config.buckets + [bucket])
repository.save(config)


@task
def load_seed():
"""One off task to load buckets and users from a seed file"""
"""One off task to load buckets and users from seed files"""
def load_seed_file(filename):
seed_path = os.path.join(os.path.dirname(__file__), "config", filename)
with open(seed_path) as f:
Expand All @@ -56,3 +72,6 @@ def save_all(filename, repo_cls, model_cls, **save_kwargs):
save_all("bucket-seed.json",
BucketConfigRepository,
BucketConfig, create_bucket=False)
save_all("user-seed.json",
UserConfigRepository,
UserConfig)

0 comments on commit 0f7c99f

Please sign in to comment.