def upgrade(self):
        if self.applied():
            print "Migration already applied".rjust(12)
            return True

        org_store = CQDEOrganizationStore.instance()
        user = User()
        organization_ids = org_store.get_organization_keys(user, LOCAL)

        if not organization_ids or len(organization_ids) > 1:
            print "Local organization was not found!"
            return False

        local_organization_id = organization_ids[0]

        queries = [
            """
                INSERT INTO user_organization (user_key, organization_key)
                SELECT user_id, {organization_id}
                FROM user WHERE user_id NOT IN (SELECT user_key FROM user_organization)
                AND authentication_key IN (SELECT id FROM authentication
                                           WHERE method = '{method}')
           """.format(organization_id=local_organization_id, method=LOCAL)
        ]
        return self.manager.db_upgrade(queries)
Ejemplo n.º 2
0
    def _get_user(self, req):
        user = User()
        user.username = req.args.get('username')
        user.mail = req.args.get('email')
        user.givenName = req.args.get('first')
        user.lastName = req.args.get('last')
        user.password = self._generate_password()
        user.mobile = req.args.get('mobile')
        user.createIcon(req.args.get('icon'))

        # Empty makes it default (Local users)
        user.organization_keys = []

        return user
Ejemplo n.º 3
0
    def setUp(self):
        userObj = User()
        userObj.id = 30
        userObj.username = '******'

        self.projectObj = Project(24,
                                  'storageauthtest',
                                  'Storage auth testing',
                                  'Desc',
                                  userObj.id,
                                  None,
                                  author=userObj)
        conf.use_test_db(True)
        self.load_fixtures()
        self.store = CQDEUserGroupStore(self.projectObj.id)
        self.store.remove_group('Owners')
        self.store.remove_group('Public contributors')
        self.store.remove_group('Public viewers')