Python flask_login.current_user.is_superuser() Examples

The following are 6 code examples of flask_login.current_user.is_superuser(). 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_login.current_user , or try the search function .
Example #1
Source File: permissions.py    From gitmark with GNU General Public License v2.0 8 votes vote down vote up
def on_identity_loaded(sender, identity):
    # Set the identity user object
    identity.user = current_user

    # Add the UserNeed to the identity
    if hasattr(current_user, 'username'):
        identity.provides.add(UserNeed(current_user.username))

    # Assuming the User model has a list of roles, update the
    # identity with the roles that the user provides
    if hasattr(current_user, 'role'):
        # for role in current_user.roles:
        identity.provides.add(RoleNeed(current_user.role))
    
    # if current_user.is_superuser:
    if hasattr(current_user, 'is_superuser') and current_user.is_superuser:
        identity.provides.add(su_need)
        # return current_user.role

    identity.allow_su = su_permission.allows(identity)
    identity.allow_admin = admin_permission.allows(identity)
    identity.allow_edit = editor_permission.allows(identity)
    identity.allow_general = general_permission.allows(identity) 
Example #2
Source File: gui_utils.py    From golem with MIT License 6 votes vote down vote up
def permission_required(permission):
    """A wrapper that checks if the current user
    has the required permissions for a page
      * The annotated function must have a `project` argument for project pages.
      * The current user must be available in `flask_login.current_user`
      * The user object must have a `project_weight(project) method`
    """
    def check_permissions(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            if not current_user.is_superuser:
                project = kwargs.get('project', None)
                if project:
                    user_weight = current_user.project_weight(project)
                else:
                    user_weight = 0
                required_weight = Permissions.get_weight(permission)
                if user_weight < required_weight:
                    return render_template('not_permission.html')
            return func(*args, **kwargs)
        return wrapper
    return check_permissions 
Example #3
Source File: admin.py    From maple-file with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def is_accessible(self):
        if current_user.is_authenticated and current_user.is_superuser:
            return True
        return False 
Example #4
Source File: app.py    From maple-bbs with GNU General Public License v3.0 5 votes vote down vote up
def init_app(app):
    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        '''基础权限'''
        identity.user = current_user

        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))

        if hasattr(current_user, 'is_superuser'):
            if current_user.is_superuser:
                identity.provides.add(RoleNeed('super'))

        if hasattr(current_user, 'is_confirmed'):
            if current_user.is_confirmed:
                identity.provides.add(RoleNeed('confirmed'))

        if hasattr(current_user, 'is_authenticated'):
            if current_user.is_authenticated:
                identity.provides.add(RoleNeed('auth'))
            else:
                identity.provides.add(RoleNeed('guest'))

        if hasattr(current_user, 'topics'):
            for topic in current_user.topics:
                identity.provides.add(TopicNeed(topic.id))

        if hasattr(current_user, 'replies'):
            for reply in current_user.replies:
                identity.provides.add(ReplyNeed(reply.id))

        if hasattr(current_user, 'collects'):
            for collect in current_user.collects:
                identity.provides.add(CollectNeed(collect.id)) 
Example #5
Source File: admin.py    From gitmark with GNU General Public License v2.0 5 votes vote down vote up
def is_accessible(self):
        return current_user.is_authenticated
        # return current_user.is_superuser


# Create customized index view class 
Example #6
Source File: web_app.py    From golem with MIT License 5 votes vote down vote up
def index():
    """If user is admin or has '*' in report permissions they will
    have access to every project. Otherwise limit the project
    list to gui_permissions
    """
    projects = test_directory.get_projects()
    if not current_user.is_superuser:
        user_projects = current_user.project_list
        projects = [p for p in user_projects if p in projects]
    return render_template('index.html', projects=projects)


# PROJECT VIEW - redirect to to /project/suites/