Mercurial > p > roundup > code
comparison test/db_test_base.py @ 7936:a9b136565838
feat: issue1525113 - notation to filter by logged-in user
At long last (almost 18 years) this patch lands. It allows sharing of
queries that want to use the currently logged in user (i.e. I or me).
By replacing an id number for the user by '@current_user' in the query
you can share the query for "my issues" where 'my' is the logged in
user not the person who created the query.
Updated the templates to use this.
Updated upgrading.py for directions on using it.
RDBMS and anydbm both work. Also expressions using it (e.g. not
@current_user) work and are tested.
Test code done.
I am not sure what the change to templating.py does. I am following
the original patch and have built a test case to hit the if
clause. But the rest of the test doesn't actualy provide the props I
need. If I knew what that code was supposed to do there I would create
a real test.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 06 May 2024 00:49:43 -0400 |
| parents | ecf0368a05da |
| children | c12377fb4144 |
comparison
equal
deleted
inserted
replaced
| 7935:f670446b5e50 | 7936:a9b136565838 |
|---|---|
| 199 yield (filt_iter_list) | 199 yield (filt_iter_list) |
| 200 self.db.config.RDBMS_SERVERSIDE_CURSOR = True | 200 self.db.config.RDBMS_SERVERSIDE_CURSOR = True |
| 201 yield (cls.filter) | 201 yield (cls.filter) |
| 202 yield (filt_iter_list) | 202 yield (filt_iter_list) |
| 203 return self.assertEqual, filter_test_iterator | 203 return self.assertEqual, filter_test_iterator |
| 204 | |
| 204 | 205 |
| 205 def filteringSetupTransitiveSearch(self, classname='issue'): | 206 def filteringSetupTransitiveSearch(self, classname='issue'): |
| 206 u_m = {} | 207 u_m = {} |
| 207 k = 30 | 208 k = 30 |
| 208 for user in ( | 209 for user in ( |
| 1510 # pack | 1511 # pack |
| 1511 self.db.pack(pack_before) | 1512 self.db.pack(pack_before) |
| 1512 | 1513 |
| 1513 # we should have the create and last set entries now | 1514 # we should have the create and last set entries now |
| 1514 self.assertEqual(jlen-1, len(self.db.getjournal('issue', id))) | 1515 self.assertEqual(jlen-1, len(self.db.getjournal('issue', id))) |
| 1516 | |
| 1517 def testCurrentUserLookup(self): | |
| 1518 # admin is the default | |
| 1519 f = self.db.user.lookup('@current_user') | |
| 1520 self.assertEqual(f, "1") | |
| 1521 | |
| 1522 | |
| 1523 self.db.journaltag = "fred" | |
| 1524 f = self.db.user.lookup('@current_user') | |
| 1525 self.assertEqual(f, "2") | |
| 1526 | |
| 1527 def testCurrentUserIssueFilterLink(self): | |
| 1528 # admin is the default user | |
| 1529 | |
| 1530 for user in ['admin', 'fred']: | |
| 1531 self.db.journaltag = user | |
| 1532 for commit in (0,1): | |
| 1533 nid = self.db.issue.create( | |
| 1534 title="spam %s %s" % (user, commit), | |
| 1535 status='1', | |
| 1536 nosy=['2'] if commit else ['1']) | |
| 1537 self.db.commit() | |
| 1538 | |
| 1539 self.db.journaltag = 'admin' | |
| 1540 self.db.issue.set('3', status='2') | |
| 1541 | |
| 1542 f = self.db.issue.filter(None, {"creator": '@current_user'}) | |
| 1543 self.assertEqual(f, ["1", "2"]) | |
| 1544 | |
| 1545 f = self.db.issue.filter(None, {"actor": '@current_user'}) | |
| 1546 self.assertEqual(f, ["1", "2", "3"]) | |
| 1547 | |
| 1548 | |
| 1549 self.db.journaltag = 'fred' | |
| 1550 f = self.db.issue.filter(None, {"creator": '@current_user'}) | |
| 1551 self.assertEqual(f, ["3", "4"]) | |
| 1552 | |
| 1553 # check not @current_user | |
| 1554 f = self.db.issue.filter(None, {"creator": ['@current_user', '-2']}) | |
| 1555 self.assertEqual(f, ["1", "2"]) | |
| 1556 | |
| 1557 # check different prop | |
| 1558 f = self.db.issue.filter(None, {"actor": '@current_user'}) | |
| 1559 self.assertEqual(f, ["4"]) | |
| 1515 | 1560 |
| 1516 def testIndexerSearching(self): | 1561 def testIndexerSearching(self): |
| 1517 f1 = self.db.file.create(content='hello', type="text/plain") | 1562 f1 = self.db.file.create(content='hello', type="text/plain") |
| 1518 # content='world' has the wrong content-type and won't be indexed | 1563 # content='world' has the wrong content-type and won't be indexed |
| 1519 f2 = self.db.file.create(content='world', type="text/frozz", | 1564 f2 = self.db.file.create(content='world', type="text/frozz", |
