예제 #1
0
    def get(self, request, *args, **kwargs):
        # `kwargs` will be used as `nav_param` so extract channel_oid from `kwargs` instead of creating param.
        channel_oid_str = kwargs.get("channel_oid", "")
        channel_oid = safe_cast(channel_oid_str, ObjectId)
        u_profs = ProfileManager.get_user_profiles(channel_oid, get_root_oid(request))

        if u_profs:
            return render_template(
                self.request, _("Channel Management - {}").format(channel_oid), "account/channel/manage.html", {
                    "user_profiles": u_profs,
                    "perm_sum": sorted(ProfileManager.get_permissions(u_profs), key=lambda x: x.code),
                    "channel_oid": channel_oid
                }, nav_param=kwargs)
        else:
            c_prof = ChannelManager.get_channel_oid(channel_oid)

            if c_prof:
                messages.info(
                    request, _("You are redirected to the channel info page "
                               "because you don't have any connections linked to the channel."),
                    extra_tags="info"
                )

                return redirect(reverse("info.channel", kwargs={"channel_oid": channel_oid}))
            else:
                return WebsiteErrorView.website_error(
                    request, WebsiteError.PROFILE_LINK_NOT_FOUND, {"channel_oid": channel_oid_str})
예제 #2
0
    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)
예제 #3
0
    def dispatch(self, request, *args, **kwargs):
        if not self.get_channel_data(*args, **kwargs).ok:
            return WebsiteErrorView.website_error(
                request,
                WebsiteError.CHANNEL_NOT_FOUND, {
                    "channel_oid": self.get_channel_data(*args, **
                                                         kwargs).oid_org
                },
                nav_param=kwargs)

        return super().dispatch(request, *args, **kwargs)
예제 #4
0
 def get(self, request, page_id, *args, **kwargs):
     page_content = ExtraContentManager.get_content(page_id)
     d = {"page_id": page_id}
     if page_content:
         title = page_content.title if page_content.title != ExtraContentManager.DefaultTitle else page_id
         return render_template(request, _("Extra Content - {}").format(title), "exctnt.html", {
             "content": page_content.content_html,
             "expiry": page_content.expires_on
         }, nav_param=d)
     else:
         return WebsiteErrorView.website_error(request, WebsiteError.EXTRA_CONTENT_NOT_FOUND, d, nav_param=d)
예제 #5
0
 def get(self, request, code, *args, **kwargs):
     node = cmd_root.get_child_node(code)
     if node:
         return render_template(request,
                                _("Bot Command - {}").format(
                                    node.main_cmd_code),
                                "doc/botcmd_node.html", {"cmd_node": node},
                                nav_param={"code": code})
     else:
         return WebsiteErrorView.website_error(
             request,
             WebsiteError.BOT_CMD_NOT_FOUND, {"cmd_code": code},
             nav_param={"code": code})
예제 #6
0
    def get(self, request, *args, **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})

        profile_model = profile_result.model

        return render_template(
            self.request, _("Edit Profile"), "account/channel/prof/edit.html",
            {
                "value_color": profile_model.color.color_hex,
                "value_name": profile_model.name
            }, nav_param=kwargs)
예제 #7
0
    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)
예제 #8
0
    def get(self, request, *args, **kwargs):
        # `kwargs` will be used as `nav_param` so extract chcoll_oid from `kwargs` instead of creating param.

        # `chcoll_oid` may be misformatted.
        # If so, `safe_cast` will yield `None` while the original parameter needs to be kept for the case of not found.
        chcoll_oid_str = kwargs.get("chcoll_oid", "")
        chcoll_oid = safe_cast(chcoll_oid_str, ObjectId)

        chcoll_data: Optional[
            ChannelCollectionModel] = ChannelCollectionManager.get_chcoll_oid(
                chcoll_oid)

        if not chcoll_data:
            return WebsiteErrorView.website_error(
                request,
                WebsiteError.CHANNEL_COLLECTION_NOT_FOUND,
                {"chcoll_oid": chcoll_oid_str},
                nav_param=kwargs)

        msgdata_1d = MessageStatsDataProcessor.get_user_chcoll_messages(
            chcoll_data, hours_within=24)
        msgdata_7d = MessageStatsDataProcessor.get_user_chcoll_messages(
            chcoll_data, hours_within=168)

        return render_template(
            self.request,
            _("Channel Collection Info - {}").format(chcoll_oid),
            "info/chcoll/main.html", {
                "chcoll_data":
                chcoll_data,
                "chcoll_cch_data":
                InfoProcessor.collate_child_channel_data(
                    get_root_oid(request), chcoll_data.child_channel_oids),
                "user_message_data1d":
                msgdata_1d,
                "user_message_data7d":
                msgdata_7d
            },
            nav_param=kwargs)
예제 #9
0
    def get(self, request, *args, **kwargs):
        channel_data = self.get_channel_data(*args, **kwargs)

        # Check if the user is in the channel
        root_oid = get_root_oid(request)
        profs = ProfileManager.get_user_profiles(channel_data.model.id,
                                                 root_oid)
        if not profs or profs == ChannelProfileConnectionModel.ProfileOids.none_obj(
        ):
            return WebsiteErrorView.website_error(
                request,
                WebsiteError.NOT_IN_THE_CHANNEL,
                {"channel_oid": channel_data.oid_org},
                nav_param=kwargs)

        # Process the necessary data
        channel_name = channel_data.model.get_channel_name(root_oid)

        limit = get_limit(request.GET, Website.RecentActivity.MaxMessageCount)

        ctxt = {
            "channel_name":
            channel_name,
            "channel_data":
            channel_data.model,
            "recent_msg_limit":
            limit or "",
            "recent_msg_limit_max":
            Website.RecentActivity.MaxMessageCount,
            "recent_msg_data":
            MessageStatsDataProcessor.get_recent_messages(
                channel_data.model, limit)
        }

        return render_template(self.request,
                               _("Recent Messages - {}").format(channel_name),
                               "info/recent/message.html",
                               ctxt,
                               nav_param=kwargs)