Python flask_security.current_user.has_role() Examples

The following are 30 code examples of flask_security.current_user.has_role(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_security.current_user , or try the search function .
Example #1
Source File: views.py    From pygameweb with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def revert(link):
    """ the link to make the latest version the one selected.
    """
    if wiki_for(link).locked and not current_user.has_role('admin'):
        flash('Wiki page locked.')
        return current_app.login_manager.unauthorized()

    latest = request.args.get('latest', None)
    if latest is not None:
        oldone = wiki_for(link)
        newone = (current_session
                  .query(Wiki)
                  .filter(Wiki.link == link)
                  .filter(Wiki.id == int(latest))
                  .first())

        oldone.latest = 0
        newone.latest = 1
        current_session.add(newone)
        current_session.add(oldone)
        current_session.commit()
        return redirect(url_for('wiki.index', link=link, id=newone.id))
    else:
        abort(404) 
Example #2
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def can_sign(self):
        return current_user.has_role("admin") 
Example #3
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and any(
            map(current_user.has_role, ("developer", "package_admin"))
        ) 
Example #4
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def can_unsign(self):
        return current_user.has_role("admin")

    # View 
Example #5
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def get_query(self):
        if not current_user.has_role("package_admin"):
            return (
                super(BuildView, self)
                .get_query()
                .join(self.model.version)
                .join(Version.package)
                .join(Package.maintainers)
                .filter(User.id == current_user.id)
            )
        return super(BuildView, self).get_query() 
Example #6
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def get_count_query(self):
        if not current_user.has_role("package_admin"):
            return (
                super(BuildView, self)
                .get_count_query()
                .join(self.model.version)
                .join(Version.package)
                .join(Package.maintainers)
                .filter(User.id == current_user.id)
            )
        return super(BuildView, self).get_count_query()

    # Hooks 
Example #7
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def index(self):
        if not current_user.is_authenticated:
            return redirect(url_for("security.login"))
        if not any(map(current_user.has_role, ("developer", "package_admin", "admin"))):
            abort(403)
        return super(IndexView, self).index() 
Example #8
Source File: views.py    From SmartProxyPool with MIT License 5 votes vote down vote up
def is_accessible(self):
        if not current_user.is_active or not current_user.is_authenticated:
            return False

        if current_user.has_role('superuser'):
            return True

        return False 
Example #9
Source File: views.py    From SmartProxyPool with MIT License 5 votes vote down vote up
def is_accessible(self):
        result = None
        if not current_user.is_active or not current_user.is_authenticated:
            result = False

        if current_user.has_role('superuser'):
            result = True

        return result 
Example #10
Source File: views.py    From SmartProxyPool with MIT License 5 votes vote down vote up
def is_accessible(self):
        result = None
        if not current_user.is_active or not current_user.is_authenticated:
            result = False

        if current_user.has_role('superuser'):
            result = True

        return result 
Example #11
Source File: views.py    From pygameweb with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def edit(link):
    """ the wiki page.
    """

    # TODO: we need to add users_id, parents, and keywords
    page = Wiki.for_link(current_session, link)
    if page is None:
        # we create a new empty wiki page!
        page = Wiki(link=link, title=link, latest=1)

    if page.locked and not current_user.has_role('admin'):
        flash('Wiki page locked.')
        return current_app.login_manager.unauthorized()

    form = WikiForm(obj=page)

    if request.method == 'GET':
        # we want people to enter in new data for this field.
        form.changes.data = ''
    elif request.method == 'POST':
        if form.validate_on_submit():
            page.new_version(current_session)
            page.content = form.content.data
            page.changes = form.changes.data
            page.users_id = current_user.id
            current_session.add(page)
            current_session.commit()
            delete_view_wiki_cache(link)

            return redirect(url_for('wiki.index', link=page.link))
    return render_template('wiki/edit.html', form=form, wiki=page) 
Example #12
Source File: views.py    From pygameweb with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def is_accessible(self):
        return current_user.has_role('admin') 
Example #13
Source File: views.py    From pygameweb with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def is_accessible(self):
        return current_user.has_role('admin') 
Example #14
Source File: views.py    From pygameweb with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def is_accessible(self):
        return current_user.has_role('admin') 
Example #15
Source File: views.py    From pygameweb with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def is_accessible(self):
        return current_user.has_role('admin') 
Example #16
Source File: views.py    From pygameweb with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def is_accessible(self):
        return current_user.has_role('admin') 
Example #17
Source File: views.py    From pygameweb with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def is_accessible(self):
        return current_user.has_role('admin') 
Example #18
Source File: search.py    From training with MIT License 5 votes vote down vote up
def owner_manager_permission_filter():
    """Search filter with permission."""
    if current_user.has_role('managers'):
        return [Q(name_or_query='match_all')]
    else:
        return [Q('match', owner=current_user.get_id())] 
Example #19
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def can_create(self):
        return current_user.has_role("package_admin") 
Example #20
Source File: Jobs.py    From LuckyCAT with GNU General Public License v3.0 5 votes vote down vote up
def can_do_stuff_with_job(current_user, owner):
    return current_user.has_role('admin') or current_user.email == owner.email 
Example #21
Source File: Jobs.py    From LuckyCAT with GNU General Public License v3.0 5 votes vote down vote up
def jobs_show():
    filtered_jobs = []
    if current_user.has_role('admin'):
        filtered_jobs = Job.objects
    else:
        for job in Job.objects:
            if job.owner:
                if job.owner.email == current_user.email:
                    filtered_jobs.append(job)

    return flask.render_template("jobs_show.html", jobs=filtered_jobs) 
Example #22
Source File: frontend.py    From spkrepo with MIT License 5 votes vote down vote up
def validate(self):
        if not super(GenerateApiKeyForm, self).validate():  # pragma: no cover
            return False

        if not current_user.has_role("developer"):
            return False

        return True 
Example #23
Source File: api.py    From spkrepo with MIT License 5 votes vote down vote up
def api_auth_required(f):
    @wraps(f)
    def wrapper(*args, **kwargs):
        if request.authorization and request.authorization.type == "basic":
            user = user_datastore.find_user(api_key=request.authorization.username)
            if user and user.has_role("developer"):
                _request_ctx_stack.top.user = user
                identity_changed.send(
                    current_app._get_current_object(), identity=Identity(user.id)
                )
                return f(*args, **kwargs)
        abort(401)

    return wrapper 
Example #24
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and current_user.has_role("admin") 
Example #25
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and current_user.has_role("package_admin") 
Example #26
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and current_user.has_role("package_admin") 
Example #27
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated and current_user.has_role("package_admin") 
Example #28
Source File: admin_model_view.py    From beavy with Mozilla Public License 2.0 5 votes vote down vote up
def is_accessible(self):
        if not current_user.is_active or not current_user.is_authenticated:
            return False

        if current_user.has_role('admin'):
            return True

        return False 
Example #29
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def can_edit(self):
        return current_user.has_role("package_admin") 
Example #30
Source File: admin.py    From spkrepo with MIT License 5 votes vote down vote up
def can_delete(self):
        return current_user.has_role("admin")