Skip to content

Commit

Permalink
Advanced Workflow: fix "request editing" action when published -> sen…
Browse files Browse the repository at this point in the history
…d messages to group managers too
  • Loading branch information
afabiani committed Oct 23, 2020
1 parent 1041b12 commit 5c93ef3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion geonode/base/templatetags/base_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ def _has_owner_his_permissions():
resource.BASE_PERMISSIONS.get('write') +
resource.BASE_PERMISSIONS.get('download')) - \
set(perms)
return (_owner_set) == set(['change_resourcebase_permissions', 'publish_resourcebase'])
return _owner_set == set() or \
_owner_set == set(['change_resourcebase_permissions', 'publish_resourcebase'])

if not _has_owner_his_permissions() and resource.owner.pk == user.pk:
return True
Expand Down
21 changes: 19 additions & 2 deletions geonode/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,28 @@ def configuration_session_cache(session):
class OwnerRightsRequestViewUtils:

@staticmethod
def get_message_recipients():
def get_message_recipients(owner):
User = get_user_model()
allowed_users = User.objects.none()
if OwnerRightsRequestViewUtils.is_admin_publish_mode():
allowed_users |= User.objects.filter(is_superuser=True)
allowed_users |= User.objects.filter(is_superuser=True).exclude(pk=owner.pk)
try:
from geonode.groups.models import GroupProfile
groups = owner.groups.all()
obj_group_managers = []
for group in groups:
try:
group_profile = GroupProfile.objects.get(slug=group.name)
managers = group_profile.get_managers()
for manager in managers:
if manager not in obj_group_managers and not manager.is_superuser:
obj_group_managers.append(manager)
except GroupProfile.DoesNotExist:
pass
allowed_users |= User.objects.filter(id__in=[_u.id for _u in obj_group_managers])
except Exception:
pass

return allowed_users

@staticmethod
Expand Down
8 changes: 4 additions & 4 deletions geonode/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,17 @@ def post(self, request, *args, **kwargs):
if form.is_valid():
reason = form.cleaned_data['reason']
notice_type_label = 'request_resource_edit'
recipients = OwnerRightsRequestViewUtils.get_message_recipients()
recipients = OwnerRightsRequestViewUtils.get_message_recipients(self.resource.owner)

Message.objects.new_message(
from_user=request.user,
to_users=recipients,
subject=_('System message: A request to modify resource'),
content=_('The resource owner has requested to modify the resource') + '.'
content=_('The resource owner has requested to modify the resource') + '.\n'
' ' +
_('Resource title') + ': ' + self.resource.title + '.'
_('Resource title') + ': ' + self.resource.title + '.\n'
' ' +
_('Reason for the request') + ': "' + reason + '".' +
_('Reason for the request') + ': "' + reason + '".\n' +
' ' +
_('To allow the change, set the resource to not "Approved" under the metadata settings' +
'and write message to the owner to notify him') + '.'
Expand Down

0 comments on commit 5c93ef3

Please sign in to comment.