def resolve(self, **kwd): '''Accept and send''' log_req = self._create_log_req_for_object_view('PublicRequestAccept', **kwd) try: cherrypy.session['Admin'].processPublicRequest(int(kwd['id']), False) log_req.result = 'Success' except ccReg.Admin.REQUEST_BLOCKED: log_req.result = 'Fail' raise CustomView(self._render( 'error', {'message': [ _(u'This object is blocked, request cannot be accepted.' u'You can return back to '), a(attr(href=f_urls[self.classname] + 'detail/?id=%s' % kwd['id']), _('public request.')) ]})) except ccReg.Admin.OBJECT_NOT_FOUND: log_req.result = 'Fail' raise CustomView(self._render( 'error', {'message': [ _(u'No such public request. Maybe it has already been resolved ' u'or this type of public request cannot be resolved. ' u'You can return back to '), a(attr(href=f_urls[self.classname] + 'detail/?id=%s' % kwd['id']), _('public request.')) ]})) finally: log_req.close() raise cherrypy.HTTPRedirect(f_urls[self.classname] + 'filter/?reload=1&load=1')
def _get_detail(self, obj_id): context = {} try: obj_id = int(obj_id) except (TypeError, ValueError): context['main'] = _("Required_integer_as_parameter") raise CustomView(self._render('base', ctx=context)) try: return get_detail(self.classname, obj_id) except (ccReg.Admin.ObjectNotFound,): context['main'] = _("Object_not_found") raise CustomView(self._render('base', ctx=context))
def close(self, **kwd): '''Close and invalidate''' log_req = self._create_log_req_for_object_view( 'PublicRequestInvalidate', **kwd) try: cherrypy.session['Admin'].processPublicRequest( int(kwd['id']), True) log_req.result = 'Success' except ccReg.Admin.REQUEST_BLOCKED: log_req.result = 'Fail' raise CustomView( self._render( 'error', { 'message': [ _(u'Request cannot be accepted.' u'You can return back to '), a( attr(href=f_urls[self.classname] + 'detail/?id=%s' % kwd['id']), _('public request.')) ] })) finally: log_req.close() raise cherrypy.HTTPRedirect(f_urls[self.classname] + 'filter/?reload=1&load=1')
def unblock(self, id): context = DictLookup() try: reg_id = int(id) except (TypeError, ValueError): context.message = _("Required_integer_as_parameter") raise CustomView(self._render('error', ctx=context)) return_message = [ _(u'You can return back to '), a(attr(href=f_urls[self.classname] + 'detail/?id=%s' % reg_id), _('registrar.')) ] admin = cherrypy.session.get('Admin') if not admin.isRegistrarBlocked(reg_id): context.message = [_("This registrar is not blocked.") ] + return_message return self._render('error', ctx=context) else: log_req = utils.create_log_request('RegistrarUpdate', [['blocked', 'False']], [[self.classname, reg_id]]) try: admin.unblockRegistrar(reg_id, log_req.request_id) log_req.result = 'Success' finally: log_req.close() context.main = [_("Registrar successfully unblocked.") ] + return_message return self._render('base', ctx=context)
def _create_check(self, contact_id, test_suite_handle, redirect_to_contact=True): check_nperm_func('add.contactcheck_%s' % test_suite_handle, raise_err=True) try: contact_id = int(contact_id) except (TypeError, ValueError): context = { 'main': _('Requires integer as parameter (got %s).' % contact_id) } raise CustomView(self._render('base', ctx=context)) log_req = create_log_request( 'ContactCheckEnqueue', properties=[['test_suit_handle', test_suite_handle]], references=[('contact', int(contact_id))]) try: cherrypy.session['Verification'].enqueueContactCheck( contact_id, test_suite_handle, log_req.request_id) log_req.result = 'Success' messages.success( _('New %s contact check has been created.' % test_suite_handle)) if redirect_to_contact: raise cherrypy.HTTPRedirect(f_urls['contact'] + 'detail/?id=%s' % contact_id) finally: log_req.close()
def _update_check(self, check, post_data): status_action = post_data['status_action'] if status_action not in get_status_action( check.test_suite_handle, check.status_history[-1].status): raise CustomView( self._render('error', ctx={ 'message': _('Unknown status_action "%s" to resolve.' % status_action) })) status, action = status_action.split(':') props = [['check_handle', check.check_handle], ['status', status], ['action', action]] log_req = create_log_request('ContactCheckResolve', properties=props, references=[('contact', check.contact_id) ]) try: if status == 'confirm_enqueue': cherrypy.session['Verification'].confirmEnqueueingContactCheck( u2c(check.check_handle), log_req.request_id) messages.success(_('Contact check has been enqueue.')) else: cherrypy.session['Verification'].resolveContactCheckStatus( u2c(check.check_handle), u2c(status), log_req.request_id) messages.success( _('Contact check has been resolved as {}.').format( ContactCheckEnums.CHECK_STATUS_NAMES[status])) if action == 'add_manual': self._create_check(check.contact_id, 'manual', redirect_to_contact=False) elif action == 'add_thank_you': self._create_check(check.contact_id, 'thank_you', redirect_to_contact=False) elif action == 'delete_domains': cherrypy.session[ 'Verification'].deleteDomainsAfterFailedManualCheck( u2c(check.check_handle)) messages.success( _('All domains held by the contact {} were deleted.'). format(check.contact_handle)) log_req.result = 'Success' raise cherrypy.HTTPRedirect(f_urls['contactcheck'] + 'detail/%s/' % check.check_handle) finally: log_req.close()
def json_filter(self, contact_id=None, **kwd): test_suit = kwd.get('test_suit') if contact_id: try: contact_id = int(contact_id) except (TypeError, ValueError): context = { 'main': _('Requires integer as parameter (got %s).' % contact_id) } raise CustomView(self._render('base', ctx=context)) cherrypy.response.headers['Content-Type'] = 'application/json' data = list(self._table_data_generator(test_suit, contact_id)) json_data = json.dumps({'aaData': data}) return json_data
def _create_log_req_for_object_view(self, request_type=None, properties=None, references=None, **kwd): ''' To avoid code duplication - this is common for all views (like detail) which are taking id of an object. request_type - default is view detail It checks if ID is integer, returns errorpage if not otherwise creates new log request with references and object_id in properties. (note: object_id in properties will be obsolete when references will be everywhere) ''' context = {} try: object_id = int(kwd.get('id')) except (TypeError, ValueError): context['message'] = _("Required_integer_as_parameter") raise CustomView(self._render('error', ctx=context)) if request_type is None: request_type = f_name_actiondetailname[self.classname] if properties is None: properties = [] if references is None: references = [] properties.append(('object_id', object_id)) object_type = f_name_req_object_type.get(self.classname) if object_type: references.append((object_type, object_id)) log_req = utils.create_log_request(request_type, properties=properties, references=references) return log_req
def check_nperm_func(nperms, nperm_type='all', raise_err=False): ''' Like check_nperm decorator, but it's normal function, used when you cannot use as decorator, for example when you need to get permission from string from other object, which is instantiated in the function. ''' user = cherrypy.session.get('user', None) if user: utils.details_cache = {} # invalidate details cache if not user.check_nperms(nperms, nperm_type): return True else: if raise_err: context = {'main': div()} context['main'].add( p(_("You don't have permissions for this page!"))) if fred.config.debug: context['main'].add( p('nperms=%s, nperm_type=%s' % (nperms, nperm_type))) raise CustomView(BaseSiteMenu(context).render()) else: return False else: redir_addr = '/login/?next=%s' % get_current_url(cherrypy.request) raise cherrypy.HTTPRedirect(redir_addr)
def detail(self, **kwd): """ Detail for Payment. If the payment is not paired with any Registrar, we display a pairing form too. """ log_req = self._create_log_req_for_object_view(**kwd) try: obj_id = int(kwd.get('id')) context = {} # Indicator whether the pairing action has been carried out # successfully. pairing_success = False user = cherrypy.session['user'] user_has_change_perms = not user.check_nperms( "change.bankstatement") # When the user sends the pairing form we arrive at BankStatement # detail again, but this time we receive registrar_handle in kwd # => pair the payment with the registrar. if cherrypy.request.method == 'POST' and user_has_change_perms: registrar_handle = kwd.get('handle', None) payment_type = kwd.get('type', None) try: payment_type = int(payment_type) except (TypeError, ValueError): log_req.result = 'Fail' context['main'] = _( 'Requires integer as parameter (got %s).' % payment_type) raise CustomView(self._render('base', ctx=context)) pairing_success = self._pair_payment_with_registrar( obj_id, payment_type, registrar_handle) # Do not use cache - we want the updated BankStatementItem. detail = utils.get_detail(self.classname, int(obj_id), use_cache=False) context['detail'] = detail context['form'] = BankStatementPairingEditForm( method="POST", initial={ 'handle': kwd.get('handle', None), 'statementId': kwd.get('statementId', None), 'type': kwd.get('type', 2), 'id': obj_id }, onsubmit='return confirmAction();') if cherrypy.request.method == 'POST' and not pairing_success: # Pairing form was submitted, but pairing did not finish # successfully => Show an error. context['form'].non_field_errors().append( 'Could not pair. Perhaps you have entered an invalid handle?' ) if detail.type == editforms.PAYMENT_UNASSIGNED and user_has_change_perms: # Payment not paired => show the payment pairing edit form action = 'pair_payment' # invoiceId is a link to detail, but for id == 0 this detail does # not exist => hide invoiceId value so the link is not "clickable". # Note: No information is lost, because id == 0 semantically means # that there is no id. context['detail'].invoiceId = "" else: action = 'detail' if detail.type != editforms.PAYMENT_REGISTRAR: context['detail'].invoiceId = "" res = self._render(action, context) log_req.result = 'Success' finally: log_req.close() return res