Пример #1
0
    def render_admin_panel(self, req, cat, page, path_info):
        """ Renders announcements admin panel
        """
        req.perm.require('TRAC_ADMIN')

        showforum = self.config.getbool('discussion', 'show_news_forum', True)

        project = Project.get(self.env)
        groupstore = CQDEUserGroupStore(project.trac_environment_key)
        (public_exists, allowed) = self.get_announce_allowed(groupstore)

        if req.method == 'POST':
            if 'hideforum' in req.args:
                self.config.set('discussion', 'show_news_forum', 'false')
                self.config.save()
                showforum = False
                # Notify listeners
                for listener in self.announcement_admin_listeners:
                    listener.announcements_hidden()
            elif 'showforum' in req.args:
                self.config.set('discussion', 'show_news_forum', 'true')
                self.config.save()
                showforum = True
                # Notify listeners
                for listener in self.announcement_admin_listeners:
                    listener.announcements_visible()
            elif 'allow' in req.args:
                #Allow should add the DISCUSSION_ANNOUNCE_APPEND to the "public contributors" group.
                groupstore.grant_permission_to_group(
                    "Public contributors", "DISCUSSION_ANNOUNCEAPPEND")
                (public_exists,
                 allowed) = self.get_announce_allowed(groupstore)
            elif 'disallow' in req.args:
                #Disallow remove it.
                groupstore.revoke_permission_from_group(
                    "Public contributors", "DISCUSSION_ANNOUNCEAPPEND")
                (public_exists,
                 allowed) = self.get_announce_allowed(groupstore)
            elif 'rename' in req.args:
                news = ProjectNews(project.env_name)
                news.rename_news_forum(req.args.get('forumname'))

        data = {}
        data['showforum'] = showforum
        data['allowed'] = allowed
        data['public_exists'] = public_exists
        return 'admin_news_forum.html', data
Пример #2
0
    def render_admin_panel(self, req, cat, page, path_info):
        """ Renders announcements admin panel
        """
        req.perm.require('TRAC_ADMIN')

        showforum = self.config.getbool('discussion', 'show_news_forum', True)

        project = Project.get(self.env)
        groupstore = CQDEUserGroupStore(project.trac_environment_key)
        (public_exists, allowed) = self.get_announce_allowed(groupstore)

        if req.method == 'POST':
            if 'hideforum' in req.args:
                self.config.set('discussion', 'show_news_forum', 'false')
                self.config.save()
                showforum = False
                # Notify listeners
                for listener in self.announcement_admin_listeners:
                    listener.announcements_hidden()
            elif 'showforum' in req.args:
                self.config.set('discussion', 'show_news_forum', 'true')
                self.config.save()
                showforum = True
                # Notify listeners
                for listener in self.announcement_admin_listeners:
                    listener.announcements_visible()
            elif 'allow' in req.args:
                #Allow should add the DISCUSSION_ANNOUNCE_APPEND to the "public contributors" group.
                groupstore.grant_permission_to_group("Public contributors", "DISCUSSION_ANNOUNCEAPPEND")
                (public_exists, allowed) = self.get_announce_allowed(groupstore)
            elif 'disallow' in req.args:
                #Disallow remove it.
                groupstore.revoke_permission_from_group("Public contributors", "DISCUSSION_ANNOUNCEAPPEND")
                (public_exists, allowed) = self.get_announce_allowed(groupstore)
            elif 'rename' in req.args:
                news = ProjectNews(project.env_name)
                news.rename_news_forum(req.args.get('forumname'))

        data = {}
        data['showforum'] = showforum
        data['allowed'] = allowed
        data['public_exists'] = public_exists
        return 'admin_news_forum.html', data
Пример #3
0
    def expand_macro(self, formatter, name, content, args=None):
        """
        Expand the macro. We will accept a parameter to point us to another project
        if necessary.
        """

        if name != "Announcements":
            return None

        data = {}
        req = formatter.req

        env_name = None
        count = 0
        title = None
        env = None

        # Parse settings for the macro
        env_name, count, title = self._parse_args(args, content)

        if not count:
            self.log.debug("Defaulting count to 5")
            count = 5

        data["news_title"] = title
        current_env_name = self.env.project_identifier

        if not env_name:
            env_name = current_env_name

        data["env_name"] = env_name

        # Check if the project exists.
        mpp_env = None
        try:
            mpp_env = TracEnvironment.read(env_name)
        except TracError:
            data["news_error"] = "Couldn't find project '{0}'".format(env_name)
            self.log.error(data["news_error"])

        # Then check the permissions
        if mpp_env:
            # Check if project's announcements have been configured as hidden
            if env_name != current_env_name:
                env = open_environment(
                    os.path.join(self.config.get("multiproject", "sys_projects_root"), env_name), use_cache=True
                )
            else:
                env = self.env

            if not env.config.getbool("discussion", "show_news_forum", True):
                self.log.debug("Project announcements hidden, not showing with macro")
                return None

            # Check permission in specified environment
            permcache = PermissionCache(env, username=req.authname)
            if "DISCUSSION_VIEW" in permcache:
                try:
                    news = ProjectNews(env_name)
                    data["newsitems"] = news.get_project_news(limit=count, f_name="Announcements")
                    data["news_forum_id"] = news.get_news_forum_id()
                except Exception, e:
                    self.log.exception("Failed to read project {0} news.".format(env_name))
                    raise TracError("Couldn't read news for project '{0}': {1}".format(env_name, e))
            else:
                data["news_error"] = "No permission to read news from project '{0}'".format(env_name)
Пример #4
0
    def expand_macro(self, formatter, name, content, args=None):
        """
        Expand the macro. We will accept a parameter to point us to another project
        if necessary.
        """

        if name != 'Announcements':
            return None

        data = {}
        req = formatter.req

        env_name = None
        count = 0
        title = None
        env = None

        # Parse settings for the macro
        env_name, count, title = self._parse_args(args, content)

        if not count:
            self.log.debug("Defaulting count to 5")
            count = 5

        data['news_title'] = title
        current_env_name = self.env.project_identifier

        if not env_name:
            env_name = current_env_name

        data['env_name'] = env_name

        # Check if the project exists.
        mpp_env = None
        try:
            mpp_env = TracEnvironment.read(env_name)
        except TracError:
            data['news_error'] = "Couldn't find project '{0}'".format(env_name)
            self.log.error(data['news_error'])

        # Then check the permissions
        if mpp_env:
            # Check if project's announcements have been configured as hidden
            if env_name != current_env_name:
                env = open_environment(os.path.join(
                    self.config.get('multiproject', 'sys_projects_root'),
                    env_name),
                                       use_cache=True)
            else:
                env = self.env

            if not env.config.getbool('discussion', 'show_news_forum', True):
                self.log.debug(
                    "Project announcements hidden, not showing with macro")
                return None

            # Check permission in specified environment
            permcache = PermissionCache(env, username=req.authname)
            if 'DISCUSSION_VIEW' in permcache:
                try:
                    news = ProjectNews(env_name)
                    data['newsitems'] = news.get_project_news(
                        limit=count, f_name="Announcements")
                    data['news_forum_id'] = news.get_news_forum_id()
                except Exception, e:
                    self.log.exception(
                        "Failed to read project {0} news.".format(env_name))
                    raise TracError(
                        "Couldn't read news for project '{0}': {1}".format(
                            env_name, e))
            else:
                data[
                    'news_error'] = "No permission to read news from project '{0}'".format(
                        env_name)