Commit 476c5fe2 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Implement application denial

parent d03254b1
...@@ -71,6 +71,7 @@ from astakos.im.models import submit_application as models_submit_application ...@@ -71,6 +71,7 @@ from astakos.im.models import submit_application as models_submit_application
from astakos.im.project_notif import ( from astakos.im.project_notif import (
membership_change_notify, membership_change_notify,
application_submit_notify, application_approve_notify, application_submit_notify, application_approve_notify,
application_deny_notify,
project_termination_notify, project_suspension_notify) project_termination_notify, project_suspension_notify)
from astakos.im.endpoints.qh import qh_register_user from astakos.im.endpoints.qh import qh_register_user
...@@ -412,6 +413,14 @@ def get_project_for_update(project_id): ...@@ -412,6 +413,14 @@ def get_project_for_update(project_id):
raise IOError( raise IOError(
_(astakos_messages.UNKNOWN_PROJECT_ID) % project_id) _(astakos_messages.UNKNOWN_PROJECT_ID) % project_id)
def get_application_for_update(application_id):
try:
objects = ProjectApplication.objects.select_for_update()
return objects.get(id=application_id)
except ProjectApplication.DoesNotExist:
m = _(astakos_messages.UNKNOWN_PROJECT_APPLICATION_ID) % application_id
raise IOError(m)
def get_user_by_id(user_id): def get_user_by_id(user_id):
try: try:
return AstakosUser.objects.get(id=user_id) return AstakosUser.objects.get(id=user_id)
...@@ -653,6 +662,14 @@ def update_application(app_id, **kw): ...@@ -653,6 +662,14 @@ def update_application(app_id, **kw):
app.resource_policies = resource_policies app.resource_policies = resource_policies
return app.id return app.id
def deny_application(application_id):
application = get_application_for_update(application_id)
if application.state != ProjectApplication.PENDING:
raise PermissionDenied()
application.deny()
application_deny_notify(application)
def approve_application(app): def approve_application(app):
app_id = app if isinstance(app, int) else app.id app_id = app if isinstance(app, int) else app.id
......
# Copyright 2012 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.core.exceptions import PermissionDenied
from django.db import transaction
from astakos.im.models import ProjectApplication
from astakos.im.functions import deny_application
class Command(BaseCommand):
args = "<project application id>"
help = "Deny a project application"
@transaction.commit_on_success
def handle(self, *args, **options):
if len(args) < 1:
raise CommandError("Please provide an application identifier")
try:
app_id = int(args[0])
except ValueError:
raise CommandError('Invalid id')
else:
try:
deny_application(app_id)
except (PermissionDenied, IOError):
raise CommandError('Invalid id')
...@@ -1325,6 +1325,15 @@ class ProjectApplication(models.Model): ...@@ -1325,6 +1325,15 @@ class ProjectApplication(models.Model):
except Project.DoesNotExist: except Project.DoesNotExist:
return None return None
def deny(self):
if self.state != self.PENDING:
m = _("cannot deny: application '%s' in state '%s'") % (
self.id, self.state)
raise AssertionError(m)
self.state = self.DENIED
self.save()
def approve(self, approval_user=None): def approve(self, approval_user=None):
""" """
If approval_user then during owner membership acceptance If approval_user then during owner membership acceptance
......
...@@ -37,6 +37,18 @@ def application_submit_notify(application): ...@@ -37,6 +37,18 @@ def application_submit_notify(application):
except NotificationError, e: except NotificationError, e:
logger.error(e.message) logger.error(e.message)
def application_deny_notify(application):
try:
notification = build_notification(
SENDER,
[application.owner.email],
_(settings.PROJECT_DENIED_SUBJECT) % application.__dict__,
template='im/projects/project_denial_notification.txt',
dictionary={'object':application})
notification.send()
except NotificationError, e:
logger.error(e.message)
def application_approve_notify(application): def application_approve_notify(application):
try: try:
notification = build_notification( notification = build_notification(
......
...@@ -149,6 +149,9 @@ PROJECT_CREATION_SUBJECT = getattr( ...@@ -149,6 +149,9 @@ PROJECT_CREATION_SUBJECT = getattr(
PROJECT_APPROVED_SUBJECT = getattr( PROJECT_APPROVED_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_APPROVED_SUBJECT', settings, 'ASTAKOS_PROJECT_APPROVED_SUBJECT',
'%s alpha2 testing project application approved (%%(name)s)' % SITENAME) '%s alpha2 testing project application approved (%%(name)s)' % SITENAME)
PROJECT_DENIED_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_DENIED_SUBJECT',
'%s alpha2 testing project application denied (%%(name)s)' % SITENAME)
PROJECT_TERMINATION_SUBJECT = getattr( PROJECT_TERMINATION_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_TERMINATION_SUBJECT', settings, 'ASTAKOS_PROJECT_TERMINATION_SUBJECT',
'%s alpha2 testing project terminated (%%(name)s)' % SITENAME) '%s alpha2 testing project terminated (%%(name)s)' % SITENAME)
......
--- A translation in English follows ---
Η αίτησή σας για το project {{object.name}} έχει απορριφθεί.
--
Your project application request ({{object.name}}) has been denied.
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