ProtectedMacro 㧠!protected é¨åã®è¡¨ç¤ºã« WIKI_MODIFY ãå¿ é ã«ããããã
ä»ã®ããã¸ã§ã¯ãã§ä½¿ã£ã¦ãã Trac ã¯ãanonymous ã«ãã¹ã¦ã® VIEW 権éãä¸ãã¦ãã¾ãã社å ã®ããã¸ã§ã¯ãéã§ãã¦ãã¦ãå ±æã§ããããã«ãã®ãããªå½¢ã«ãã¦ããã®ã§ããããµã¼ãã®ãã°ã¤ã³ãã¹ã¯ã¼ãçã¯ããã¸ã§ã¯ãå¤ã®äººã«ã¯ç¥ããããããã¾ããã
ãã®ãããªå ´åã«ä½¿ããããªãã¯ããæ¢ãã¦ã¿ãã¨ãProtectedMacro 㨠AccessMacro ã¨ãããã®ãè¦ã¤ããã¾ããããããã Wiki ã®ä¸é¨ã®é åã«é²è¦§å¶éãããããã¨ãã§ãããã©ã°ã¤ã³ã§ããã
- ProtectedMacro ã®ã»ã㯠unauthorized user åãã®ã¡ãã»ã¼ã¸ãè¨å®ã§ãã
- AccessMacro ã®ã»ãã¯ãã¼ããã·ã§ã³ããã詳細ã«è¨å®ã§ããããä»åããã¾ã§ã®æ©è½ã¯å¿ è¦ãªã
ã¨ãããã¨ã§ãProtectedMacro ã®ã»ãã試ãã¦ã¿ã¾ããã
ã¤ã³ã¹ãã¼ã«
æ®éã«ã¤ã³ã¹ãã¼ã«ã§ãã¾ããä¸å¿ããã£ã¨æé ãæ¸ãã¦ããã¨ã
- .zip ããã¦ã³ãã¼ããã¦è§£å
- python setup.py bdist_egg
- su easy_install dist/*
- Apache åèµ·å
ã¨ããæãã§ãã
権éã«ã¤ãã¦ã¯
- PROTECTED_VIEW
- PROTECTED_RED_VIEW
- PROTECTED_BLUE_VIEW
- PROTECTED_GREEN_VIEW
ã® 4 ã¤ããã£ã¦ããããã
- !protected
- !protected-red
- !protected-blue
- !protected-green
ã¨ãªã£ã¦ãããã£ã¼ã«ããè¦ãï¼æ·»ä»ãã¡ã¤ã«ãè¦ãããã®æ¨©éã«ãªã£ã¦ãã¾ããTRAC_ADMIN ã§ããã°å ¨é¨è¦ããã¨ãã§ããããã§ãã
試ãã¦ã¿ã
Wiki ä¸ã«
{{{ #!protected #:ãã°ã¤ã³ã¦ã¼ã¶ã®ã¿é²è¦§ã§ãã¾ã * id: ****** * pass: ****** }}}
>
ã¨æ¸ãã¦ããã¨ã
- PROTECTED_VIEW 権éããªãå ´å
- PROTECTED_VIEW 権éãããå ´å
ã®ããã«è¡¨ç¤ºããããã¨ãããæãã§ããã
åé¡ç¹
é²è¦§ããå ´åã¯ä¸è¨ã®ããã«ãã¾ãæ©è½ããã®ã§ãããç·¨éç»é¢ã§ã¯ PROTECTED_VIEW 権éããªãã¦ã !protected ãªé åãè¦ãã¦ãã¾ãã¾ããä»å㯠PROTECTED_VIEW 権éããªãã¦ã¼ã¶ï¼WIKI_MODIFY 権éããªãã¦ã¼ã¶ãªã®ã§åé¡ãªãã¾ããããããã¸ã§ã¯ãã«ãã£ã¦ã¯åé¡ã«ãªãããããã¾ããã
ä¸è¨ã¯ããããä»æ§ã¨ãããã¨ã§ãããã§ãããããä¸ã¤åé¡ãããã¾ãã¦ãWiki ã®å±¥æ´ãã diff ãè¦ãã¨ãPROTECTED_VIEW 権éããªãã¦ã !protected ãªé åãè¦ãã¦ãã¾ãã¾ããdiff ãè¦ãããã®æ¨©éï¼WIKI_DIFF ã¿ãããªï¼ãå¥ã«ãã£ã¦ããã§å¶å¾¡ã§ããã°ãããã§ãããdiff ã«å¿ è¦ãªæ¨©é㯠WIKI_VIEW ãªã®ã§ãããã§ã¯å¶å¾¡ã§ãã¾ããã
ãã°å ±åããã¦ããããããããã£ã¦ããããªãããªï¼ã¨è¦ã¦ã¿ãã¨ã
ããã«ãç°ãªããã©ã¼ãããã§ãã¦ã³ãã¼ããã§ããã¹ãããã¦ã³ãã¼ãããå ´åãåæ§ã®åé¡ãããï¼ãã¡ãã権éã§ã¯å¶å¾¡ã§ããªãï¼ã¨ã®ãã¨ãããã¦ãããã¯ããã£ã¦ããªããã¨ã
ã¾ãã£ããä»æ§ãç ´ç¶»ãã¦ããæããªã®ã§ãã¨ãããããã£ãã®ãã±ããã«ãdiff ã§ãè¦ãã¡ããããã¨ã³ã¡ã³ãã追å ã㦠ProtectedMacro ã¯å¿ãããã¨ã«ã
AccessMacro ã試ãï¼
ã§ãããã²ã¨ã¤ã®ãã©ã°ã¤ã³ AccessMacro ã®ã»ãã試ãã¦ã¿ããã¨ãã¦ããã¾ãããã£ã¡ã«ãåãåé¡ãããã®ã§ã¯ã»ã»ã»ãã¨å ã«ãã±ãããè¦ã¦ã¿ãã¨ã»ã»ã»ããã¾ããã
ãã¡ãã®ãã±ããã«ã¯ãããã¯ããã£ã¦ãã¦ã»ã»ã»åãæ¹æ³ã§ ProtectedMacro ã対å¿ã§ããããªæ°ããã¾ãã
ãã ãã®ããã㯠Trac æ¬ä½ã«æãå ¥ããããæ¹ã®ããã§ã»ã»ã»ä»ã® Trac ã¯ç§ã管çè ãããªãã®ã§ãããã¯é¿ãããã§ããã§ããã©ã°ã¤ã³å´ã§ãã¾ããã¨ã§ããªãããªã¼ï¼ã¨èª¿ã¹ã¦ã¿ãã¨ããªãã¨ããªãããã ã£ãã®ã§ ProtectedMacro ã®ããããä½ã£ã¦ã¿ã¾ããã
ãããã®å 容
WIKI_MODIFY 権éããªã㨠diff ãããã¹ãã®ãã¦ã³ãã¼ããè¡ããªããããã®ã§ããdiff ã wiki è¨è¿°ãèªããªãã®ã¯å°ãçãã®ã§ããããã¹ã¯ã¼ãçã®æ å ±ãããã¸ã§ã¯ãå¤ã«æ¼ãã or ããã¸ã§ã¯ãã§å ±æããã¦ããªããªã¹ã¯ã«æ¯ã¹ãã°ãã·ããªã¨ã
å¦çã¨ãã¦ã¯ãtrac/wiki/web_ui.py ã« AccessMacro ã®ãã±ããã«ããã£ã¦ããããããå½ã¦ã¦ãå¿ è¦ãªå¦çï¼åå²ã ãæãåºãã¦ãIRequestFilter ã® pre_process_request ã§å¦çãã¦ããã ãã§ãããã¯ãã§ããªãã®ã« macro.py ã«å ¥ãã¡ãã£ã¦ã¾ãããã¾ã IPermissionPolicy ãå ã å ¥ã£ã¦ãããã»ã»ã»åé¡ãªãããããªãããªã¨ã
Index: macro.py =================================================================== --- macro.py (revision 6673) +++ macro.py (working copy) @@ -2,8 +2,10 @@ from trac.attachment import Attachment from trac.core import * from trac.perm import IPermissionRequestor, IPermissionPolicy +from trac.web.api import IRequestFilter from trac.wiki.api import IWikiMacroProvider from trac.wiki.formatter import format_to_html +from trac.wiki.model import WikiPage LEVELS = {"protected":{"action":"PROTECTED_VIEW", "style":"border-left:2px solid red; padding-left:3px"}, "protected-red":{"action":"PROTECTED_RED_VIEW", "style":"border-left:2px solid red; padding-left:3px"}, @@ -100,4 +102,40 @@ # IPermissionRequestor, def get_permission_actions(self): return [level["action"] for level in LEVELS.values()] - + +class ProtectedFilter(Component): + implements(IRequestFilter) + + # IRequestFilter + def pre_process_request(self, req, handler): + action = req.args.get('action', 'view') + pagename = req.args.get('page', 'WikiStart') + + if pagename.endswith('/'): + req.redirect(req.href.wiki(pagename.strip('/'))) + + page = WikiPage(self.env, pagename) + + if req.method == 'POST': + pass + elif action == 'delete': + pass + elif action == 'edit': + pass + elif action == 'diff': + if page.exists: + req.perm(page.resource).require('WIKI_MODIFY') + else: + format = req.args.get('format') + if format: + req.perm(page.resource).require('WIKI_MODIFY') + + return handler + + # IRequestFilter + def post_process_request(self, req, template, content_type): + return (template, content_type) + + # IRequestFilter + def post_process_request(self, req, template, data, content_type): + return (template, data, content_type)
ããã㯠さきほどのチケット ã«ãæ·»ä»ãã¦ããã®ã§ãæ¬å½ã¯ãã¡ãã使ã£ã¦ããã ããã»ãããããã§ããã»ã»ã»ãã±ããã«æ·»ä»ããã»ãã¯ãããã°ã³ã¼ãæ¶ãã®å¿ãã¦ããã®ã§ãããããå½ã¦ãæ¹ã¯ãã®é¨åãæ¶ãã¦ãã使ã£ã¦ãã ããããã¾ã«ãã£ã¡ãããã©ãããããã®ã¯æ¥ãããããªãã
ãã¨ãæ·»ä»ãã¡ã¤ã«ã®ã»ãã¯ä»å試ãã¦ãã¾ããã®ã§ãåä½ã«åé¡ãªããã¨ã確èªããããã§ãå©ç¨ãã ããã
ï¼2009-10-13 追è¨ï¼
æ¤ç´¢ããã¨ãã plain text ãè¦ãã¡ããã¾ããã»ã»ã»ãã²ã¨ã¾ã SEARCH_VIEW ã¯ããã¦å¯¾å¿ãã¦ãã¾ãã
ï¼2010-08-13 追è¨ï¼
2010-02-17 ãããã«ãããé©ç¨ããã¦ãã¿ããã§ããå ¬å¼ã®ææ°çã使ã£ã¦ããã ãå½¢ã§åé¡ãªããã¨ã