Mercurial > p > roundup > code
diff 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 |
line wrap: on
line diff
--- a/test/db_test_base.py Sun May 05 20:57:11 2024 -0400 +++ b/test/db_test_base.py Mon May 06 00:49:43 2024 -0400 @@ -202,6 +202,7 @@ yield (filt_iter_list) return self.assertEqual, filter_test_iterator + def filteringSetupTransitiveSearch(self, classname='issue'): u_m = {} k = 30 @@ -1513,6 +1514,50 @@ # we should have the create and last set entries now self.assertEqual(jlen-1, len(self.db.getjournal('issue', id))) + def testCurrentUserLookup(self): + # admin is the default + f = self.db.user.lookup('@current_user') + self.assertEqual(f, "1") + + + self.db.journaltag = "fred" + f = self.db.user.lookup('@current_user') + self.assertEqual(f, "2") + + def testCurrentUserIssueFilterLink(self): + # admin is the default user + + for user in ['admin', 'fred']: + self.db.journaltag = user + for commit in (0,1): + nid = self.db.issue.create( + title="spam %s %s" % (user, commit), + status='1', + nosy=['2'] if commit else ['1']) + self.db.commit() + + self.db.journaltag = 'admin' + self.db.issue.set('3', status='2') + + f = self.db.issue.filter(None, {"creator": '@current_user'}) + self.assertEqual(f, ["1", "2"]) + + f = self.db.issue.filter(None, {"actor": '@current_user'}) + self.assertEqual(f, ["1", "2", "3"]) + + + self.db.journaltag = 'fred' + f = self.db.issue.filter(None, {"creator": '@current_user'}) + self.assertEqual(f, ["3", "4"]) + + # check not @current_user + f = self.db.issue.filter(None, {"creator": ['@current_user', '-2']}) + self.assertEqual(f, ["1", "2"]) + + # check different prop + f = self.db.issue.filter(None, {"actor": '@current_user'}) + self.assertEqual(f, ["4"]) + def testIndexerSearching(self): f1 = self.db.file.create(content='hello', type="text/plain") # content='world' has the wrong content-type and won't be indexed
