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


Python flask_principal.Permission类代码示例

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


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

示例1: post

 def post(self):
     request_arg = RequestMethod_parser.parse_args()
     requestMethod = request_arg['requestMethod']
     if requestMethod == "POST":
         permission = Permission(ActionNeed('添加用户'))
         if permission.can()is not True:
             abort_if_unauthorized("添加用户")
         args = User_parser.parse_args()
         try:
             args['roleName'] = list(eval(args['roleName'][0]))
         except:
             pass
         userName = args['userName']
         passWord = args['passWord']
         email = args['email']
         roleName = args['roleName']
         phone = args['phone']
         user1 = User.query.filter(User.userName == userName).first()
         abort_if_exist(user1, "userName")
         try:
             html = render_template(
                 "Admin/user_info.html", user_name=userName, password=passWord, flag="创建账号")
             send_email("社团网账号信息", [email], html)
             user = User(userName, passWord, email, phone)
             for name in roleName:
                 role = Role.query.filter(Role.roleName == name).first()
                 abort_if_not_exist(role, "role")
                 user.roles.append(role)
             db.session.add(user)
             db.session.commit()
         except:
             pass
     else:
         abort(404, message="api not found")
开发者ID:SicunStudio,项目名称:aunet-flask,代码行数:34,代码来源:users.py

示例2: status

 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,代码行数:35,代码来源:hail.py

示例3: post

 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("修改新闻标签")
         tag = Tag.query.filter(Tag.id == id).first()
         abort_if_not_exist(tag, "tag")
         args = parser_spec.parse_args()
         name = args['name']
         if name != None and name != tag.name:
             t = Tag.query.filter(Tag.name == name).first()
             abort_if_exist(t, "tag")
             tag.name = name
         db.session.add(tag)
         db.session.commit()
     elif requestMethod == "DELETE":
         permission = Permission(ActionNeed('删除新闻标签'))
         if permission.can()is not True:
             abort_if_unauthorized("删除新闻标签")
         tag = Tag.query.filter(Tag.id == id).first()
         abort_if_not_exist(tag, "tag")
         db.session.delete(tag)
         db.session.commit()
     else:
         abort(404, message="api not found")
开发者ID:SicunStudio,项目名称:aunet-flask,代码行数:27,代码来源:news.py

示例4: _contact_handler

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,代码行数:32,代码来源:users.py

示例5: contact

def contact(retailer_id, contact_id):
    permisssion = Permission(RoleNeed('normal'))
    need = ItemNeed('access', 'retailer', retailer_id)
    if not permisssion.union(Permission(need)).can():
        return abort(403)
    retailer = Retailer.query.get(retailer_id)
    contact = Contact.query.get(contact_id) if contact_id else Contact()
    contact_form = ContactForm(obj=contact)
    del contact_form.roles
    if contact_form.validate_on_submit():
        contact_form.populate_obj(contact)
        contact.phone = contact_form.phone.data
        if not contact.id:
            retailer.contacts.append(contact)
        db.session.commit()
        flash(_('User updated.'), 'success')
        kwargs = {
            'retailer_id': retailer.id,
            'contact_id': contact.id,
        }
        return redirect(url_for('retailers_bp.contact', **kwargs))
    context = {
        'user_id': contact.id,
        'retailer': retailer,
        'tab_counts': tab_counts(retailer),
        'contact': contact,
        'contact_form': contact_form,
    }
    return render_template('retailers/contact.html', **context)
开发者ID:TammyAndBenjamin,项目名称:tabapp,代码行数:29,代码来源:main.py

示例6: test_permission_difference

 def test_permission_difference(self):
     p1 = Permission(('a', 'b'), ('a', 'c'))
     p2 = Permission(('a', 'c'), ('d', 'e'))
     p3 = p1.difference(p2)
     assert p3.needs == set([('a', 'b')])
     p4 = p2.difference(p1)
     assert p4.needs == set([('d', 'e')])
开发者ID:Mondego,项目名称:pyreco,代码行数:7,代码来源:allPythonContent.py

示例7: get

 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,代码行数:7,代码来源:news.py

示例8: get

 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,代码行数:7,代码来源:users.py

示例9: test_permission_or

    def test_permission_or(self):
        p1 = Permission(RoleNeed('boss'), RoleNeed('lackey'))
        p2 = Permission(RoleNeed('lackey'), RoleNeed('underling'))

        p3 = p1 | p2
        p4 = p1.difference(p2)

        assert p3.needs == p4.needs
开发者ID:Mondego,项目名称:pyreco,代码行数:8,代码来源:allPythonContent.py

示例10: decorated_function

 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,代码行数:8,代码来源:security.py

示例11: decorated_view

 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,代码行数:8,代码来源:decorators.py

示例12: test_permission_and

    def test_permission_and(self):
        p1 = Permission(RoleNeed('boss'))
        p2 = Permission(RoleNeed('lackey'))

        p3 = p1 & p2
        p4 = p1.union(p2)

        assert p3.needs == p4.needs
开发者ID:Mondego,项目名称:pyreco,代码行数:8,代码来源:allPythonContent.py

示例13: put

    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,代码行数:9,代码来源:permission.py

示例14: decorator

 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,代码行数:9,代码来源:permission.py

示例15: post

 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,代码行数:10,代码来源:permission.py


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