天天看點

修改Viewvc代碼使隻讀權限的使用者隻能檢視log

弄了近3天(這個周末是totally進去咯),總算把viewvc修改成隻讀權限(這裡說的隻讀權限是指svnauthz中配置為隻讀權限)的使用者隻能檢視log了 O(∩_∩)O哈哈~

太累了,先發貼占個位子,等幾天把代碼及修改的詳細地方貼出來~~

O(∩_∩)O哈哈~

主要是在viewvc.py中增加兩個viewvc現成的函數_process_access_section(self,  cp,  section)

_userspec_matches_user(self,  userspec):

然後在class Request:

  def __init__(self, server, cfg):

函數中,在獲得了USERNAME後面,加上下面的語句:

(說起這幾句話簡單,就是把diff,annotate,markup 三種view從cfg中去掉,不曉得我看了好久的代碼才找到是該在這個位置裡添加!沁透了我的汗水啊~~~~兄弟們,給我頂~~~↖(^ω^)↗):

#Brant

        logging.basicConfig(level=logging.DEBUG,

                                        format='%(asctime)s %(levelname)s %(message)s',

                                        filename='D:/Viewvc.Request.log',

                                        filemode='w')

        logging.debug('A debug message1')        

        cp1 = ConfigParser()

        cp1.read(self.cfg.conf_path) # Read viewvc.conf

        svnauthzfile = cp1.get("authz-svnauthz", "authzfile") # get svnauthzfile frmo viewvc.conf

        cp = ConfigParser()

        cp.read(svnauthzfile) # Read svnauthzfile

        root_sections = []

        no_diff_annonate_markup_view = 0

        logging.debug('below:cp.sections')        

        logging.debug(cp.sections())        

        for section in cp.sections():                

                logging.debug('A debug message5')

            # Skip the "groups" section -- we handled that already.

                if section == 'groups':

                        continue

                if section == 'aliases':

                no_diff_annonate_markup_view = _process_access_section(self,    cp,    section)

                logging.debug('after1 cp.sections[%s] haha:%d',    section,    no_diff_annonate_markup_view)

        logging.debug('ooo view_result:%d',    no_diff_annonate_markup_view)

        logging.debug(self.cfg.options.allowed_views)

        if no_diff_annonate_markup_view == 1:

                if 'diff' in self.cfg.options.allowed_views:

                        self.cfg.options.allowed_views.remove('diff');

                if 'markup' in self.cfg.options.allowed_views:

                        self.cfg.options.allowed_views.remove('markup');

                if 'annotate' in self.cfg.options.allowed_views:

                        self.cfg.options.allowed_views.remove('annotate');

                if 'diff' in cfg.options.allowed_views:

                        cfg.options.allowed_views.remove('diff');

                if 'markup' in cfg.options.allowed_views:

                        cfg.options.allowed_views.remove('markup');

                if 'annotate' in cfg.options.allowed_views:

                        cfg.options.allowed_views.remove('annotate');

其他的工作就是修改下viewcv的模闆。等幾天再寫吧,O(∩_∩)O哈哈~

PS幾句:

偶從來沒想過會用python這個後起新秀,更别說學習它了!更别說修改一個用它寫的開源工具了!

可是這周末沒想到鬼使神差地硬把Viewvc按照我的需求給改了!

我都覺得我瘋了~~

不過看到自己成果後,還是爽翻了O(∩_∩)O哈哈~

本文轉自 xkdcc 51CTO部落格,原文連結:http://blog.51cto.com/brantc/213780,如需轉載請自行聯系原作者