Esempio n. 1
0
    def post(self):
        req = request.get_json(force=True)
        require_fields(req, ('name', 'email'))

        user = models.User(org=self.current_org,
                           name=req['name'],
                           email=req['email'],
                           is_invitation_pending=False,
                           group_ids=[])

        user.hash_password('Abcd1234')

        try:
            models.db.session.add(user)
            models.db.session.commit()
        except IntegrityError as e:
            if "email" in e.message:
                abort(400, message='Username already taken.')
            abort(500)

        self.record_event({
            'action': 'create',
            'object_id': user.id,
            'object_type': 'user'
        })

        should_send_invitation = 'no_invite' not in request.args
        return invite_user(self.current_user,
                           user,
                           send_email=should_send_invitation)
    def post(self):
        req = request.get_json(True)
        require_fields(req, ('options', 'name', 'type'))

        schema = get_configuration_schema_for_destination_type(req['type'])
        if schema is None:
            abort(400)

        config = ConfigurationContainer(req['options'], schema)
        if not config.is_valid():
            abort(400)

        destination = models.NotificationDestination(org=self.current_org,
                                                     name=req['name'],
                                                     type=req['type'],
                                                     options=config,
                                                     user=self.current_user)

        try:
            models.db.session.add(destination)
            models.db.session.commit()
        except IntegrityError as e:
            if 'name' in e.message:
                abort(400, message=u"Alert Destination with the name {} already exists.".format(req['name']))
            abort(500)

        return destination.to_dict(all=True)
Esempio n. 3
0
def reset_password_with_token(token, invite_flag=False):
    user = verify_token(token)

    if invite_flag and not user.details.get('is_invitation_pending'):
        abort(400, message='Invitation already accepted!')

    req = request.get_json(force=True)
    require_fields(req, ['password'])
    if len(req['password']) < 6:
        abort(400, message='Bad password.')

    if invite_flag:
        user.is_invitation_pending = False
        user.is_email_verified = True

    user.hash_password(req['password'])
    models.db.session.add(user)
    models.db.session.commit()
Esempio n. 4
0
    def post(self):
        req = request.get_json(True)
        require_fields(req, ('options', 'name', 'query_id'))

        query = models.Query.get_by_id_and_org(req['query_id'],
                                               self.current_org)
        require_access(query, self.current_user, view_only)

        alert = models.Alert(name=req['name'],
                             query_rel=query,
                             user=self.current_user,
                             rearm=req.get('rearm'),
                             options=req['options'])

        models.db.session.add(alert)
        models.db.session.flush()
        models.db.session.commit()

        return serialize_alert(alert)
Esempio n. 5
0
    def post(self):
        req = request.get_json(True)
        require_fields(req, ('trigger', 'description', 'snippet'))

        snippet = models.QuerySnippet(trigger=req['trigger'],
                                      description=req['description'],
                                      snippet=req['snippet'],
                                      user=self.current_user,
                                      org=self.current_org)

        models.db.session.add(snippet)
        models.db.session.commit()

        self.record_event({
            'action': 'create',
            'object_id': snippet.id,
            'object_type': 'query_snippet'
        })

        return snippet.to_dict()
Esempio n. 6
0
    def post(self):
        req = request.get_json(True)
        require_fields(req, ('options', 'name', 'type'))

        schema = get_configuration_schema_for_query_runner_type(req['type'])
        if schema is None:
            abort(400)

        config = ConfigurationContainer(filter_none(req['options']), schema)
        # from IPython import embed
        # embed()
        if not config.is_valid():
            abort(400)

        try:
            datasource = models.DataSource.create_with_group(
                org=self.current_org,
                name=req['name'],
                type=req['type'],
                folder_id=req['folder_id'],
                options=config)

            models.db.session.commit()
        except IntegrityError as e:
            if req['name'] in e.message:
                abort(400,
                      message="Data source with the name {} already exists.".
                      format(req['name']))

            abort(400)

        self.record_event({
            'action': 'create',
            'object_id': datasource.id,
            'object_type': 'datasource'
        })

        return datasource.to_dict(all=True)