7 |
7 |
8 from logilab.common.testlib import TestCase, unittest_main |
8 from logilab.common.testlib import TestCase, unittest_main |
9 |
9 |
10 from cubicweb.devtools.testlib import EnvBasedTC |
10 from cubicweb.devtools.testlib import EnvBasedTC |
11 from cubicweb.vregistry import Selector, AndSelector, OrSelector |
11 from cubicweb.vregistry import Selector, AndSelector, OrSelector |
12 from cubicweb.selectors import implements |
12 from cubicweb.selectors import implements, match_user_groups |
13 from cubicweb.interfaces import IDownloadable |
13 from cubicweb.interfaces import IDownloadable |
14 from cubicweb.web import action |
14 from cubicweb.web import action |
15 |
15 |
16 class _1_(Selector): |
16 class _1_(Selector): |
17 def __call__(self, *args, **kwargs): |
17 def __call__(self, *args, **kwargs): |
107 """tests usage of 'owners' group with match_user_group""" |
107 """tests usage of 'owners' group with match_user_group""" |
108 class SomeAction(action.Action): |
108 class SomeAction(action.Action): |
109 id = 'yo' |
109 id = 'yo' |
110 category = 'foo' |
110 category = 'foo' |
111 __select__ = match_user_groups('owners') |
111 __select__ = match_user_groups('owners') |
|
112 self.vreg._loadedmods[__name__] = {} |
112 self.vreg.register_vobject_class(SomeAction) |
113 self.vreg.register_vobject_class(SomeAction) |
113 self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions']) |
114 self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions']) |
114 try: |
115 try: |
115 # login as a simple user |
116 # login as a simple user |
116 self.create_user('john') |
117 self.create_user('john') |
117 self.login('john') |
118 self.login('john') |
118 # it should not be possible to use SomeAction not owned objects |
119 # it should not be possible to use SomeAction not owned objects |
119 rset, req = self.env.get_rset_and_req('Any G WHERE G is CWGroup, G name "managers"') |
120 rset, req = self.env.get_rset_and_req('Any G WHERE G is CWGroup, G name "managers"') |
120 self.failIf('foo' in self.pactions(req, rset)) |
121 self.failIf('yo' in dict(self.pactions(req, rset))) |
121 # insert a new card, and check that we can use SomeAction on our object |
122 # insert a new card, and check that we can use SomeAction on our object |
122 self.execute('INSERT Card C: C title "zoubidou"') |
123 self.execute('INSERT Card C: C title "zoubidou"') |
123 self.commit() |
124 self.commit() |
124 rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
125 rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
125 self.failUnless('foo' in self.pactions(req, rset)) |
126 self.failUnless('yo' in dict(self.pactions(req, rset)), self.pactions(req, rset)) |
126 # make sure even managers can't use the action |
127 # make sure even managers can't use the action |
127 self.restore_connection() |
128 self.restore_connection() |
128 rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
129 rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
129 self.failIf('foo' in self.pactions(req, rset)) |
130 self.failIf('yo' in dict(self.pactions(req, rset))) |
130 finally: |
131 finally: |
131 del self.vreg[SomeAction.__registry__][SomeAction.id] |
132 del self.vreg[SomeAction.__registry__][SomeAction.id] |
132 |
133 |
133 if __name__ == '__main__': |
134 if __name__ == '__main__': |
134 unittest_main() |
135 unittest_main() |