Commit 7829827f authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Checks for operations on applications

parent 6b154ae5
......@@ -693,8 +693,10 @@ def cancel_application(application_id, request_user=None):
application = get_application_for_update(application_id)
checkAllowed(application, request_user)
if application.state != ProjectApplication.PENDING:
raise PermissionDenied()
if not application.can_cancel():
m = _(astakos_messages.APPLICATION_CANNOT_CANCEL % (
application.id, application.state_display()))
raise PermissionDenied(m)
application.cancel()
......@@ -702,15 +704,20 @@ def dismiss_application(application_id, request_user=None):
application = get_application_for_update(application_id)
checkAllowed(application, request_user)
if application.state != ProjectApplication.DENIED:
raise PermissionDenied()
if not application.can_dismiss():
m = _(astakos_messages.APPLICATION_CANNOT_DISMISS % (
application.id, application.state_display()))
raise PermissionDenied(m)
application.dismiss()
def deny_application(application_id):
application = get_application_for_update(application_id)
if application.state != ProjectApplication.PENDING:
raise PermissionDenied()
if not application.can_deny():
m = _(astakos_messages.APPLICATION_CANNOT_DENY % (
application.id, application.state_display()))
raise PermissionDenied(m)
application.deny()
application_deny_notify(application)
......@@ -725,6 +732,11 @@ def approve_application(app):
except ProjectApplication.DoesNotExist:
raise PermissionDenied()
if not application.can_approve():
m = _(astakos_messages.APPLICATION_CANNOT_APPROVE % (
application.id, application.state_display()))
raise PermissionDenied(m)
application.approve()
sync_projects()
......
......@@ -188,6 +188,11 @@ USER_JOINED_PROJECT = '%(realname)s has joined the Project
USER_LEFT_PROJECT = '%(realname)s has left the Project.'
USER_JOIN_REQUEST_SUBMITED = 'Join request submitted.'
APPLICATION_CANNOT_APPROVE = "Cannot approve application %s in state '%s'"
APPLICATION_CANNOT_DENY = "Cannot deny application %s in state '%s'"
APPLICATION_CANNOT_DISMISS = "Cannot dismiss application %s in state '%s'"
APPLICATION_CANNOT_CANCEL = "Cannot cancel application %s in state '%s'"
# Auth providers messages
AUTH_PROVIDER_NOT_ACTIVE = "'%(provider)s' is disabled."
AUTH_PROVIDER_NOT_ACTIVE_FOR_LOGIN = "Login using '%(provider)s' is disabled."
......
......@@ -1432,8 +1432,11 @@ class ProjectApplication(models.Model):
except Project.DoesNotExist:
return None
def can_cancel(self):
return self.state == self.PENDING
def cancel(self):
if self.state != self.PENDING:
if not self.can_cancel():
m = _("cannot cancel: application '%s' in state '%s'") % (
self.id, self.state)
raise AssertionError(m)
......@@ -1441,8 +1444,11 @@ class ProjectApplication(models.Model):
self.state = self.CANCELLED
self.save()
def can_dismiss(self):
return self.state == self.DENIED
def dismiss(self):
if self.state != self.DENIED:
if not self.can_dismiss():
m = _("cannot dismiss: application '%s' in state '%s'") % (
self.id, self.state)
raise AssertionError(m)
......@@ -1450,8 +1456,11 @@ class ProjectApplication(models.Model):
self.state = self.DISMISSED
self.save()
def can_deny(self):
return self.state == self.PENDING
def deny(self):
if self.state != self.PENDING:
if not self.can_deny():
m = _("cannot deny: application '%s' in state '%s'") % (
self.id, self.state)
raise AssertionError(m)
......@@ -1460,6 +1469,9 @@ class ProjectApplication(models.Model):
self.response_date = datetime.now()
self.save()
def can_approve(self):
return self.state == self.PENDING
def approve(self, approval_user=None):
"""
If approval_user then during owner membership acceptance
......@@ -1473,10 +1485,10 @@ class ProjectApplication(models.Model):
raise AssertionError("NOPE")
new_project_name = self.name
if self.state != self.PENDING:
if not self.can_approve():
m = _("cannot approve: project '%s' in state '%s'") % (
new_project_name, self.state)
raise PermissionDenied(m) # invalid argument
raise AssertionError(m) # invalid argument
now = datetime.now()
project = self._get_project_for_update()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment