本文整理汇总了Python中coprs.logic.users_logic.UsersLogic类的典型用法代码示例。如果您正苦于以下问题:Python UsersLogic类的具体用法?Python UsersLogic怎么用?Python UsersLogic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UsersLogic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: activate_group
def activate_group(fas_group):
form = ActivateFasGroupForm()
if form.validate_on_submit():
if UsersLogic.is_blacklisted_group(fas_group):
flask.flash("This group is blacklisted and cannot be added.")
return flask.redirect(url_for(
"groups_ns.list_user_groups"))
if fas_group not in flask.g.user.user_teams:
raise InsufficientRightsException(
"User '{}' doesn't have access to fas group {}"
.format(flask.g.user.username, fas_group))
alias = form.name.data
group = UsersLogic.get_group_by_fas_name_or_create(
fas_group, alias)
db.session.add(group)
db.session.commit()
flask.flash(
"FAS group {} is activated in the Copr under the alias {} "
.format(fas_group, alias)
)
return flask.redirect(url_for(
"groups_ns.list_projects_by_group", group_name=alias))
else:
return flask.render_template(
"groups/activate_fas_group.html",
fas_group=fas_group,
form=form,
user=flask.g.user,
)
示例2: copr_edit_package_post
def copr_edit_package_post(copr, package_name):
UsersLogic.raise_if_cant_build_in_copr(
flask.g.user, copr, "You don't have permissions to edit this package.")
url_on_success = helpers.copr_url("coprs_ns.copr_packages", copr)
return process_save_package(copr, package_name, view="coprs_ns.copr_edit_package",
view_method=copr_edit_package, url_on_success=url_on_success)
示例3: remove_copr_chroot
def remove_copr_chroot(cls, user, copr_chroot):
"""
:param models.CoprChroot chroot:
"""
UsersLogic.raise_if_cant_update_copr(
user, copr_chroot.copr,
"Only owners and admins may update their projects.")
db.session.delete(copr_chroot)
示例4: remove_comps
def remove_comps(cls, user, copr_chroot):
UsersLogic.raise_if_cant_update_copr(
user, copr_chroot.copr,
"Only owners and admins may update their projects.")
copr_chroot.comps_name = None
copr_chroot.comps_zlib = None
ActionsLogic.send_update_comps(copr_chroot)
db.session.add(copr_chroot)
示例5: test_group_add_alias_with_space
def test_group_add_alias_with_space(self, f_users, f_fas_groups, f_db):
fas_name = f_fas_groups[0]
alias = "alias_1 foo bar"
assert not UsersLogic.group_alias_exists(alias)
r = self.test_client.post(
"/groups/activate/{}".format(fas_name),
data={"name": alias},
follow_redirects=True
)
assert not UsersLogic.group_alias_exists(alias)
示例6: test_group_add_not_in_fas_group
def test_group_add_not_in_fas_group(self, f_users, f_fas_groups, f_db):
fas_name = f_fas_groups[3]
alias = "alias_1"
assert not UsersLogic.group_alias_exists(alias)
r = self.test_client.post(
"/groups/activate/{}".format(fas_name),
data={"name": alias},
follow_redirects=True
)
# assert r.status_code == 403
assert not UsersLogic.group_alias_exists(alias)
示例7: coprs_migration_report
def coprs_migration_report(username=None):
if not username and not flask.g.user:
return generic_error("You are not logged in")
elif not username:
username = flask.g.user.name
user = UsersLogic.get(username).first()
coprs = CoprsLogic.filter_without_group_projects(CoprsLogic.get_multiple_owned_by_username(username)).all()
for group in UsersLogic.get_groups_by_fas_names_list(user.user_teams).all():
coprs.extend(CoprsLogic.get_multiple_by_group_id(group.id).all())
return render_migration_report(coprs, user=user)
示例8: update_chroot
def update_chroot(cls, user, copr_chroot,
buildroot_pkgs, comps=None, comps_name=None):
"""
:type user: models.User
:type copr_chroot: models.CoprChroot
"""
UsersLogic.raise_if_cant_update_copr(
user, copr_chroot.copr,
"Only owners and admins may update their projects.")
cls._update_chroot(buildroot_pkgs, comps, comps_name, copr_chroot)
db.session.add(copr_chroot)
return copr_chroot
示例9: create_chroot
def create_chroot(cls, user, copr, mock_chroot,
buildroot_pkgs=None, comps=None, comps_name=None):
"""
:type user: models.User
:type mock_chroot: models.MockChroot
"""
if buildroot_pkgs is None:
buildroot_pkgs = ""
UsersLogic.raise_if_cant_update_copr(
user, copr,
"Only owners and admins may update their projects.")
chroot = models.CoprChroot(copr=copr, mock_chroot=mock_chroot)
cls._update_chroot(buildroot_pkgs, comps, comps_name, chroot)
return chroot
示例10: get_active_groups_by_user
def get_active_groups_by_user(user_name):
names = flask.g.user.user_groups
if names:
query = UsersLogic.get_groups_by_names_list(names)
return query.filter(User.name == user_name)
else:
return []
示例11: get_group_by_name_safe
def get_group_by_name_safe(group_name):
try:
group = UsersLogic.get_group_by_alias(group_name).one()
except sqlalchemy.orm.exc.NoResultFound:
raise ObjectNotFound(
message="Group {} does not exist.".format(group_name))
return group
示例12: decorated_function
def decorated_function(*args, **kwargs):
token = None
apt_login = None
if "Authorization" in flask.request.headers:
base64string = flask.request.headers["Authorization"]
base64string = base64string.split()[1].strip()
userstring = base64.b64decode(base64string)
(apt_login, token) = userstring.decode("utf-8").split(":")
token_auth = False
if token and apt_login:
user = UsersLogic.get_by_api_login(apt_login).first()
if (user and user.api_token == token and
user.api_token_expiration >= datetime.date.today()):
token_auth = True
flask.g.user = user
if not token_auth:
output = {
"output": "notok",
"error": "Login invalid/expired. "
"Please visit https://copr.fedoraproject.org/api "
"get or renew your API token.",
}
jsonout = flask.jsonify(output)
jsonout.status_code = 500
return jsonout
return f(*args, **kwargs)
示例13: list_user_groups
def list_user_groups():
teams = flask.g.user.user_teams
active_map = {
group.fas_name: group.name for group in
UsersLogic.get_groups_by_fas_names_list(teams).all()
}
teams = UsersLogic.filter_blacklisted_teams(teams)
copr_groups = {
fas_name: active_map.get(fas_name)
for fas_name in teams
}
return render_template(
"groups/user_fas_groups.html",
user=flask.g.user,
teams=teams,
copr_groups=copr_groups)
示例14: test_group_add_twice
def test_group_add_twice(self, f_users, f_fas_groups, f_db):
fas_name = f_fas_groups[0]
alias = "alias_1"
assert not UsersLogic.group_alias_exists(alias)
self.test_client.post(
"/groups/activate/{}".format(fas_name),
data={"name": alias},
follow_redirects=True
)
assert UsersLogic.group_alias_exists(alias)
assert len(models.Group.query.all()) == 1
self.test_client.post(
"/groups/activate/{}".format(fas_name),
data={"name": alias},
follow_redirects=True
)
assert len(models.Group.query.all()) == 1
示例15: add
def add(cls, user, name, selected_chroots, repos=None, description=None,
instructions=None, check_for_duplicates=False, group=None, **kwargs):
copr = models.Copr(name=name,
repos=repos or u"",
owner_id=user.id,
description=description or u"",
instructions=instructions or u"",
created_on=int(time.time()),
**kwargs)
if group is not None:
UsersLogic.raise_if_not_in_group(user, group)
copr.group = group
# form validation checks for duplicates
CoprsLogic.new(user, copr,
check_for_duplicates=check_for_duplicates)
CoprChrootsLogic.new_from_names(copr, selected_chroots)
return copr