def apply_changeset_to_multiple_hosts(request, changeset_pk, template='changesetapplies/apply_changeset_to_multiple_hosts.html'): """Apply changeset POST handler.""" user_has_access = False try: user = request.user.schemanizer_user user_has_access = user.role.name in ( users_models.Role.NAME.developer, users_models.Role.NAME.dba, users_models.Role.NAME.admin) if user_has_access: request_id = helpers.generate_request_id(request) changeset = changesets_models.Changeset.objects.get(pk=int(changeset_pk)) if not privileges_logic.can_user_apply_changeset(user, changeset): raise exceptions.PrivilegeError( 'User is not allowed to apply changeset.') if ( changeset.review_status != changesets_models.Changeset.REVIEW_STATUS_APPROVED): raise exceptions.Error('Cannot apply unapproved changeset.') if request.method == 'POST': log.debug(request.POST) server_ids = [] for k, v in request.POST.iteritems(): if k.startswith('server_'): server_ids.append(int(v)) if not server_ids: raise exceptions.Error('No server was selected.') if not changeset.before_version and len(server_ids) > 1: raise exceptions.Error( 'This changeset is going to be applied for the ' 'first time, select a single server only.') task_ids = [] for server_id in server_ids: result = tasks.apply_changeset.delay( changeset.id, user.id, server_id) task_ids.append(result.task_id) request_id = helpers.generate_request_id(request) request.session[request_id] = task_ids redirect_url = reverse('changesetapplies_changeset_applies') redirect_url = '%s?request_id=%s' % (redirect_url, request_id) messages.info(request, 'Added new changeset apply task(s).') return redirect(redirect_url) else: messages.error(request, MSG_USER_NO_ACCESS) except Exception, e: log.exception('EXCEPTION') messages.error(request, u'%s' % (e,))
def changeset_apply(request, changeset_pk, template='changesetapplies/changeset_apply.html'): """View for applying changeset.""" user_has_access = False try: user = request.user.schemanizer_user user_has_access = user.role.name in ( users_models.Role.NAME.developer, users_models.Role.NAME.dba, users_models.Role.NAME.admin) if user_has_access: request_id = helpers.generate_request_id(request) changeset = changesets_models.Changeset.objects.get(pk=int(changeset_pk)) environments = servers_models.Environment.objects.all() if not privileges_logic.can_user_apply_changeset(user, changeset): raise exceptions.PrivilegeError( 'User is not allowed to apply changeset.') else: messages.error(request, MSG_USER_NO_ACCESS) except Exception, e: log.exception('EXCEPTION') messages.error(request, u'%s' % (e,))
def changeset_review(request, changeset_id, template="changesetreviews/changeset_review.html"): user_has_access = False try: request_id = helpers.generate_request_id(request) changeset = changesets_models.Changeset.objects.get(pk=int(changeset_id)) user = request.user.schemanizer_user user_has_access = privileges_logic.can_user_review_changeset(user, changeset) schema_version = request.GET.get("schema_version", None) if schema_version: schema_version = schemaversions_models.SchemaVersion.objects.get(pk=int(schema_version)) if user_has_access: if request.method == "POST": if u"select_schema_version_form_submit" in request.POST: # # process select schema version form submission # select_schema_version_form = forms.SelectSchemaVersionForm( request.POST, database_schema=changeset.database_schema ) if select_schema_version_form.is_valid(): schema_version_pk = int(select_schema_version_form.cleaned_data["schema_version"]) schema_version = schemaversions_models.SchemaVersion.objects.get(pk=schema_version_pk) changeset.review_version = schema_version changeset.save() tasks.review_changeset.delay( changeset_pk=changeset.pk, schema_version_pk=schema_version.pk, reviewed_by_user_pk=user.pk ) messages.info( request, u"Changeset review has been started, email will " u"be sent to interested parties when review " u"procedure is completed.", ) return redirect("changesetreviews_changeset_reviews") else: # # Invalid POST. # messages.error(request, u"Unknown command.") else: # # # # GET # # # # if schema_version: # # # # User has selected a schema version already, # # proceed with changeset review. # # # thread = changeset_review_logic.start_changeset_review_thread( # changeset, schema_version, user) # review_threads[request_id] = thread # thread_started = True # # else: # # # # No schema version was selected yet, # # ask one from user # # select_schema_version_form = forms.SelectSchemaVersionForm(database_schema=changeset.database_schema) else: messages.error(request, MSG_USER_NO_ACCESS) except Exception, e: log.exception("EXCEPTION") messages.error(request, u"%s" % (e,))