Skip to content

Commit

Permalink
Modifies loadpolicies to remove necessity of update flag and ensure i…
Browse files Browse the repository at this point in the history
…t runs at provisioning

Reference Issue #978
  • Loading branch information
amplifi authored and oliverroick committed Dec 8, 2016
1 parent 4cba99a commit 3e38764
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 42 deletions.
7 changes: 3 additions & 4 deletions cadasta/accounts/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tutelary import models


def run(verbose=True, force=False, update=False):
def run(verbose=True, force=False):
PERMISSIONS_DIR = settings.BASE_DIR + '/permissions/'

if force:
Expand All @@ -16,9 +16,8 @@ def run(verbose=True, force=False, update=False):
'project-manager', 'data-collector', 'project-user']:
try:
pols[pol] = models.Policy.objects.get(name=pol)
if update:
pols[pol].body = open(PERMISSIONS_DIR + pol + '.json').read()
pols[pol].save()
pols[pol].body = open(PERMISSIONS_DIR + pol + '.json').read()
pols[pol].save()
except:
pols[pol] = models.Policy.objects.create(
name=pol,
Expand Down
8 changes: 1 addition & 7 deletions cadasta/accounts/management/commands/loadpolicies.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,5 @@ def add_arguments(self, parser):
dest='force',
default=False)

parser.add_argument(
'--update',
action='store_true',
dest='update',
default=False)

def handle(self, *args, **options):
load.run(force=options['force'], update=options['update'])
load.run(force=options['force'])
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def test_command_no_args(self):
call_command('loadpolicies')
assert accounts.load.run.call_count == 1
assert accounts.load.run.args == ()
assert accounts.load.run.kwargs == {'force': False, 'update': False}
assert accounts.load.run.kwargs == {'force': False}

def test_command_with_args(self):
call_command('loadpolicies', force=True, update=True)
call_command('loadpolicies', force=True)
assert accounts.load.run.call_count == 1
assert accounts.load.run.args == ()
assert accounts.load.run.kwargs == {'force': True, 'update': True}
assert accounts.load.run.kwargs == {'force': True}
37 changes: 13 additions & 24 deletions cadasta/core/management/commands/loadstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,19 @@ def add_arguments(self, parser):
default=False,
help='Force object deletion and recreation'
)
parser.add_argument(
'--update-policies',
action='store_true',
dest='update_policies',
default=False,
help='Force update of tutelary policies from JSON files'
)

def handle(self, *args, **options):
if options['update_policies']:
print('PERFORMING POLICY UPDATE FROM FILES!!!\n')
loadpolicies.Command().handle(force=False, update=True)
else:
# All of the following are idempotent unless "force" is used.
if options['force']:
print('FORCING STATIC DATA RELOAD!!!\n')
# All of the following are idempotent unless "force" is used.
if options['force']:
print('FORCING STATIC DATA RELOAD!!!\n')

print('LOADING SITE\n')
loadsite.Command().handle(force=options['force'])
print('LOADING COUNTRIES\n')
loadcountries.Command().handle(force=options['force'])
print('LOADING POLICIES\n')
loadpolicies.Command().handle(force=options['force'], update=False)
print('LOADING ATTRIBUTE TYPES\n')
loadattrtypes.Command().handle(force=options['force'])
print('LOADING TENURE RELATIONSHIP TYPES\n')
loadtenurereltypes.Command().handle(force=options['force'])
print('LOADING SITE\n')
loadsite.Command().handle(force=options['force'])
print('LOADING COUNTRIES\n')
loadcountries.Command().handle(force=options['force'])
print('LOADING POLICIES\n')
loadpolicies.Command().handle(force=options['force'])
print('LOADING ATTRIBUTE TYPES\n')
loadattrtypes.Command().handle(force=options['force'])
print('LOADING TENURE RELATIONSHIP TYPES\n')
loadtenurereltypes.Command().handle(force=options['force'])
4 changes: 2 additions & 2 deletions cadasta/core/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def _adjust_kwargs(cls, **kwargs):
kwargs['body'] = open(body_file).read()
return kwargs

def load_policies(update=False):
load.run(force=not update, update=update)
def load_policies(force=True):
load.run(force)


class RoleFactory(factory.django.DjangoModelFactory):
Expand Down
2 changes: 0 additions & 2 deletions cadasta/core/tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def test_fixture_setup(self):
data.delete_test_projects()
data.add_test_organizations()
PolicyFactory.load_policies()
# Just for test coverage...
PolicyFactory.load_policies(update=True)
create_attribute_types()
load_tenure_relationship_types()
data.add_test_users_and_roles()
Expand Down
8 changes: 8 additions & 0 deletions provision/roles/webserver/production/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
notify:
- Restart nginx

- name: Load static data
become: yes
become_user: "{{ app_user }}"
django_manage: command=loadstatic
app_path="{{ application_path }}cadasta"
virtualenv="{{ virtualenv_path }}"
settings="{{ django_settings }}"

- name: Link static content
become: yes
become_user: "{{ app_user }}"
Expand Down

0 comments on commit 3e38764

Please sign in to comment.