Skip to content

Commit

Permalink
simplifyed some long conditionals and made shure conditionals are vailid
Browse files Browse the repository at this point in the history
  • Loading branch information
DanieSimonlLowe committed Jan 20, 2021
1 parent c796bac commit 7bf5c60
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
19 changes: 10 additions & 9 deletions geonode/api/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,21 @@ class GroupAuthorization(ApiLockdownAuthorization):
def read_list(self, object_list, bundle):
groups = super(GroupAuthorization, self).read_list(object_list, bundle)
user = bundle.request.user
if groups and (not user.is_authenticated or user.is_anonymous):
return groups.exclude(groupprofile__access='private')
elif groups and not user.is_superuser:
return groups.filter(Q(groupprofile__in=user.group_list_all()) | ~Q(groupprofile__access='private'))
return groups
if groups:
if not user.is_authenticated or user.is_anonymous:
return groups.exclude(groupprofile__access='private')
elif not user.is_superuser:
return groups.filter(Q(groupprofile__in=user.group_list_all()) | ~Q(groupprofile__access='private')) return groups


class GroupProfileAuthorization(ApiLockdownAuthorization):

def read_list(self, object_list, bundle):
groups = super(GroupProfileAuthorization, self).read_list(object_list, bundle)
user = bundle.request.user
if groups and (not user.is_authenticated or user.is_anonymous):
return groups.exclude(access='private')
elif groups and not user.is_superuser:
return groups.filter(Q(pk__in=user.group_list_all()) | ~Q(access='private'))
if groups:
if not user.is_authenticated or user.is_anonymous:
return groups.exclude(access='private')
elif not user.is_superuser:
return groups.filter(Q(pk__in=user.group_list_all()) | ~Q(access='private'))
return groups
46 changes: 23 additions & 23 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,28 +930,28 @@ def save(self, notify=False, *args, **kwargs):
_notification_sent = False

# Approval Notifications Here
if not _notification_sent and settings.ADMIN_MODERATE_UPLOADS:
if not self.__is_approved and self.is_approved:
# Set "approved" workflow permissions
self.set_workflow_perms(approved=True)
if not _notification_sent and settings.ADMIN_MODERATE_UPLOADS \
and not self.__is_approved and self.is_approved:
# Set "approved" workflow permissions
self.set_workflow_perms(approved=True)

# Send "approved" notification
notice_type_label = '%s_approved' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True
# Send "approved" notification
notice_type_label = '%s_approved' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True

# Publishing Notifications Here
if not _notification_sent and settings.RESOURCE_PUBLISHING:
if not self.__is_published and self.is_published:
# Set "published" workflow permissions
self.set_workflow_perms(published=True)
if not _notification_sent and settings.RESOURCE_PUBLISHING \
and not self.__is_published and self.is_published:
# Set "published" workflow permissions
self.set_workflow_perms(published=True)

# Send "published" notification
notice_type_label = '%s_published' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True
# Send "published" notification
notice_type_label = '%s_published' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True

# Updated Notifications Here
if not _notification_sent:
Expand Down Expand Up @@ -1130,22 +1130,22 @@ def license_light(self):
a = []
if not self.license:
return ''
if (not (self.license.name is None)) and (len(self.license.name) > 0):
if self.license.name is not None and (len(self.license.name) > 0):
a.append(self.license.name)
if (not (self.license.url is None)) and (len(self.license.url) > 0):
if self.license.url is not None and (len(self.license.url) > 0):
a.append("(" + self.license.url + ")")
return " ".join(a)

@property
def license_verbose(self):
a = []
if (not (self.license.name_long is None)) and (
if self.license.name_long is not None and (
len(self.license.name_long) > 0):
a.append(self.license.name_long + ":")
if (not (self.license.description is None)) and (
if self.license.description is not None and (
len(self.license.description) > 0):
a.append(self.license.description)
if (not (self.license.url is None)) and (len(self.license.url) > 0):
if self.license.url is not None and (len(self.license.url) > 0):
a.append("(" + self.license.url + ")")
return " ".join(a)

Expand Down
5 changes: 2 additions & 3 deletions geonode/geoserver/createlayer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def test_layer_creation(self):
internal_apps_tests = os.environ.get('TEST_RUN_INTERNAL_APPS', None)
if not internal_apps_tests:
internal_apps_tests = settings.internal_apps_tests

if internal_apps_tests and not internal_apps_tests:
else:
layer_name = 'point_layer'
layer_title = 'A layer for points'

Expand Down Expand Up @@ -146,7 +145,7 @@ def test_layer_creation_with_attributes(self):
if not internal_apps_tests:
internal_apps_tests = settings.internal_apps_tests

if internal_apps_tests and not internal_apps_tests:
else:
attributes = """
{
"field_str": "string",
Expand Down

0 comments on commit 7bf5c60

Please sign in to comment.