Esempio n. 1
0
    def update_metadata(self, name, **kwargs):
        distro_id = utils.make_distro_id(name)

        ses = self.sessionmaker()
        q = ses.query(model.SQLDistro)
        distro = q.filter_by(distro_id=distro_id).all()

        if len(distro) == 0:
            if not self.has_role(None, ADD_DISTRO_ROLE, MANAGER_ROLE):
                raise SecurityError('"%s" cannot add "%s" distro' %
                                    (self.get_active_user(), distro_id))
            distro = model.SQLDistro()
            utils.update_obj(distro, **kwargs)
            distro.distro_id = distro_id
            distro.owner = self.get_active_user()
            ses.add(distro)
            self.logger.debug('Creating new distro "%s"' % distro_id)
        else:
            distro = distro[0]
            if not self.has_role(distro_id, model.OWNER_ROLE, MANAGER_ROLE):
                raise SecurityError('"%s" cannot manage "%s" distro' %
                                    (self.get_active_user(), distro_id))
            self.logger.debug('Updating distro "%s"' % distro_id)
            utils.update_obj(distro, **kwargs)
        distro.name = name
        distro.last_updated = datetime.datetime.now()
        ses.commit()
Esempio n. 2
0
    def update_metadata(self, name, **kwargs):
        distro_id = utils.make_distro_id(name)

        ses = self.sessionmaker()
        q = ses.query(model.SQLDistro)
        distro = q.filter_by(distro_id=distro_id).all()

        if len(distro) == 0:
            if not self.has_role(None, ADD_DISTRO_ROLE, MANAGER_ROLE):
                raise SecurityError('"%s" cannot add "%s" distro' %
                                    (self.get_active_user(), distro_id))
            distro = model.SQLDistro()
            utils.update_obj(distro, **kwargs)
            distro.distro_id = distro_id
            distro.owner = self.get_active_user()
            ses.add(distro)
            self.logger.debug('Creating new distro "%s"' % distro_id)
        else:
            distro = distro[0]
            if not self.has_role(distro_id, model.OWNER_ROLE, MANAGER_ROLE):
                raise SecurityError('"%s" cannot manage "%s" distro' %
                                    (self.get_active_user(), distro_id))
            self.logger.debug('Updating distro "%s"' % distro_id)
            utils.update_obj(distro, **kwargs)
        distro.name = name
        distro.last_updated = datetime.datetime.now()
        ses.commit()
Esempio n. 3
0
    def _update_roles(self, ses, distro_id='',
                      username='', groupname='', roles=[]):

        assert username or groupname

        kwargs = {'distro_id': distro_id,
                  'groupname': groupname,
                  'username': username}
        if username:
            assert not groupname
            kwargs['username'] = username
        elif groupname:
            assert not username
            kwargs['groupname'] = groupname

        q = ses.query(SQLRoleMapping)
        res = q.filter_by(**kwargs)

        remaining = []
        all = []
        for mapping in res:
            all.append(mapping.role)
            if mapping.role not in roles:
                ses.delete(mapping)
                continue
            remaining.append(mapping.role)

        if set(remaining) != roles:
            for role in roles:
                if role in remaining:
                    continue
                r = SQLRoleMapping()
                utils.update_obj(r, **kwargs)
                r.role = role
                ses.add(r)