11# Copyright The IETF Trust 2007, All Rights Reserved
22from django .conf import settings
33from django .core .urlresolvers import reverse
4- from django .http import HttpResponseRedirect , Http404
4+ from django .http import HttpResponseRedirect , Http404 , HttpResponseForbidden
55from django .shortcuts import get_object_or_404
66from django .shortcuts import render_to_response
77from django .template import RequestContext
1010from ietf .submit .models import IdSubmissionDetail , IdApprovedDetail
1111from ietf .submit .forms import UploadForm , AutoPostForm , MetaDataForm
1212from ietf .submit .utils import (DraftValidation , perform_post ,
13- UPLOADED , WAITING_AUTHENTICATION , CANCELED , INITIAL_VERSION_APPROVAL_REQUESTED )
13+ get_person_for_user , is_secretariat ,
14+ UPLOADED , WAITING_AUTHENTICATION , CANCELED ,
15+ INITIAL_VERSION_APPROVAL_REQUESTED ,
16+ MANUAL_POST_REQUESTED )
1417from ietf .utils .mail import send_mail
1518
1619
@@ -46,12 +49,30 @@ def submit_status(request):
4649
4750
4851
52+ def _can_approve (user , detail ):
53+ person = get_person_for_user (user )
54+ if detail .status_id != INITIAL_VERSION_APPROVAL_REQUESTED or not detail .group_acronym :
55+ return None
56+ if person in [i .person for i in detail .group_acronym .wgchair_set .all ()] or is_secretariat (user ):
57+ return True
58+ return False
59+
60+ def _can_force_post (user , detail ):
61+ person = get_person_for_user (user )
62+ if detail .status_id != MANUAL_POST_REQUESTED :
63+ return None
64+ if is_secretariat (user ):
65+ return True
66+ return False
67+
4968def draft_status (request , submission_id , message = None ):
5069 detail = get_object_or_404 (IdSubmissionDetail , submission_id = submission_id )
5170 validation = DraftValidation (detail )
5271 is_valid = validation .is_valid ()
5372 status = None
5473 allow_edit = True
74+ can_force_post = _can_force_post (request .user , detail )
75+ can_approve = _can_approve (request .user , detail )
5576 if detail .status_id != UPLOADED :
5677 if detail .status_id == CANCELED :
5778 message = ('error' , 'This submission has been canceled, modification is no longer possible' )
@@ -60,30 +81,29 @@ def draft_status(request, submission_id, message=None):
6081
6182 if request .method == 'POST' and allow_edit :
6283 if request .POST .get ('autopost' , False ):
63- try :
64- approved_detail = IdApprovedDetail .objects .get (filename = detail .filename )
65- except ObjectDoesNotExist :
66- approved_detail = None
67- detail .status_id = INITIAL_VERSION_APPROVAL_REQUESTED
68- detail .save ()
69-
70- if detail .revision == '00' and not approved_detail :
71- subject = 'New draft waiting for approval: %s' % detail .filename
72- from_email = settings .IDST_FROM_EMAIL
73- to_email = []
74- if detail .group_acronym :
75- to_email += [i .person .email ()[1 ] for i in detail .group_acronym .wgchair_set .all ()]
76- to_email = list (set (to_email ))
77- if to_email :
78- metadata_form = MetaDataForm (draft = detail , validation = validation )
79- send_mail (request , to_email , from_email , subject , 'submit/manual_post_mail.txt' ,
80- {'form' : metadata_form , 'draft' : detail })
81- else :
82- auto_post_form = AutoPostForm (draft = detail , validation = validation , data = request .POST )
83- if auto_post_form .is_valid ():
84+ auto_post_form = AutoPostForm (draft = detail , validation = validation , data = request .POST )
85+ if auto_post_form .is_valid ():
86+ try :
87+ approved_detail = IdApprovedDetail .objects .get (filename = detail .filename )
88+ except ObjectDoesNotExist :
89+ approved_detail = None
90+ detail .status_id = INITIAL_VERSION_APPROVAL_REQUESTED
91+ detail .save ()
92+
93+ if detail .revision == '00' and not approved_detail :
94+ subject = 'New draft waiting for approval: %s' % detail .filename
95+ from_email = settings .IDST_FROM_EMAIL
96+ to_email = []
97+ if detail .group_acronym :
98+ to_email += [i .person .email ()[1 ] for i in detail .group_acronym .wgchair_set .all ()]
99+ to_email = list (set (to_email ))
100+ if to_email :
101+ metadata_form = MetaDataForm (draft = detail , validation = validation )
102+ send_mail (request , to_email , from_email , subject , 'submit/manual_post_mail.txt' ,
103+ {'form' : metadata_form , 'draft' : detail })
104+ return HttpResponseRedirect (reverse (draft_status , None , kwargs = {'submission_id' : detail .submission_id }))
105+ else :
84106 auto_post_form .save (request )
85- return HttpResponseRedirect (reverse (draft_status , None , kwargs = {'submission_id' : detail .submission_id }))
86-
87107 else :
88108 return HttpResponseRedirect (reverse (draft_edit , None , kwargs = {'submission_id' : detail .submission_id }))
89109 else :
@@ -97,6 +117,8 @@ def draft_status(request, submission_id, message=None):
97117 'status' : status ,
98118 'message' : message ,
99119 'allow_edit' : allow_edit ,
120+ 'can_force_post' : can_force_post ,
121+ 'can_approve' : can_approve ,
100122 },
101123 context_instance = RequestContext (request ))
102124
@@ -117,6 +139,7 @@ def draft_edit(request, submission_id):
117139 form = MetaDataForm (draft = detail , validation = validation , data = request .POST )
118140 if form .is_valid ():
119141 form .save (request )
142+ return HttpResponseRedirect (reverse (draft_status , None , kwargs = {'submission_id' : detail .submission_id }))
120143 else :
121144 form = MetaDataForm (draft = detail , validation = validation )
122145 return render_to_response ('submit/draft_edit.html' ,
@@ -141,10 +164,17 @@ def draft_confirm(request, submission_id, auth_key):
141164 return draft_status (request , submission_id , message )
142165
143166
144- def draft_approve (request , submission_id ):
167+ def draft_approve (request , submission_id , check_function = _can_approve ):
145168 detail = get_object_or_404 (IdSubmissionDetail , submission_id = submission_id )
146- if detail .status_id == INITIAL_VERSION_APPROVAL_REQUESTED :
147- validation = DraftValidation (detail )
148- approved_detail = IdApprovedDetail ()
149- perform_post (detail )
169+ person = get_person_for_user (request .user )
170+ can_perform = check_function (request .user , detail )
171+ if not can_perform :
172+ if can_perform == None :
173+ raise Http404
174+ return HttpResponseForbidden ('You have no permission to perform this action' )
175+ perform_post (detail )
150176 return HttpResponseRedirect (reverse (draft_status , None , kwargs = {'submission_id' : submission_id }))
177+
178+
179+ def draft_force (request , submission_id ):
180+ return draft_approve (request , submission_id , check_function = _can_force_post )
0 commit comments