def dashboard_DELETE(request): dashboard = request.context.resource actions = AlertChannelActionService.by_resource_id(dashboard.resource_id) for action in actions: DBSession.delete(action) DBSession.delete(dashboard) request.session.flash("Dashboard removed") return True
def remove(request): """ Used to remove reourt groups from database """ report = request.context.report_group form = forms.ReactorForm(request.POST, csrf_context=request) form.validate() DBSession.delete(report) return True
def alert_channels_rule_DELETE(request): """ Removes specific alert channel rule """ user = request.user rule_action = AlertChannelActionService.by_owner_id_and_pkey( user.id, request.GET.get("pkey")) if rule_action: DBSession.delete(rule_action) return True return HTTPNotFound()
def applications_postprocess_DELETE(request): """ Removes application postprocessing rules """ form = forms.ReactorForm(request.POST, csrf_context=request) resource = request.context.resource if form.validate(): for postprocess_conf in resource.postprocess_conf: if postprocess_conf.pkey == int(request.GET["pkey"]): # remove rule DBSession.delete(postprocess_conf) return True
def users_external_identies_DELETE(request): """ Unbinds external identities(google,twitter etc.) from user account """ user = request.user for identity in user.external_identities.all(): log.info('found identity %s' % identity) if (identity.provider_name == request.params.get('provider') and identity.external_user_name == request.params.get('id')): log.info('remove identity %s' % identity) DBSession.delete(identity) return True return False
def groups_DELETE(request): """ Removes a groups permanently from db """ msg = _("You cannot remove administrator group from the system") group = GroupService.by_id(request.matchdict.get("group_id")) if group: if group.id == 1: request.session.flash(msg, "warning") else: DBSession.delete(group) request.session.flash(_("Group removed")) return True request.response.status = 422 return False
def charts_PATCH(request): dashboard = request.context.resource json_body = copy.deepcopy(request.unsafe_json_body) chart_config = json_body["config"] # for now just throw error in case something weird is found applications = UserService.resources_with_perms( request.user, ["view"], resource_types=["application"]) # CRITICAL - this ensures our resultset is limited to only the ones # user has view permissions all_possible_app_ids = set([app.resource_id for app in applications]) schema = ChartConfigSchema().bind(resources=all_possible_app_ids) schema.deserialize(chart_config) # some processing/normalizing for new/missing variables if "timeRange" not in chart_config: chart_config["timeRange"] = "1M" if "startMoment" not in chart_config: chart_config["startMoment"] = "now" if "startMomentUnit" not in chart_config: chart_config["startMomentUnit"] = "days" if "startMomentValue" not in chart_config: chart_config["startMomentValue"] = 0 # ensure we don't have any leftover chart definitions present from # removed layout columns chart_ids = [] for row in dashboard.layout_config: for col in row["columns"]: chart_ids.append(col["chartId"]) for chart in dashboard.charts: if chart.uuid not in chart_ids: actions = AlertChannelActionService.by_other_id(chart.uuid) for action in actions: DBSession.delete(action) dashboard.charts.remove(chart) chart_config["json_config_version"] = chart.json_config_version # make sure we set model field as dirty request.context.chart.name = json_body["name"] request.context.chart.config = None request.context.chart.config = chart_config session = DBSession() mark_changed(session) request.session.flash("Chart saved") return True
def users_DELETE(request): """ Removes a user permanently from db - makes a check to see if after the operation there will be at least one admin left """ msg = _("There needs to be at least one administrator in the system") user = UserService.by_id(request.matchdict.get("user_id")) if user: users = UserService.users_for_perms(["root_administration"]).all() if len(users) < 2 and user.id == users[0].id: request.session.flash(msg, "warning") else: DBSession.delete(user) request.session.flash(_("User removed")) return True request.response.status = 422 return False
def application_remove(request): """ Removes application resources """ resource = request.context.resource # we need polymorphic object here, to properly launch sqlalchemy events resource = ApplicationService.by_id(resource.resource_id) form = forms.CheckPasswordForm(MultiDict(request.safe_json_body or {}), csrf_context=request) form.password.user = request.user if form.validate(): DBSession.delete(resource) request.session.flash(_('Application removed')) else: return HTTPUnprocessableEntity(body=form.errors_json) return True
def remove_integration(self): if self.integration: DBSession.delete(self.integration) self.request.session.flash("Integration removed") return ""