當前位置: 首頁>>代碼示例>>Python>>正文


Python flask_principal.UserNeed方法代碼示例

本文整理匯總了Python中flask_principal.UserNeed方法的典型用法代碼示例。如果您正苦於以下問題:Python flask_principal.UserNeed方法的具體用法?Python flask_principal.UserNeed怎麽用?Python flask_principal.UserNeed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask_principal的用法示例。


在下文中一共展示了flask_principal.UserNeed方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: on_identity_loaded

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
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) 
開發者ID:GitMarkTeam,項目名稱:gitmark,代碼行數:25,代碼來源:permissions.py

示例2: patron_permission

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def patron_permission(patron_pid):
    """Return a permission for the given patron."""
    return Permission(UserNeed(int(patron_pid)), backoffice_access_action) 
開發者ID:inveniosoftware,項目名稱:invenio-app-ils,代碼行數:5,代碼來源:permissions.py

示例3: __init__

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def __init__(self, record):
        """Constructor."""
        super(PatronOwnerPermission, self).__init__(
            UserNeed(int(record["patron_pid"])), backoffice_access_action
        ) 
開發者ID:inveniosoftware,項目名稱:invenio-app-ils,代碼行數:7,代碼來源:permissions.py

示例4: record_needs

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def record_needs(self):
        """Create needs of the record."""
        needs = []
        for access_entity in self.record_explicit_restrictions():
            try:
                if isinstance(access_entity, string_types):
                    needs.append(UserNeed(int(access_entity)))
                elif isinstance(access_entity, int):
                    needs.append(UserNeed(access_entity))
            except ValueError:
                needs.append(RoleNeed(access_entity.lower()))
        return needs 
開發者ID:inveniosoftware,項目名稱:invenio-app-ils,代碼行數:14,代碼來源:permissions.py

示例5: _on_identity_loaded

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def _on_identity_loaded(sender, identity):
    if hasattr(current_user, "fs_uniquifier"):
        identity.provides.add(UserNeed(current_user.fs_uniquifier))

    for role in getattr(current_user, "roles", []):
        identity.provides.add(RoleNeed(role.name))
        for fsperm in role.get_permissions():
            identity.provides.add(FsPermNeed(fsperm))

    identity.user = current_user 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:12,代碼來源:core.py

示例6: on_identity_loaded

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def on_identity_loaded(sender, identity):
    """Method for Flask Principal identity load listener
    """
    # set the identity user object
    identity.user = current_user

    if current_user.is_authenticated:
        # add UserNeed to identity
        identity.provides.add(UserNeed(current_user.id)) 
開發者ID:muicss,項目名稱:flaskapp,代碼行數:11,代碼來源:__init__.py

示例7: on_identity_loaded

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def on_identity_loaded(sender, identity):
    """
    Sets the identity of a given option, assigns additional permissions based on
    the role that the user is a part of.

    :param sender:
    :param identity:
    """
    # load the user
    user = user_service.get(identity.id)

    # add the UserNeed to the identity
    identity.provides.add(UserNeed(identity.id))

    # identity with the roles that the user provides
    if hasattr(user, "roles"):
        for role in user.roles:
            identity.provides.add(RoleNeed(role.name))
            identity.provides.add(RoleMemberNeed(role.id))

    # apply ownership for authorities
    if hasattr(user, "authorities"):
        for authority in user.authorities:
            identity.provides.add(AuthorityCreatorNeed(authority.id))

    g.user = user 
開發者ID:Netflix,項目名稱:lemur,代碼行數:28,代碼來源:service.py

示例8: on_identity_loaded

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def on_identity_loaded(sender, identity):
	user = load_user(identity.id)
	if user is None:
		return

	identity.provides.add(UserNeed(user.get_name()))
	if user.is_user():
		identity.provides.add(RoleNeed("user"))
	if user.is_admin():
		identity.provides.add(RoleNeed("admin")) 
開發者ID:AstroPrint,項目名稱:AstroBox,代碼行數:12,代碼來源:__init__.py

示例9: _on_identity_loaded

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def _on_identity_loaded(self, sender, identity: Identity) -> None:
        """
        Callback that runs whenever a new identity has been loaded.
        """
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))

        for role in getattr(current_user, 'roles', []):
            identity.provides.add(RoleNeed(role.name))

        identity.user = current_user 
開發者ID:briancappello,項目名稱:flask-unchained,代碼行數:13,代碼來源:security.py

示例10: populate_identity_roles

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def populate_identity_roles(identity, user=None):
    identity.user = user

    if user is None or user.is_anonymous:
        if current_app.config['POLICY_ANONYMOUS_VIEW_INDEX']:
            identity.provides.add(roles.index_view)
        if current_app.config['POLICY_ANONYMOUS_VIEW_POST']:
            identity.provides.add(roles.post_view)
        if current_app.config['POLICY_ANONYMOUS_VIEW_STATS']:
            identity.provides.add(roles.stats_view)
        if current_app.config['POLICY_ANONYMOUS_VIEW_TAGS']:
            identity.provides.add(roles.tags_view)
        if current_app.config['POLICY_ANONYMOUS_DOWNLOADS']:
            identity.provides.add(roles.post_download)

    else:
        identity.provides.add(UserNeed(user.identifier))
        identity.provides.add(roles.index_view)
        identity.provides.add(roles.post_view)
        identity.provides.add(roles.post_edit)
        identity.provides.add(roles.post_comment)
        identity.provides.add(roles.post_download)
        identity.provides.add(roles.stats_view)
        identity.provides.add(roles.tags_view)

        # TODO: Populate group permissions, and port existing group admin
        # code to roles.

    return identity 
開發者ID:airbnb,項目名稱:knowledge-repo,代碼行數:31,代碼來源:auth.py

示例11: init_app

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
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)) 
開發者ID:honmaple,項目名稱:maple-bbs,代碼行數:36,代碼來源:app.py

示例12: on_identity_loaded

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def on_identity_loaded(sender, identity):
    """Helper for flask-principal."""
    # Set the identity user object
    identity.user = current_user

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

    try:
        if current_user.is_admin:
            identity.provides.add(RoleNeed("admin"))
    except AttributeError:
        pass  # Definitely not an admin 
開發者ID:Flowminder,項目名稱:FlowKit,代碼行數:16,代碼來源:main.py

示例13: auth_required_same_user

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def auth_required_same_user(*args, **kwargs):
    """Decorator for requiring an authenticated user to be the same as the
    user in the URL parameters. By default the user url parameter name to
    lookup is 'id', but this can be customized by passing an argument:

    @auth_require_same_user('user_id')
    @bp.route('/users/<int:user_id>/foo/<int:id>')
    def get(user_id, id):
        # do stuff

    Any keyword arguments are passed along to the @auth_required decorator,
    so roles can also be specified in the same was as it, eg:
    @auth_required_same_user('user_id', role='ROLE_ADMIN')

    Aborts with HTTP 403: Forbidden if the user-check fails
    """
    auth_kwargs = {}
    user_id_parameter_name = 'id'
    if not was_decorated_without_parenthesis(args):
        auth_kwargs = kwargs
        if args and isinstance(args[0], str):
            user_id_parameter_name = args[0]

    def wrapper(fn):
        @wraps(fn)
        @auth_required(**auth_kwargs)
        def decorated(*args, **kwargs):
            try:
                user_id = request.view_args[user_id_parameter_name]
            except KeyError:
                raise KeyError('Unable to find the user lookup parameter '
                               f'{user_id_parameter_name} in the url args')
            if not Permission(UserNeed(user_id)).can():
                abort(HTTPStatus.FORBIDDEN)
            return fn(*args, **kwargs)
        return decorated

    if was_decorated_without_parenthesis(args):
        return wrapper(args[0])
    return wrapper 
開發者ID:briancappello,項目名稱:flask-react-spa,代碼行數:42,代碼來源:decorators.py

示例14: on_identity_loaded

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
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, 'id'):
        identity.provides.add(UserNeed(current_user.id))

    # Assuming the User model has a list of groups, update the
    # identity with the groups that the user provides
    if hasattr(current_user, 'flicket_groups'):
        the_user = FlicketUser.query.filter_by(id=current_user.id).first()
        for g in the_user.flicket_groups:
            identity.provides.add(RoleNeed('{}'.format(g.group_name))) 
開發者ID:evereux,項目名稱:flicket,代碼行數:15,代碼來源:view_admin.py

示例15: owner_permission_factory

# 需要導入模塊: import flask_principal [as 別名]
# 或者: from flask_principal import UserNeed [as 別名]
def owner_permission_factory(record=None):
    """Permission factory with owner access."""
    return Permission(UserNeed(record["owner"])) 
開發者ID:inveniosoftware,項目名稱:training,代碼行數:5,代碼來源:permissions.py


注:本文中的flask_principal.UserNeed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。