def grant_perm(self, user, perm): """ Grant user global permissions :param user: :param perm: """ user = self._get_user(user) perm = self._get_perm(perm) # if this permission is already granted skip it _perm = UserToPerm.query()\ .filter(UserToPerm.user == user)\ .filter(UserToPerm.permission == perm)\ .scalar() if _perm: return new = UserToPerm() new.user = user new.permission = perm self.sa.add(new) return new
def grant_perm(self, user, perm): """ Grant user global permissions :param user: :param perm: """ user = User.guess_instance(user) perm = Permission.guess_instance(perm) # if this permission is already granted skip it _perm = UserToPerm.query() \ .filter(UserToPerm.user == user) \ .filter(UserToPerm.permission == perm) \ .scalar() if _perm: return new = UserToPerm() new.user = user new.permission = perm Session().add(new) return new
def _make_perm(perm): new_perm = UserToPerm() new_perm.user = user new_perm.permission = Permission.get_by_key(perm) return new_perm
def _make_new(usr, perm_name): log.debug('Creating new permission:%s', perm_name) new = UserToPerm() new.user = usr new.permission = Permission.get_by_key(perm_name) return new
def _make_new(usr, perm_name): log.debug('Creating new permission:%s' % (perm_name)) new = UserToPerm() new.user = usr new.permission = Permission.get_by_key(perm_name) return new