Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
476c5fe2
Commit
476c5fe2
authored
Jan 11, 2013
by
Giorgos Korfiatis
Browse files
Implement application denial
parent
d03254b1
Changes
6
Hide whitespace changes
Inline
Side-by-side
snf-astakos-app/astakos/im/functions.py
View file @
476c5fe2
...
...
@@ -71,6 +71,7 @@ from astakos.im.models import submit_application as models_submit_application
from
astakos.im.project_notif
import
(
membership_change_notify
,
application_submit_notify
,
application_approve_notify
,
application_deny_notify
,
project_termination_notify
,
project_suspension_notify
)
from
astakos.im.endpoints.qh
import
qh_register_user
...
...
@@ -412,6 +413,14 @@ def get_project_for_update(project_id):
raise
IOError
(
_
(
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
):
try
:
return
AstakosUser
.
objects
.
get
(
id
=
user_id
)
...
...
@@ -653,6 +662,14 @@ def update_application(app_id, **kw):
app
.
resource_policies
=
resource_policies
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
):
app_id
=
app
if
isinstance
(
app
,
int
)
else
app
.
id
...
...
snf-astakos-app/astakos/im/management/commands/project-deny.py
0 → 100644
View file @
476c5fe2
# 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'
)
snf-astakos-app/astakos/im/models.py
View file @
476c5fe2
...
...
@@ -1325,6 +1325,15 @@ class ProjectApplication(models.Model):
except
Project
.
DoesNotExist
:
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
):
"""
If approval_user then during owner membership acceptance
...
...
snf-astakos-app/astakos/im/project_notif.py
View file @
476c5fe2
...
...
@@ -37,6 +37,18 @@ def application_submit_notify(application):
except
NotificationError
,
e
:
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
):
try
:
notification
=
build_notification
(
...
...
snf-astakos-app/astakos/im/settings.py
View file @
476c5fe2
...
...
@@ -149,6 +149,9 @@ PROJECT_CREATION_SUBJECT = getattr(
PROJECT_APPROVED_SUBJECT
=
getattr
(
settings
,
'ASTAKOS_PROJECT_APPROVED_SUBJECT'
,
'%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
(
settings
,
'ASTAKOS_PROJECT_TERMINATION_SUBJECT'
,
'%s alpha2 testing project terminated (%%(name)s)'
%
SITENAME
)
...
...
snf-astakos-app/astakos/im/templates/im/projects/project_denial_notification.txt
0 → 100644
View file @
476c5fe2
--- A translation in English follows ---
Η αίτησή σας για το project {{object.name}} έχει απορριφθεί.
--
Your project application request ({{object.name}}) has been denied.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment