def can_vote(session, user, voter, **kwargs): return Permission(IsVoter(session, voter), identity=user)
def post(self, forum_id, slug=None): forum_instance, __ = Forum.get_forum( forum_id=forum_id, user=real(current_user) ) mod_forum_url = url_for( 'forum.manage_forum', forum_id=forum_instance.id, slug=forum_instance.slug ) ids = request.form.getlist('rowid') tmp_topics = Topic.query.filter(Topic.id.in_(ids)).all() if not len(tmp_topics) > 0: flash( _( 'In order to perform this action you have to select at ' 'least one topic.' ), 'danger' ) return redirect(mod_forum_url) # locking/unlocking if 'lock' in request.form: changed = do_topic_action( topics=tmp_topics, user=real(current_user), action='locked', reverse=False ) flash(_('%(count)s topics locked.', count=changed), 'success') return redirect(mod_forum_url) elif 'unlock' in request.form: changed = do_topic_action( topics=tmp_topics, user=real(current_user), action='locked', reverse=True ) flash(_('%(count)s topics unlocked.', count=changed), 'success') return redirect(mod_forum_url) # highlighting/trivializing elif 'highlight' in request.form: changed = do_topic_action( topics=tmp_topics, user=real(current_user), action='important', reverse=False ) flash(_('%(count)s topics highlighted.', count=changed), 'success') return redirect(mod_forum_url) elif 'trivialize' in request.form: changed = do_topic_action( topics=tmp_topics, user=real(current_user), action='important', reverse=True ) flash(_('%(count)s topics trivialized.', count=changed), 'success') return redirect(mod_forum_url) # deleting elif 'delete' in request.form: changed = do_topic_action( topics=tmp_topics, user=real(current_user), action='delete', reverse=False ) flash(_('%(count)s topics deleted.', count=changed), 'success') return redirect(mod_forum_url) # moving elif 'move' in request.form: new_forum_id = request.form.get('forum') if not new_forum_id: flash(_('Please choose a new forum for the topics.'), 'info') return redirect(mod_forum_url) new_forum = Forum.query.filter_by(id=new_forum_id).first_or_404() # check the permission in the current forum and in the new forum if not Permission( And(IsAtleastModeratorInForum(forum_id=new_forum_id), IsAtleastModeratorInForum(forum=forum_instance))): flash( _('You do not have the permissions to move this topic.'), 'danger' ) return redirect(mod_forum_url) if new_forum.move_topics_to(tmp_topics): flash(_('Topics moved.'), 'success') else: flash(_('Failed to move topics.'), 'danger') return redirect(mod_forum_url) # hiding/unhiding elif "hide" in request.form: changed = do_topic_action( topics=tmp_topics, user=real(current_user), action="hide", reverse=False ) flash(_("%(count)s topics hidden.", count=changed), "success") return redirect(mod_forum_url) elif "unhide" in request.form: changed = do_topic_action( topics=tmp_topics, user=real(current_user), action="unhide", reverse=False ) flash(_("%(count)s topics unhidden.", count=changed), "success") return redirect(mod_forum_url) else: flash(_('Unknown action requested'), 'danger') return redirect(mod_forum_url)
def can_manage_voter(session, user, voter, **kwargs): if Permission( IsElectionGroupAdmin(session, voter.pollbook.election.group_id), identity=user): return True return False
def post(self, forum_id, slug=None): # noqa: C901 forum_instance, __ = Forum.get_forum(forum_id=forum_id, user=real(current_user)) mod_forum_url = url_for("forum.manage_forum", forum_id=forum_instance.id, slug=forum_instance.slug) ids = request.form.getlist("rowid") tmp_topics = Topic.query.filter(Topic.id.in_(ids)).all() if not len(tmp_topics) > 0: flash( _("In order to perform this action you have to select at " "least one topic."), "danger") return redirect(mod_forum_url) # locking/unlocking if "lock" in request.form: changed = do_topic_action(topics=tmp_topics, user=real(current_user), action="locked", reverse=False) flash(_("%(count)s topics locked.", count=changed), "success") return redirect(mod_forum_url) elif "unlock" in request.form: changed = do_topic_action(topics=tmp_topics, user=real(current_user), action="locked", reverse=True) flash(_("%(count)s topics unlocked.", count=changed), "success") return redirect(mod_forum_url) # highlighting/trivializing elif "highlight" in request.form: changed = do_topic_action(topics=tmp_topics, user=real(current_user), action="important", reverse=False) flash(_("%(count)s topics highlighted.", count=changed), "success") return redirect(mod_forum_url) elif "trivialize" in request.form: changed = do_topic_action(topics=tmp_topics, user=real(current_user), action="important", reverse=True) flash(_("%(count)s topics trivialized.", count=changed), "success") return redirect(mod_forum_url) # deleting elif "delete" in request.form: changed = do_topic_action(topics=tmp_topics, user=real(current_user), action="delete", reverse=False) flash(_("%(count)s topics deleted.", count=changed), "success") return redirect(mod_forum_url) # moving elif "move" in request.form: new_forum_id = request.form.get("forum") if not new_forum_id: flash(_("Please choose a new forum for the topics."), "info") return redirect(mod_forum_url) new_forum = Forum.query.filter_by(id=new_forum_id).first_or_404() # check the permission in the current forum and in the new forum if not Permission( And(IsAtleastModeratorInForum(forum_id=new_forum_id), IsAtleastModeratorInForum(forum=forum_instance))): flash(_("You do not have the permissions to move this topic."), "danger") return redirect(mod_forum_url) if new_forum.move_topics_to(tmp_topics): flash(_("Topics moved."), "success") else: flash(_("Failed to move topics."), "danger") return redirect(mod_forum_url) # hiding/unhiding elif "hide" in request.form: changed = do_topic_action(topics=tmp_topics, user=real(current_user), action="hide", reverse=False) flash(_("%(count)s topics hidden.", count=changed), "success") return redirect(mod_forum_url) elif "unhide" in request.form: changed = do_topic_action(topics=tmp_topics, user=real(current_user), action="unhide", reverse=False) flash(_("%(count)s topics unhidden.", count=changed), "success") return redirect(mod_forum_url) else: flash(_("Unknown action requested"), "danger") return redirect(mod_forum_url)
def form(self): if Permission(CanPostReply): return QuickreplyForm() return None
def fulfill(self, user): if not hub_current_server: abort(404) return bool(Permission(Has(hub_current_server.base_permission), identity=user))
def fulfill(self, user): if not hub_current_server: raise FlaskBBError("Could not get current server id") return bool(Permission(Has(hub_current_server.management_permission), identity=user))
def _(user): return Permission(requirement, identity=user)
def _(user): return Permission(Has(permission), identity=user)
def manage_forum(forum_id, slug=None): page = request.args.get('page', 1, type=int) forum_instance, forumsread = Forum.get_forum(forum_id=forum_id, user=current_user) # remove the current forum from the select field (move). available_forums = Forum.query.order_by(Forum.position).all() available_forums.remove(forum_instance) if not Permission(IsAtleastModeratorInForum(forum=forum_instance)): flash(_("You do not have the permissions to moderate this forum."), "danger") return redirect(forum_instance.url) if forum_instance.external: return redirect(forum_instance.external) topics = Forum.get_topics(forum_id=forum_instance.id, user=current_user, page=page, per_page=flaskbb_config["TOPICS_PER_PAGE"]) mod_forum_url = url_for("forum.manage_forum", forum_id=forum_instance.id, slug=forum_instance.slug) # the code is kind of the same here but it somehow still looks cleaner than # doin some magic if request.method == "POST": ids = request.form.getlist("rowid") tmp_topics = Topic.query.filter(Topic.id.in_(ids)).all() if not len(tmp_topics) > 0: flash( _("In order to perform this action you have to select at " "least one topic."), "danger") return redirect(mod_forum_url) # locking/unlocking if "lock" in request.form: changed = do_topic_action(topics=tmp_topics, user=current_user, action="locked", reverse=False) flash(_("%(count)s topics locked.", count=changed), "success") return redirect(mod_forum_url) elif "unlock" in request.form: changed = do_topic_action(topics=tmp_topics, user=current_user, action="locked", reverse=True) flash(_("%(count)s topics unlocked.", count=changed), "success") return redirect(mod_forum_url) # highlighting/trivializing elif "highlight" in request.form: changed = do_topic_action(topics=tmp_topics, user=current_user, action="important", reverse=False) flash(_("%(count)s topics highlighted.", count=changed), "success") return redirect(mod_forum_url) elif "trivialize" in request.form: changed = do_topic_action(topics=tmp_topics, user=current_user, action="important", reverse=True) flash(_("%(count)s topics trivialized.", count=changed), "success") return redirect(mod_forum_url) # deleting elif "delete" in request.form: changed = do_topic_action(topics=tmp_topics, user=current_user, action="delete", reverse=False) flash(_("%(count)s topics deleted.", count=changed), "success") return redirect(mod_forum_url) # moving elif "move" in request.form: new_forum_id = request.form.get("forum") if not new_forum_id: flash(_("Please choose a new forum for the topics."), "info") return redirect(mod_forum_url) new_forum = Forum.query.filter_by(id=new_forum_id).first_or_404() # check the permission in the current forum and in the new forum if not Permission( And(IsAtleastModeratorInForum(forum_id=new_forum_id), IsAtleastModeratorInForum(forum=forum_instance))): flash(_("You do not have the permissions to move this topic."), "danger") return redirect(mod_forum_url) new_forum.move_topics_to(tmp_topics) return redirect(mod_forum_url) return render_template( "forum/edit_forum.html", forum=forum_instance, topics=topics, available_forums=available_forums, forumsread=forumsread, )
def do_topic_action(topics, user, action, reverse): # noqa: C901 """Executes a specific action for topics. Returns a list with the modified topic objects. :param topics: A iterable with ``Topic`` objects. :param user: The user object which wants to perform the action. :param action: One of the following actions: locked, important and delete. :param reverse: If the action should be done in a reversed way. For example, to unlock a topic, ``reverse`` should be set to ``True``. """ if not topics: return False from flaskbb.utils.requirements import ( IsAtleastModeratorInForum, CanDeleteTopic, Has, ) if not Permission(IsAtleastModeratorInForum(forum=topics[0].forum)): flash( _("You do not have the permissions to execute this action."), "danger", ) return False modified_topics = 0 if action not in {"delete", "hide", "unhide"}: for topic in topics: if getattr(topic, action) and not reverse: continue setattr(topic, action, not reverse) modified_topics += 1 topic.save() elif action == "delete": if not Permission(CanDeleteTopic): flash( _("You do not have the permissions to delete these topics."), "danger", ) return False for topic in topics: modified_topics += 1 topic.delete() elif action == "hide": if not Permission(Has("makehidden")): flash( _("You do not have the permissions to hide these topics."), "danger", ) return False for topic in topics: if topic.hidden: continue modified_topics += 1 topic.hide(user) elif action == "unhide": if not Permission(Has("makehidden")): flash( _("You do not have the permissions to unhide these topics."), "danger", ) return False for topic in topics: if not topic.hidden: continue modified_topics += 1 topic.unhide() return modified_topics
def has_permission(user, permission): return Permission(Has(permission), identity=user)
def can_view_rank_details(rank, settings, user): return Permission(Or(IsAtleastModerator, UserCanViewRankDetails(rank, settings)), identity=user)
def test_Permission_provide_ident(app, member, ismember): Allows(app=app) p = Permission(ismember, identity=member) assert p.identity is member
def get(self): if Permission(CanAccessServerHub()): return redirect(url_for("hub.hublogs", server=hub_current_server.id)) return redirect(url_for("hub.bans", server=hub_current_server.id))
def __get_actions(self, server_status): actions = [] if Permission(CanAccessServerHub()): actions.append( NavigationLink( endpoint="hub.hublogs", name=_("Logs"), icon="fa fa-clock-o", urlforkwargs={"server": hub_current_server.id}, )) if Permission(CanAccessServerHubAdditional()): if server_status == "online": actions.append( NavigationLink( endpoint="hub.stop", name=_("Stop"), icon="fa fa-power-off", urlforkwargs={"server": hub_current_server.id}, )) actions.append( NavigationLink( endpoint="hub.restart", name=_("Restart"), icon="fa fa-undo", urlforkwargs={"server": hub_current_server.id}, )) else: actions.append( NavigationLink( endpoint="hub.start", name=_("Start"), icon="fa fa-power-off", urlforkwargs={"server": hub_current_server.id}, )) if Permission(CanAccessServerHubAdditional()): actions.append( NavigationLink( endpoint="hub.configs", name=_("Configs"), icon="fa fa-wrench", urlforkwargs={"server": hub_current_server.id}, )) if Permission(CanAccessServerHub()): actions.append( NavigationLink( endpoint="hub.gamelogs", name=_("Game Logs"), icon="fa fa-file", urlforkwargs={"server": hub_current_server.id}, )) actions.append( NavigationLink( endpoint="hub.bans", name=_("Bans"), icon="fa fa-wheelchair-alt", urlforkwargs={"server": hub_current_server.id}, ) ) if Permission(CanAccessServerHubManagement()): actions.append( NavigationLink( endpoint="hub.team", name=_("Team"), icon="fa fa-group", urlforkwargs={"server": hub_current_server.id}, )) return actions