예제 #1
0
 def test_delete_bad(self):
     ucount = User.select().count()
     runner = CliRunner()
     result = runner.invoke(
         delete_user, ['*****@*****.**'])
     self.assertIn('Deleted 0 users', result.output)
     self.assertEqual(User.select().count(), ucount)
예제 #2
0
 def test_delete(self):
     self.factory.create_user(email='*****@*****.**')
     ucount = User.select().count()
     runner = CliRunner()
     result = runner.invoke(
         delete_user, ['*****@*****.**'])
     self.assertFalse(result.exception)
     self.assertEqual(result.exit_code, 0)
     self.assertEqual(User.select().where(User.email ==
                                          "*****@*****.**").count(), 0)
     self.assertEqual(User.select().count(), ucount - 1)
예제 #3
0
 def test_password(self):
     self.factory.create_user(email='*****@*****.**')
     runner = CliRunner()
     result = runner.invoke(
         password, ['*****@*****.**', 'xyzzy'])
     self.assertFalse(result.exception)
     self.assertEqual(result.exit_code, 0)
     u = User.select().where(User.email == "*****@*****.**").first()
     self.assertTrue(u.verify_password('xyzzy'))
예제 #4
0
 def test_create_googleauth(self):
     runner = CliRunner()
     result = runner.invoke(
         create_user, ['*****@*****.**', 'Fred Foobar', '--google'])
     self.assertFalse(result.exception)
     self.assertEqual(result.exit_code, 0)
     u = User.select().where(User.email == "*****@*****.**").first()
     self.assertEqual(u.name, "Fred Foobar")
     self.assertIsNone(u.password_hash)
     self.assertEqual(u.groups, [self.factory.default_group.id])
예제 #5
0
 def test_create_basic(self):
     runner = CliRunner()
     result = runner.invoke(
         create_user, ['*****@*****.**', 'Fred Foobar'],
         input="password1\npassword1\n")
     self.assertFalse(result.exception)
     self.assertEqual(result.exit_code, 0)
     u = User.select().where(User.email == "*****@*****.**").first()
     self.assertEqual(u.name, "Fred Foobar")
     self.assertTrue(u.verify_password('password1'))
     self.assertEqual(u.groups, [self.factory.default_group.id])
예제 #6
0
 def test_grant_admin(self):
     self.factory.create_user(name='Fred Foobar',
                                  email='*****@*****.**',
                                  org=self.factory.org,
                                  groups=[self.factory.default_group.id])
     runner = CliRunner()
     result = runner.invoke(
         grant_admin, ['*****@*****.**'])
     self.assertFalse(result.exception)
     self.assertEqual(result.exit_code, 0)
     u = User.select().order_by(User.id.desc()).first()
     self.assertEqual(u.groups, [self.factory.default_group.id,
                                 self.factory.admin_group.id])
if __name__ == '__main__':
    migrator = PostgresqlMigrator(db.database)
    with db.database.transaction():

        if not NotificationDestination.table_exists():
            NotificationDestination.create_table()
            
            # Update alert subscription fields
            migrate(
                migrator.add_column('alert_subscriptions', 'destination_id', AlertSubscription.destination)
            )

            try:
                org = Organization.get_by_slug('default')
                user = User.select().where(User.org==org, peewee.SQL("%s = ANY(groups)", org.admin_group.id)).get()
            except Exception:
                print "!!! Warning: failed finding default organization or admin user, won't migrate Webhook/HipChat alert subscriptions."
                exit()

            if settings.WEBHOOK_ENDPOINT:
                # Have all existing alerts send to webhook if already configured
                schema = get_configuration_schema_for_destination_type('webhook')
                conf = {'url': settings.WEBHOOK_ENDPOINT}
                if settings.WEBHOOK_USERNAME:
                    conf['username'] = settings.WEBHOOK_USERNAME
                    conf['password'] = settings.WEBHOOK_PASSWORD
                options = ConfigurationContainer(conf, schema)

                webhook = NotificationDestination.create(
                    org=org,
예제 #8
0
if __name__ == '__main__':
    migrator = PostgresqlMigrator(db.database)
    with db.database.transaction():

        if not NotificationDestination.table_exists():
            NotificationDestination.create_table()
            
            # Update alert subscription fields
            migrate(
                migrator.add_column('alert_subscriptions', 'destination_id', AlertSubscription.destination)
            )

            try:
                org = Organization.get_by_slug('default')
                user = User.select().where(User.org==org, peewee.SQL("%s = ANY(groups)", org.admin_group.id)).get()
            except Exception:
                print("!!! Warning: failed finding default organization or admin user, won't migrate Webhook/HipChat alert subscriptions.")
                exit()

            if WEBHOOK_ENDPOINT:
                # Have all existing alerts send to webhook if already configured
                schema = get_configuration_schema_for_destination_type('webhook')
                conf = {'url': WEBHOOK_ENDPOINT}
                if WEBHOOK_USERNAME:
                    conf['username'] = WEBHOOK_USERNAME
                    conf['password'] = WEBHOOK_PASSWORD
                options = ConfigurationContainer(conf, schema)

                webhook = NotificationDestination.create(
                    org=org,
예제 #9
0
        migrate(migrator.add_column('groups', 'type', Group.type))

        for name in ['default', 'admin']:
            group = Group.get(Group.name == name)
            group.type = Group.BUILTIN_GROUP
            group.save()

        # Create association table between data sources and groups
        DataSourceGroup.create_table()

        # add default to existing data source:
        default_org = Organization.get_by_id(1)
        default_group = Group.get(Group.name == "default")
        for ds in DataSource.all(default_org):
            DataSourceGroup.create(data_source=ds, group=default_group)

        # change the groups list on a user object to be an ids list
        migrate(migrator.rename_column('users', 'groups', 'old_groups'), )

        migrate(migrator.add_column('users', 'groups', User.groups))

        group_map = dict(map(lambda g: (g.name, g.id), Group.select()))
        user_map = defaultdict(list)
        for user in User.select(User, peewee.SQL('old_groups')):
            group_ids = [group_map[group] for group in user.old_groups]
            user.update_instance(groups=group_ids)

        migrate(migrator.drop_column('users', 'old_groups'))

    db.close_db(None)
예제 #10
0
            group = Group.get(Group.name==name)
            group.type = Group.BUILTIN_GROUP
            group.save()

        # Create association table between data sources and groups
        DataSourceGroup.create_table()

        # add default to existing data source:
        default_org = Organization.get_by_id(1)
        default_group = Group.get(Group.name=="default")
        for ds in DataSource.all(default_org):
            DataSourceGroup.create(data_source=ds, group=default_group)

        # change the groups list on a user object to be an ids list
        migrate(
            migrator.rename_column('users', 'groups', 'old_groups'),
        )

        migrate(migrator.add_column('users', 'groups', User.groups))

        group_map = dict(map(lambda g: (g.name, g.id), Group.select()))
        user_map = defaultdict(list)
        for user in User.select(User, peewee.SQL('old_groups')):
            group_ids = [group_map[group] for group in user.old_groups]
            user.update_instance(groups=group_ids)

        migrate(migrator.drop_column('users', 'old_groups'))

    db.close_db(None)