本文整理汇总了Python中assembl.auth.util.get_permissions函数的典型用法代码示例。如果您正苦于以下问题:Python get_permissions函数的具体用法?Python get_permissions怎么用?Python get_permissions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_permissions函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: widget_view
def widget_view(request):
# IF_OWNED not applicable for widgets... so far
ctx = request.context
user_id = authenticated_userid(request) or Everyone
permissions = get_permissions(
user_id, ctx.get_discussion_id())
check_permissions(ctx, user_id, permissions, CrudPermissions.READ)
view = (request.matchdict or {}).get('view', None)\
or ctx.get_default_view() or 'default'
json = ctx._instance.generic_json(view, user_id, permissions)
# json['discussion'] = ...
if user_id != Everyone:
user = User.get(user_id)
user_state = ctx._instance.get_user_state(user_id)
json['user'] = user.generic_json(view, user_id, permissions)
json['user_permissions'] = get_permissions(
user_id, ctx._instance.get_discussion_id())
if user_state is not None:
json['user_state'] = user_state
target_id = request.GET.get('target', None)
if target_id:
idea = Idea.get_instance(target_id)
if idea:
json['target'] = idea.generic_json(view, user_id, permissions)
else:
return HTTPNotFound("No idea "+target_id)
return json
开发者ID:Lornz-,项目名称:assembl,代码行数:27,代码来源:widget.py
示例2: voting_widget_view
def voting_widget_view(request):
user_id = authenticated_userid(request) or Everyone
ctx = request.context
view = (request.matchdict or {}).get('view', None)\
or ctx.get_default_view() or 'default'
widget = ctx._instance
permissions = get_permissions(
user_id, ctx.get_discussion_id())
json = widget.generic_json(view, user_id, permissions)
#json['discussion'] = ...
if user_id != Everyone:
user = User.get(user_id)
json['user'] = user.generic_json(view, user_id, permissions)
json['user_permissions'] = get_permissions(
user_id, widget.get_discussion_id())
user_state = widget.get_user_state(user_id)
if user_state is not None:
json['user_state'] = user_state
target_id = request.GET.get('target', None)
if target_id and Idea.get_database_id(target_id):
json['user_votes_url'] = widget.get_user_votes_url(target_id)
json['voting_urls'] = widget.get_voting_urls(target_id)
json['criteria'] = [idea.generic_json(view, user_id, permissions)
for idea in widget.criteria]
return json
开发者ID:Lornz-,项目名称:assembl,代码行数:25,代码来源:widget.py
示例3: add_local_role
def add_local_role(request):
# Do not use check_permissions, this is a special case
ctx = request.context
user_id = request.authenticated_userid
if not user_id:
raise HTTPUnauthorized()
discussion_id = ctx.get_discussion_id()
discussion = Discussion.get(discussion_id)
user_uri = User.uri_generic(user_id)
if discussion_id is None:
raise HTTPBadRequest()
permissions = get_permissions(user_id, discussion_id)
json = request.json_body
if "discussion" not in json:
json["discussion"] = Discussion.uri_generic(discussion_id)
requested_user = json.get('user', None)
if not requested_user:
json['user'] = requested_user = user_uri
elif requested_user != user_uri and P_ADMIN_DISC not in permissions:
raise HTTPUnauthorized()
if P_ADMIN_DISC not in permissions:
if P_SELF_REGISTER in permissions:
json['requested'] = False
json['role'] = R_PARTICIPANT
req_user = User.get_instance(requested_user)
if not discussion.check_authorized_email(req_user):
raise HTTPForbidden()
elif P_SELF_REGISTER_REQUEST in permissions:
json['requested'] = True
else:
raise HTTPUnauthorized()
try:
instances = ctx.create_object("LocalUserRole", json, user_id)
except HTTPClientError as e:
raise e
except Exception as e:
raise HTTPBadRequest(e)
if instances:
first = instances[0]
db = first.db
for instance in instances:
db.add(instance)
db.flush()
# Side effect: materialize subscriptions.
if not first.requested:
# relationship may not be initialized
user = first.user or User.get(first.user_id)
user.get_notification_subscriptions(discussion_id, True)
# Update the user's AgentStatusInDiscussion
user.update_agent_status_subscribe(discussion)
view = request.GET.get('view', None) or 'default'
permissions = get_permissions(
user_id, ctx.get_discussion_id())
return CreationResponse(first, user_id, permissions, view)
开发者ID:assembl,项目名称:assembl,代码行数:56,代码来源:auth.py
示例4: add_local_role
def add_local_role(request):
# Do not use check_permissions, this is a special case
ctx = request.context
user_id = authenticated_userid(request)
if user_id == Everyone:
raise HTTPUnauthorized()
discussion_id = ctx.get_discussion_id()
user_uri = User.uri_generic(user_id)
if discussion_id is None:
raise HTTPBadRequest()
permissions = get_permissions(user_id, discussion_id)
json = request.json_body
if "discussion" not in json:
json["discussion"] = Discussion.uri_generic(discussion_id)
requested_user = json.get('user', None)
if not requested_user:
json['user'] = requested_user = user_uri
elif requested_user != user_uri and P_ADMIN_DISC not in permissions:
raise HTTPUnauthorized()
if P_ADMIN_DISC not in permissions:
if P_SELF_REGISTER in permissions:
json['requested'] = False
json['role'] = R_PARTICIPANT
elif P_SELF_REGISTER_REQUEST in permissions:
json['requested'] = True
else:
raise HTTPUnauthorized()
try:
instances = ctx.create_object("LocalUserRole", json, user_id)
except HTTPClientError as e:
raise e
except Exception as e:
raise HTTPBadRequest(e)
if instances:
first = instances[0]
db = first.db()
for instance in instances:
db.add(instance)
db.flush()
# Side effect: materialize subscriptions.
if not first.requested:
# relationship may not be initialized
user = first.user or User.get(first.user_id)
user.get_notification_subscriptions(discussion_id, True)
view = request.GET.get('view', None) or 'default'
permissions = get_permissions(
user_id, ctx.get_discussion_id())
return Response(
dumps(first.generic_json(view, user_id, permissions)),
location=first.uri_generic(first.id),
status_code=201)
开发者ID:hypnotics,项目名称:assembl,代码行数:51,代码来源:auth.py
示例5: fetch_posts
def fetch_posts(request):
ctx = request.context
csource = ctx._instance
force_restart = request.params.get('force_restart', False)
reimport = request.params.get('reimport', False)
limit = request.params.get('limit', None)
if limit:
try:
limit = int(limit)
except ValueError:
raise HTTPBadRequest("Non-numeric limit value: "+limit)
if force_restart or reimport or limit:
# Only discussion admins
user_id = authenticated_userid(request) or Everyone
permissions = get_permissions(
user_id, ctx.get_discussion_id())
if P_ADMIN_DISC not in permissions:
requested = []
if reimport:
requested.append('reimport')
if force_restart:
requested.append('force restart')
raise HTTPUnauthorized("Only discussion administrator can "+'and'.join(requested))
wake(csource.id, reimport, force_restart, limit=limit)
return {"message": "Source notified",
"name": csource.name}
开发者ID:rmoorman,项目名称:assembl,代码行数:27,代码来源:content_source.py
示例6: delete_post_instance
def delete_post_instance(request):
# Users who are allowed to delete (actually tombstone) a Post instance:
# - user who is the author of the Post instance and who has the P_DELETE_MY_POST permission in this discussion
# - user who has the P_DELETE_POST permission in this discussion
ctx = request.context
user_id = request.authenticated_userid or Everyone
permissions = get_permissions(
user_id, ctx.get_discussion_id())
instance = ctx._instance
allowed = False
if (user_id == instance.creator_id and P_DELETE_MY_POST in permissions) or (P_DELETE_POST in permissions):
allowed = True
if not allowed:
raise HTTPUnauthorized()
# Remove extracts associated to this post
extracts_to_remove = instance.db.query(Extract).filter(Extract.content_id == instance.id).all()
number_of_extracts = len(extracts_to_remove)
for extract in extracts_to_remove:
extract.delete()
if user_id == instance.creator_id and P_DELETE_MY_POST in permissions:
cause = PublicationStates.DELETED_BY_USER
elif P_DELETE_POST in permissions:
cause = PublicationStates.DELETED_BY_ADMIN
instance.delete_post(cause)
return {
"result": "Post has been successfully deleted.",
"removed_extracts": number_of_extracts
}
开发者ID:assembl,项目名称:assembl,代码行数:33,代码来源:post.py
示例7: _get_ideas_real
def _get_ideas_real(discussion, view_def=None, ids=None, user_id=None):
user_id = user_id or Everyone
# optimization: Recursive widget links.
from assembl.models import (
Widget, IdeaWidgetLink, IdeaDescendantsShowingWidgetLink)
universal_widget_links = []
by_idea_widget_links = defaultdict(list)
widget_links = discussion.db.query(IdeaWidgetLink
).join(Widget).join(Discussion).filter(
Widget.test_active(), Discussion.id == discussion.id,
IdeaDescendantsShowingWidgetLink.polymorphic_filter()
).options(joinedload_all(IdeaWidgetLink.idea)).all()
for wlink in widget_links:
if isinstance(wlink.idea, RootIdea):
universal_widget_links.append({
'@type': wlink.external_typename(),
'widget': Widget.uri_generic(wlink.widget_id)})
else:
for id in wlink.idea.get_all_descendants(True):
by_idea_widget_links[Idea.uri_generic(id)].append({
'@type': wlink.external_typename(),
'widget': Widget.uri_generic(wlink.widget_id)})
next_synthesis = discussion.get_next_synthesis()
ideas = discussion.db.query(Idea).filter_by(
discussion_id=discussion.id
)
ideas = ideas.outerjoin(SubGraphIdeaAssociation,
and_(SubGraphIdeaAssociation.sub_graph_id==next_synthesis.id, SubGraphIdeaAssociation.idea_id==Idea.id)
)
ideas = ideas.outerjoin(IdeaLink,
and_(IdeaLink.target_id==Idea.id)
)
ideas = ideas.order_by(IdeaLink.order, Idea.creation_date)
if ids:
ids = [get_database_id("Idea", id) for id in ids]
ideas = ideas.filter(Idea.id.in_(ids))
# remove tombstones
ideas = ideas.filter(and_(*Idea.base_conditions()))
ideas = ideas.options(
joinedload_all(Idea.source_links),
joinedload_all(Idea.has_showing_widget_links),
undefer(Idea.num_children))
permissions = get_permissions(user_id, discussion.id)
Idea.prepare_counters(discussion.id, True)
retval = [idea.generic_json(view_def, user_id, permissions)
for idea in ideas]
retval = [x for x in retval if x is not None]
for r in retval:
if r.get('widget_links', None) is not None:
links = r['widget_links'][:]
links.extend(universal_widget_links)
links.extend(by_idea_widget_links[r['@id']])
r['active_widget_links'] = links
return retval
开发者ID:festrade,项目名称:assembl,代码行数:60,代码来源:idea.py
示例8: discussion_edit
def discussion_edit(request):
discussion_id = int(request.matchdict["discussion_id"])
discussion = Discussion.get_instance(discussion_id)
user_id = authenticated_userid(request)
assert user_id
permissions = get_permissions(user_id, discussion_id)
partners = json.dumps(
[p.generic_json(user_id=user_id, permissions=permissions) for p in discussion.partner_organizations]
)
if not discussion:
raise HTTPNotFound("Discussion with id '%d' not found." % (discussion_id,))
context = dict(
get_default_context(request),
discussion=discussion,
admin_discussion_permissions_url=request.route_url("discussion_permissions", discussion_id=discussion.id),
partners=partners,
)
if request.method == "POST":
g = lambda x: request.POST.get(x, None)
(topic, slug, objectives) = (g("topic"), g("slug"), g("objectives"))
discussion.topic = topic
discussion.slug = slug
discussion.objectives = objectives
return render_to_response("admin/discussion_edit.jinja2", context, request=request)
开发者ID:rmoorman,项目名称:assembl,代码行数:31,代码来源:views.py
示例9: votes_collection_add
def votes_collection_add(request):
ctx = request.context
user_id = authenticated_userid(request)
permissions = get_permissions(
user_id, ctx.get_discussion_id())
check_permissions(ctx, user_id, permissions, CrudPermissions.CREATE)
args = request.params
if 'type' in args:
args = dict(args)
typename = args['type']
del args['type']
else:
typename = ctx.collection_class.external_typename()
args['voter_id'] = user_id
try:
instances = ctx.create_object(typename, None, user_id, **args)
except Exception as e:
raise HTTPBadRequest(e)
if instances:
first = instances[0]
db = first.db()
for instance in instances:
db.add(instance)
print "before flush"
db.flush()
print "after flush"
return Response(
dumps(first.generic_json('default', user_id, permissions)),
location=first.uri_generic(first.id),
status_code=201)
raise HTTPBadRequest()
开发者ID:hypnotics,项目名称:assembl,代码行数:31,代码来源:__init__.py
示例10: save_synthesis
def save_synthesis(request):
synthesis_id = request.matchdict['id']
discussion_id = int(request.matchdict['discussion_id'])
if synthesis_id == 'next_synthesis':
discussion = Discussion.get_instance(discussion_id)
synthesis = discussion.get_next_synthesis()
else:
synthesis = Synthesis.get_instance(synthesis_id)
if not synthesis:
raise HTTPBadRequest("Synthesis with id '%s' not found." % synthesis_id)
synthesis_data = json.loads(request.body)
user_id = request.authenticated_userid
permissions = get_permissions(user_id, discussion_id)
for key in ('subject', 'introduction', 'conclusion'):
if key in synthesis_data:
ls_data = synthesis_data[key]
if ls_data is None:
continue
assert isinstance(ls_data, dict)
current = LangString.create_from_json(
ls_data, user_id, permissions=permissions)
setattr(synthesis, key, current)
Synthesis.default_db.add(synthesis)
Synthesis.default_db.flush()
return {'ok': True, 'id': synthesis.uri()}
开发者ID:assembl,项目名称:assembl,代码行数:29,代码来源:synthesis.py
示例11: mutate
def mutate(root, args, context, info):
model = models.User
discussion_id = context.matchdict['discussion_id']
discussion = models.Discussion.get(discussion_id)
user_id = context.authenticated_userid or Everyone
global_id = args.get('id')
id_ = int(Node.from_global_id(global_id)[1])
user = model.get(id_)
# Global permission check. Permission is checked in the preferences setter
# Is it necessary?
permissions = get_permissions(user_id, discussion_id)
allowed = user.user_can(
user_id, CrudPermissions.UPDATE, permissions)
if not allowed:
raise HTTPUnauthorized("You don't have the authorization to update this haversting locale. If you think it's an error, please reconnect to assembl.")
with model.default_db.no_autoflush as db:
preferences = user.get_preferences_for_discussion(discussion)
# Permission check in the preferences setter
# See models.user_key_value and models.preferences preference_data_list
preferences['harvesting_translation'] = args.get('translation')
db.flush()
return UpdateHarvestingTranslationPreference(
preferences=preferences)
开发者ID:assembl,项目名称:assembl,代码行数:26,代码来源:preferences.py
示例12: mutate
def mutate(root, args, context, info):
user_id = context.authenticated_userid or Everyone
post_id = args.get('post_id')
post_id = int(Node.from_global_id(post_id)[1])
post = models.Post.get(post_id)
discussion_id = context.matchdict['discussion_id']
permissions = get_permissions(user_id, discussion_id)
require_instance_permission(CrudPermissions.DELETE, post, context)
# Same logic as in assembl/views/api2/post.py:delete_post_instance
# Remove extracts associated to this post
extracts_to_remove = post.db.query(models.Extract).filter(
models.Extract.content_id == post.id).all()
for extract in extracts_to_remove:
extract.delete()
if user_id == post.creator_id and P_DELETE_MY_POST in permissions:
cause = models.PublicationStates.DELETED_BY_USER
elif P_DELETE_POST in permissions:
cause = models.PublicationStates.DELETED_BY_ADMIN
post.delete_post(cause)
post.db.flush()
return DeletePost(post=post)
开发者ID:assembl,项目名称:assembl,代码行数:25,代码来源:post.py
示例13: require_instance_permission
def require_instance_permission(permission_type, instance, request):
user_id = request.authenticated_userid or Everyone
discussion_id = request.matchdict['discussion_id']
permissions = get_permissions(user_id, discussion_id)
allowed = instance.user_can(user_id, permission_type, permissions) if instance else False
if not allowed:
raise HTTPUnauthorized(request.localizer.translate(error))
开发者ID:assembl,项目名称:assembl,代码行数:7,代码来源:permissions_helpers.py
示例14: require_cls_permission
def require_cls_permission(permission_type, cls, request):
user_id = request.authenticated_userid or Everyone
discussion_id = request.matchdict['discussion_id']
permissions = get_permissions(user_id, discussion_id)
allowed = cls.user_can_cls(user_id, permission_type, permissions)
if not allowed or (allowed == IF_OWNED and user_id == Everyone):
raise HTTPUnauthorized(request.localizer.translate(error))
开发者ID:assembl,项目名称:assembl,代码行数:7,代码来源:permissions_helpers.py
示例15: get_token
def get_token(request):
user_id = authenticated_userid(request)
discussion_id = request.context.get_discussion_id()
if not user_id:
raise HTTPUnauthorized()
req_permissions = request.GET.getall('permission') or [
P_READ, P_READ_PUBLIC_CIF]
random_seed = request.GET.get('seed', None)
if random_seed:
# We need some determinism
import random
random.seed(random_seed)
random_str = ''.join([chr(random.randint(0,256)) for i in range(8)])
random.seed(urandom(8))
else:
random_str = urandom(8)
if isinstance(req_permissions, list):
req_permissions = set(req_permissions)
else:
req_permissions = set((req_permissions,))
permissions = set(get_permissions(user_id, discussion_id))
if not req_permissions:
req_permissions = permissions
else:
if P_READ in permissions:
permissions.add(P_READ_PUBLIC_CIF)
if P_SYSADMIN not in permissions:
req_permissions = list(req_permissions.intersection(permissions))
req_permissions = list(req_permissions)
data = [str(user_id), str(discussion_id)]
data.extend([str(x) for (x,) in Permission.db.query(Permission.id).filter(
Permission.name.in_(req_permissions)).all()])
data = ','.join(data) + '.' + base64.urlsafe_b64encode(random_str)
return Response(body=data_token(data), content_type="text/text")
开发者ID:hypnotics,项目名称:assembl,代码行数:34,代码来源:discussion.py
示例16: resolve_email
def resolve_email(self, args, context, info):
user_id = context.authenticated_userid or Everyone
discussion_id = context.matchdict['discussion_id']
permissions = get_permissions(user_id, discussion_id)
include_emails = P_ADMIN_DISC in permissions or P_SYSADMIN in permissions
if include_emails or self.id == user_id:
return self.get_preferred_email()
开发者ID:assembl,项目名称:assembl,代码行数:7,代码来源:user.py
示例17: collection_add_json
def collection_add_json(request, json=None):
ctx = request.context
json = request.json_body if json is None else json
user_id = authenticated_userid(request) or Everyone
permissions = get_permissions(
user_id, ctx.get_discussion_id())
typename = ctx.collection_class.external_typename()
typename = json.get(
'@type', ctx.collection_class.external_typename())
cls = ctx.get_collection_class(typename)
check_permissions(ctx, user_id, permissions, CrudPermissions.CREATE, cls)
try:
instances = ctx.create_object(typename, json, user_id)
except Exception as e:
raise HTTPBadRequest(e)
if instances:
first = instances[0]
db = first.db
for instance in instances:
db.add(instance)
db.flush()
view = request.GET.get('view', None) or 'default'
return Response(
dumps(first.generic_json(view, user_id, permissions)),
location=first.uri_generic(first.id),
status_code=201)
开发者ID:Lornz-,项目名称:assembl,代码行数:26,代码来源:__init__.py
示例18: notif_collection_add_json
def notif_collection_add_json(request):
ctx = request.context
user_id = authenticated_userid(request) or Everyone
permissions = get_permissions(
user_id, ctx.get_discussion_id())
check_permissions(ctx, user_id, permissions, CrudPermissions.CREATE)
typename = ctx.collection_class.external_typename()
typename = request.json_body.get(
'@type', ctx.collection_class.external_typename())
json = request.json_body
try:
instances = ctx.create_object(typename, json, user_id)
except Exception as e:
raise HTTPBadRequest(e)
if instances:
first = instances[0]
db = first.db
for instance in instances:
db.add(instance)
db.flush()
templates = ctx.find_collection('Discussion.user_templates')
if templates:
templates.parent_instance.reset_participant_default_subscriptions(False)
view = request.GET.get('view', None) or 'default'
return Response(
dumps(first.generic_json(view, user_id, permissions)),
location=first.uri_generic(first.id),
status_code=201)
开发者ID:Lornz-,项目名称:assembl,代码行数:28,代码来源:notification.py
示例19: collection_add
def collection_add(request, args):
ctx = request.context
user_id = authenticated_userid(request) or Everyone
permissions = get_permissions(
user_id, ctx.get_discussion_id())
check_permissions(ctx, user_id, permissions, CrudPermissions.CREATE)
if 'type' in args:
args = dict(args)
typename = args['type']
del args['type']
else:
typename = ctx.collection_class.external_typename()
session = User.default_db
old_autoflush = session.autoflush
session.autoflush = False
try:
instances = ctx.create_object(typename, None, user_id, **args)
except Exception as e:
session.autoflush = old_autoflush
raise HTTPBadRequest(e)
if instances:
first = instances[0]
db = first.db
for instance in instances:
db.add(instance)
session.autoflush = old_autoflush
session.flush()
return Response(
dumps(first.generic_json('default', user_id, permissions)),
location=first.uri_generic(first.id),
status_code=201)
raise HTTPBadRequest()
开发者ID:Lornz-,项目名称:assembl,代码行数:32,代码来源:__init__.py
示例20: class_add
def class_add(request):
ctx = request.context
user_id = authenticated_userid(request) or Everyone
permissions = get_permissions(
user_id, ctx.get_discussion_id())
check_permissions(ctx, user_id, permissions, CrudPermissions.CREATE)
args = request.params
typename = args.get('type', None)
if typename:
cls = ctx.get_class(typename)
else:
cls = request.context._class
typename = cls.external_typename()
try:
instances = ctx.create_object(typename, None, user_id, **args)
except ObjectNotUniqueError as e:
raise JSONError(409, str(e))
except Exception as e:
raise HTTPBadRequest(e)
if instances:
first = instances[0]
db = first.db
for instance in instances:
db.add(instance)
db.flush()
return Response(
dumps(first.generic_json('default', user_id, permissions)),
location=first.uri_generic(first.id),
status_code=201)
raise HTTPBadRequest()
开发者ID:Lornz-,项目名称:assembl,代码行数:30,代码来源:__init__.py
注:本文中的assembl.auth.util.get_permissions函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论