Skip to content

Commit

Permalink
Merge pull request #2127 from akvo/#2102-iati-export
Browse files Browse the repository at this point in the history
[#2102] IATI export improvements
  • Loading branch information
damienallen committed May 3, 2016
2 parents edfa28c + 7050bf6 commit b618108
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 335 deletions.
9 changes: 5 additions & 4 deletions akvo/rest/views/project_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,8 @@ def project_editor(request, pk=None):
break

# Update the IATI checks for every save in the editor.
try:
project.update_iati_checks()
except:
pass
updated_project = Project.objects.get(pk=pk)
updated_project.update_iati_checks()

return Response(
{
Expand Down Expand Up @@ -772,5 +770,8 @@ def log_project_addition(request, project_pk=None):
change_message=message
)

# Perform IATI checks after a project has been created.
project.update_iati_checks()

content = {'log_entry': 'added successfully'}
return Response(content, status=status.HTTP_201_CREATED)
4 changes: 4 additions & 0 deletions akvo/rsr/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@
rules.add_perm('rsr.change_projectdocument', is_rsr_admin | is_org_admin | is_org_project_editor)
rules.add_perm('rsr.delete_projectdocument', is_rsr_admin | is_org_admin | is_org_project_editor)

rules.add_perm('rsr.add_iatiexport', is_rsr_admin | is_org_admin)
rules.add_perm('rsr.change_iatiexport', is_rsr_admin | is_org_admin)
rules.add_perm('rsr.delete_iatiexport', is_rsr_admin | is_org_admin)

rules.add_perm('rsr.add_organisation', is_rsr_admin | is_org_admin | is_org_project_editor)
rules.add_perm('rsr.change_organisation', is_rsr_admin | is_org_admin | is_org_project_editor)
rules.add_perm('rsr.delete_organisation', is_rsr_admin)
Expand Down
20 changes: 13 additions & 7 deletions akvo/rsr/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group

from .models import Employment, Organisation, PartnerSite, Project, ProjectUpdate, PublishingStatus
from .models import (Employment, IatiExport, Organisation, PartnerSite, Project, ProjectUpdate,
PublishingStatus)


@rules.predicate
Expand All @@ -25,24 +26,29 @@ def is_org_admin(user, obj):
return False
for employment in user.employers.approved():
if employment.group == Group.objects.get(name='Admins'):
org = employment.organisation
if not obj:
return True
elif isinstance(obj, Organisation):
if obj in employment.organisation.content_owned_organisations():
if obj in org.content_owned_organisations():
return True
elif isinstance(obj, get_user_model()) and obj in employment.organisation.all_users():
elif isinstance(obj, get_user_model()) and obj in org.all_users():
return True
elif type(obj) == Employment and \
obj.organisation in employment.organisation.content_owned_organisations():
obj.organisation in org.content_owned_organisations():
return True
elif isinstance(obj, Project) and obj in employment.organisation.all_projects():
elif isinstance(obj, Project) and obj in org.all_projects():
return True
elif isinstance(obj, PublishingStatus) and obj in employment.organisation.all_projects().publishingstatuses():
elif isinstance(obj, PublishingStatus) and \
obj in org.all_projects().publishingstatuses():
return True
elif isinstance(obj, PartnerSite) and obj in employment.organisation.partnersites():
elif isinstance(obj, PartnerSite) and obj in org.partnersites():
return True
elif isinstance(obj, ProjectUpdate) and obj.user == user:
return True
elif isinstance(obj, IatiExport) and \
obj.reporting_organisation in org.content_owned_organisations():
return True
else:
try:
if obj.project and obj.project in employment.organisation.all_projects():
Expand Down
Loading

0 comments on commit b618108

Please sign in to comment.