Revision 19eb3ee6

b/snf-astakos-app/astakos/im/functions.py
71 71
from astakos.im.project_notif import (
72 72
    membership_change_notify,
73 73
    application_submit_notify, application_approve_notify,
74
    application_deny_notify,
74 75
    project_termination_notify, project_suspension_notify)
75 76
from astakos.im.endpoints.qh import qh_register_user
76 77

  
......
412 413
        raise IOError(
413 414
            _(astakos_messages.UNKNOWN_PROJECT_ID) % project_id)
414 415

  
416
def get_application_for_update(application_id):
417
    try:
418
        objects = ProjectApplication.objects.select_for_update()
419
        return objects.get(id=application_id)
420
    except ProjectApplication.DoesNotExist:
421
        m = _(astakos_messages.UNKNOWN_PROJECT_APPLICATION_ID) % application_id
422
        raise IOError(m)
423

  
415 424
def get_user_by_id(user_id):
416 425
    try:
417 426
        return AstakosUser.objects.get(id=user_id)
......
653 662
    app.resource_policies = resource_policies
654 663
    return app.id
655 664

  
665
def deny_application(application_id):
666
    application = get_application_for_update(application_id)
667
    if application.state != ProjectApplication.PENDING:
668
        raise PermissionDenied()
669

  
670
    application.deny()
671
    application_deny_notify(application)
672

  
656 673
def approve_application(app):
657 674

  
658 675
    app_id = app if isinstance(app, int) else app.id
b/snf-astakos-app/astakos/im/management/commands/project-deny.py
1
# Copyright 2012 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34
from optparse import make_option
35

  
36
from django.core.management.base import BaseCommand, CommandError
37
from django.core.exceptions import PermissionDenied
38
from django.db import transaction
39

  
40
from astakos.im.models import ProjectApplication
41
from astakos.im.functions import deny_application
42

  
43
class Command(BaseCommand):
44
    args = "<project application id>"
45
    help = "Deny a project application"
46

  
47
    @transaction.commit_on_success
48
    def handle(self, *args, **options):
49
        if len(args) < 1:
50
            raise CommandError("Please provide an application identifier")
51
        try:
52
            app_id = int(args[0])
53
        except ValueError:
54
            raise CommandError('Invalid id')
55
        else:
56
            try:
57
                deny_application(app_id)
58
            except (PermissionDenied, IOError):
59
                raise CommandError('Invalid id')
b/snf-astakos-app/astakos/im/models.py
1325 1325
        except Project.DoesNotExist:
1326 1326
            return None
1327 1327

  
1328
    def deny(self):
1329
        if self.state != self.PENDING:
1330
            m = _("cannot deny: application '%s' in state '%s'") % (
1331
                    self.id, self.state)
1332
            raise AssertionError(m)
1333

  
1334
        self.state = self.DENIED
1335
        self.save()
1336

  
1328 1337
    def approve(self, approval_user=None):
1329 1338
        """
1330 1339
        If approval_user then during owner membership acceptance
b/snf-astakos-app/astakos/im/project_notif.py
37 37
    except NotificationError, e:
38 38
        logger.error(e.message)
39 39

  
40
def application_deny_notify(application):
41
    try:
42
        notification = build_notification(
43
            SENDER,
44
            [application.owner.email],
45
            _(settings.PROJECT_DENIED_SUBJECT) % application.__dict__,
46
            template='im/projects/project_denial_notification.txt',
47
            dictionary={'object':application})
48
        notification.send()
49
    except NotificationError, e:
50
        logger.error(e.message)
51

  
40 52
def application_approve_notify(application):
41 53
    try:
42 54
        notification = build_notification(
b/snf-astakos-app/astakos/im/settings.py
149 149
PROJECT_APPROVED_SUBJECT = getattr(
150 150
    settings, 'ASTAKOS_PROJECT_APPROVED_SUBJECT',
151 151
    '%s alpha2 testing project application approved (%%(name)s)' % SITENAME)
152
PROJECT_DENIED_SUBJECT = getattr(
153
    settings, 'ASTAKOS_PROJECT_DENIED_SUBJECT',
154
    '%s alpha2 testing project application denied (%%(name)s)' % SITENAME)
152 155
PROJECT_TERMINATION_SUBJECT = getattr(
153 156
    settings, 'ASTAKOS_PROJECT_TERMINATION_SUBJECT',
154 157
    '%s alpha2 testing project terminated (%%(name)s)' % SITENAME)
b/snf-astakos-app/astakos/im/templates/im/projects/project_denial_notification.txt
1
--- A translation in English follows ---
2

  
3
Η αίτησή σας για το project {{object.name}} έχει απορριφθεί.
4

  
5
--
6

  
7
Your project application request ({{object.name}}) has been denied.

Also available in: Unified diff