def get(self, request, **kwargs): profile_result = get_profile_data(kwargs) if not profile_result.ok: return WebsiteErrorView.website_error( request, WebsiteError.PROFILE_NOT_FOUND, {"profile_oid": profile_result.oid_org}) root_oid = get_root_oid(request) profile_model = profile_result.model channel_model = ChannelManager.get_channel_oid( profile_model.channel_oid) permissions = ProfileManager.get_user_permissions( channel_model.id, root_oid) # noinspection PyTypeChecker return render_template( request, _("Profile Info - {}").format(profile_model.name), "info/profile.html", { "profile_data": profile_model, "profile_controls": ProfileHelper.get_user_profile_controls( channel_model, profile_model.id, root_oid, permissions), "perm_cats": list(ProfilePermission), "is_default": profile_model.id == channel_model.config.default_profile_oid }, nav_param=kwargs)
def get(self, request, *args, **kwargs): channel_result = self.get_channel_data(*args, **kwargs) permissions = ProfileManager.get_user_permissions(channel_result.model.id, get_root_oid(request)) can_ced_profile = ProfilePermission.PRF_CED in permissions return render_template( self.request, _("List Profile"), "account/channel/prof/list.html", { "prof_entry": ProfileHelper.get_channel_profiles(channel_result.model.id), "perm_cats": list(ProfilePermission), "can_ced_profile": can_ced_profile, "channel_oid": channel_result.model.id }, nav_param=kwargs)
def dispatch(self, request, *args, **kwargs): root_oid = get_root_oid(request) pass_ = ProfileManager.get_user_permissions(self.get_channel_data(*args, **kwargs).model.id, root_oid)\ .issuperset(self.required_permission()) if not pass_: return WebsiteErrorView.website_error( request, WebsiteError.INSUFFICIENT_PERMISSION, { "channel_oid": self.get_channel_data(*args, ** kwargs).oid_org, "required_permission": self.required_permission() }, nav_param=kwargs) else: return super().dispatch(request, *args, **kwargs)
def get(self, request, *args, **kwargs): root_oid = get_root_oid(request) channel_data = self.get_channel_data(*args, **kwargs) channel_oid = channel_data.model.id attach_member = ProfileManager.can_control_profile_member( ProfileManager.get_user_permissions(channel_oid, root_oid)) member_list = {} if attach_member: member_list = IdentitySearcher.get_batch_user_name( ProfileManager.get_channel_member_oids(channel_oid, available_only=True), channel_data.model) member_list = sorted(member_list.items(), key=lambda item: item[1]) return render_template( self.request, _("Attach Profile"), "account/channel/prof/attach.html", { "channel_oid": channel_oid, "attachable_profiles": ProfileManager.get_attachable_profiles(channel_data.model.get_oid(), root_oid), "member_list": member_list }, nav_param=kwargs)
def post(self, request, **kwargs): sender_oid = get_root_oid(request) profile_result = get_profile_data(kwargs) if not profile_result.ok: return HttpResponse(status=404) channel_model = ChannelManager.get_channel_oid( profile_result.model.channel_oid) # --- Get form data action = InfoPageActionControl.parse(request.POST.get("action")) target_uid = safe_cast(request.POST.get("uid"), ObjectId) if not action.is_argument_valid(target_uid): return HttpResponse(status=400) # --- Check permission permissions = ProfileManager.get_user_permissions( channel_model.id, sender_oid) # --- Execute corresponding action profile_oid = profile_result.model.id if action == InfoPageActionControl.DETACH: return InfoPageActionControl.action_detach(request, channel_model.id, sender_oid, target_uid, permissions, profile_oid) elif action == InfoPageActionControl.DELETE: return InfoPageActionControl.action_delete(request, channel_model, profile_oid) else: return HttpResponse(status=501)
def _permission_check_(self): permission_pass = ProfileManager.get_user_permissions(self._channel_oid, self._sender_oid)\ .issuperset(self.required_permission()) if not permission_pass: self._err[result.SenderIdentity.PERMISSION] = False
def _has_access_to_pinned_(channel_oid: ObjectId, user_oid: ObjectId): perms = ProfileManager.get_user_permissions(channel_oid, user_oid) return ProfilePermission.AR_ACCESS_PINNED_MODULE in perms