当前位置: 首页>>代码示例>>Python>>正文


Python Permission.can方法代码示例

本文整理汇总了Python中flask_principal.Permission.can方法的典型用法代码示例。如果您正苦于以下问题:Python Permission.can方法的具体用法?Python Permission.can怎么用?Python Permission.can使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_principal.Permission的用法示例。


在下文中一共展示了Permission.can方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
    def post(self, id):
        request_arg = RequestMethod_parser.parse_args()
        requestMethod = request_arg['requestMethod']
        if requestMethod == "PUT":
            permission = Permission(ActionNeed('修改新闻属性'))
            if permission.can()is not True:
                abort_if_unauthorized("修改新闻属性")

            category = Category.query.filter(Category.id == id).first()
            abort_if_not_exist(category, "category")
            args = parser_spec.parse_args()
            name = args['name']
            if name != None and name != category.name:
                c = Category.query.filter(Category.name == name).first()
                abort_if_exist(c, "category")
                category.name = name
            db.session.add(category)
            db.session.commit()
        elif requestMethod == "DELETE":
            permission = Permission(ActionNeed('删除新闻属性'))
            if permission.can()is not True:
                abort_if_unauthorized("删除新闻属性")
            id = int(id)
            category = Category.query.filter(Category.id == id).first()
            abort_if_not_exist(category, "category")
            db.session.delete(category)
            db.session.commit()
        else:
            abort(404, message="api not found")
开发者ID:SicunStudio,项目名称:aunet-flask,代码行数:31,代码来源:news.py

示例2: status

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
 def status(self, value):
     old_status = self._status
     assert value in status_enum_list
     if value == self._status:
         return True
     roles_accepted = self.roles_accepted.get(value, None)
     if roles_accepted:
         perm = Permission(*[RoleNeed(role) for role in roles_accepted])
         if not perm.can():
             raise RuntimeError("You're not authorized to set this status")
     status_required = self.status_required.get(value, None)
     if status_required and self._status != status_required:
         raise ValueError("You cannot set status from {} to {}".format(self._status, value))
     self._status = value
     self.status_changed()
     taxi = TaxiM.cache.get(self.taxi_id)
     taxi.synchronize_status_with_hail(self)
     client = influx_db.get_client(current_app.config['INFLUXDB_TAXIS_DB'])
     try:
         client.write_points([{
             "measurement": "hails_status_changed",
             "tags": {
                 "added_by": User.query.get(self.added_by).email,
                 "operator": self.operateur.email,
                 "zupc": taxi.ads.zupc.insee,
                 "previous_status": old_status,
                 "status": self._status
                 },
             "time": datetime.utcnow().strftime('%Y%m%dT%H:%M:%SZ'),
             "fields": {
                 "value": 1
             }
             }])
     except Exception as e:
         current_app.logger.error('Influxdb Error: {}'.format(e))
开发者ID:odtvince,项目名称:APITaxi_models,代码行数:37,代码来源:hail.py

示例3: _contact_handler

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
def _contact_handler(user_id, endpoint):
    contact = Contact.query.get(user_id) if user_id else Contact()
    contact_form = ContactForm(obj=contact)

    admin_permisssion = Permission(RoleNeed('admin'))
    if not admin_permisssion.can():
        del contact_form.roles

    credentials_form = CredentialsForm(obj=contact)
    forms = {
        'contact_details': contact_form,
        'contact_credentials': credentials_form,
    }
    current_form = forms.get(request.form.get('action'))
    if current_form and current_form.validate_on_submit():
        contact = Contact.query.get(user_id) if user_id else Contact()
        current_form.populate_obj(contact)
        if not contact.id:
            db.session.add(contact)
        db.session.commit()
        flash(_('User updated.'), 'success')
        kwargs = {
            'user_id': contact.id,
        }
        return redirect(url_for(endpoint, **kwargs))
    context = {
        'user_id': contact.id,
        'contact': contact,
        'contact_form': contact_form,
        'credentials_form': credentials_form,
    }
    return render_template('admin/users/form.html', **context)
开发者ID:TammyAndBenjamin,项目名称:tabapp,代码行数:34,代码来源:users.py

示例4: get

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
 def get(self, id):
     permission = Permission(ActionNeed(('查看权限节点')))
     if permission.can() is not True:
         abort_if_unauthorized("查看权限节点")
     node = Node.query.filter(Node.id == id).first()
     abort_if_not_exist(node, "node")
     return node
开发者ID:SicunStudio,项目名称:aunet-flask,代码行数:9,代码来源:users.py

示例5: post

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
    def post(self):
        request_arg = RequestMethod_parser.parse_args()
        requestMethod = request_arg['requestMethod']
        print(requestMethod)
        if requestMethod == "POST":
            permission = Permission(ActionNeed('添加角色'))
            if permission.can()is not True:
                abort_if_unauthorized("添加角色")
            args = Role_parser.parse_args()
            roleName = args['roleName']
            try:
                nodeName = list(eval(args['nodeName'][0]))
            except:
                nodeName = args['nodeName']

            role1 = Role.query.filter(Role.roleName == roleName).first()
            abort_if_exist(role1, "roleName")
            role = Role(roleName)
            db.session.add(role)
            db.session.commit()
            for name in nodeName:
                node = Node.query.filter(Node.nodeName == name).first()
                abort_if_not_exist(node, "node")
                role.nodes.append(node)
            db.session.add(role)
            db.session.commit()
        else:
            abort(404, message="api not found")
开发者ID:SicunStudio,项目名称:aunet-flask,代码行数:30,代码来源:users.py

示例6: get

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
 def get(self, id):
     permission = Permission(ActionNeed(('查看新闻')))
     if permission.can() is not True:
         abort_if_unauthorized("查看新闻")
     news = News.query.filter(News.id == id).first()
     abort_if_not_exist(news, "news")
     return news
开发者ID:SicunStudio,项目名称:aunet-flask,代码行数:9,代码来源:news.py

示例7: decorated_view

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
 def decorated_view(*args, **kwargs):
     perm = Permission(*[RoleNeed(role) for role in roles])
     if perm.can():
         return fn(*args, **kwargs)
     if _security._unauthorized_callback:
         return _security._unauthorized_callback()
     else:
         return _get_unauthorized_view()
开发者ID:ArioShaman,项目名称:flask-site,代码行数:10,代码来源:decorators.py

示例8: decorated_function

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
 def decorated_function(*args, **kwargs):
     if not current_user.is_authenticated():
         return redirect(url_for('login_bp.login', next=request.path))
     for key in role_keys:
         permisssion = Permission(RoleNeed(key))
         if permisssion.can():
             return f(*args, **kwargs)
     return abort(403)
开发者ID:TammyAndBenjamin,项目名称:tabapp,代码行数:10,代码来源:security.py

示例9: decorator

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
 def decorator(*args, **kwargs):
     permission = Permission(RoleNeed('confirmed'))
     if not permission.can():
         flash(
             _("You haven't confirm your account,Please confirmed"),
             'warning')
         return redirect(url_for('user.user',
                                 user_url=current_user.username))
     return func(*args, **kwargs)
开发者ID:0xsKu,项目名称:maple-bbs,代码行数:11,代码来源:permission.py

示例10: put

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
    def put(self, topicId):
        def callback():
            flash(_("You have no permission"), 'warning')
            return redirect(url_for('topic.topic', topicId=topicId))

        permission = Permission(EditTopicNeed(topicId))
        if not permission.can():
            self.callback = callback
            return True
开发者ID:0xsKu,项目名称:maple-bbs,代码行数:11,代码来源:permission.py

示例11: can_access

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
def can_access(endpoint):
    """ Method used in templates only, it helps to validate endpoint access """
    f = current_app.view_functions[endpoint]
    if not hasattr(f, 'role_keys'):
        return True
    for role_key in f.role_keys:
        permisssion = Permission(RoleNeed(role_key))
        if permisssion.can():
            return True
    return False
开发者ID:TammyAndBenjamin,项目名称:tabapp,代码行数:12,代码来源:security.py

示例12: post

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
 def post(self):
     form = request.form.getlist('add-to-collect')
     for collectId in form:
         try:
             collectId = int(collectId)
             permission = Permission(PostCollect(collectId))
             if not permission.can():
                 return True
         except ValueError:
             abort(403)
开发者ID:0xsKu,项目名称:maple-bbs,代码行数:12,代码来源:permission.py

示例13: status

# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import can [as 别名]
 def status(self, value):
     assert value in status_enum_list
     if value == self.__status:
         return True
     roles_accepted = self.roles_accepted.get(value, None)
     if roles_accepted:
         perm = Permission(*[RoleNeed(role) for role in roles_accepted])
         if not perm.can():
             raise RuntimeError("You're not authorized to set this status")
     status_required = self.status_required.get(value, None)
     if status_required and self.__status != status_required:
         raise ValueError("You cannot set status from {} to {}".format(self.__status, value))
     self.__status = value
     self.status_changed()
     TaxiM.query.get(self.taxi_id).synchronize_status_with_hail(self)
开发者ID:odtvince,项目名称:APITaxi,代码行数:17,代码来源:hail.py


注:本文中的flask_principal.Permission.can方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。