allura
Révision | 7d983c45fc37bf55b47172023c681dbf081caa88 (tree) |
---|---|
l'heure | 2012-07-17 19:09:48 |
Auteur | Igor Bondarenko <jetmind2@gmai...> |
Commiter | Igor Bondarenko |
[#4528] ticket:120 omit deleted projects in my_projects plus test
@@ -25,7 +25,7 @@ | ||
25 | 25 | <div class="project-list grid-18"> |
26 | 26 | <b>Projects</b> |
27 | 27 | <ul> |
28 | - {% for p in user.my_projects(exclude_deleted=True) %} | |
28 | + {% for p in user.my_projects() %} | |
29 | 29 | {% if h.has_access(p, 'read')() %} |
30 | 30 | <li> |
31 | 31 | <a class="project-name" href="{{p.url()}}">{{p.name}}</a> |
@@ -429,17 +429,16 @@ class User(MappedClass, ActivityNode, ActivityObject): | ||
429 | 429 | def script_name(self): |
430 | 430 | return '/u/' + self.username + '/' |
431 | 431 | |
432 | - def my_projects(self, exclude_deleted=False): | |
432 | + def my_projects(self): | |
433 | 433 | '''Find the projects for which this user has a named role.''' |
434 | 434 | reaching_role_ids = g.credentials.user_roles(user_id=self._id).reaching_ids_set |
435 | 435 | reaching_roles = [ ProjectRole.query.get(_id=i) for i in reaching_role_ids ] |
436 | - named_roles = [ r for r in reaching_roles if r.name ] | |
436 | + named_roles = [ r for r in reaching_roles | |
437 | + if r.name and not r.project.deleted ] | |
437 | 438 | seen_project_ids = set() |
438 | 439 | for r in named_roles: |
439 | 440 | if r.project_id in seen_project_ids: continue |
440 | 441 | seen_project_ids.add(r.project_id) |
441 | - if exclude_deleted and r.project.deleted: | |
442 | - continue | |
443 | 442 | yield r.project |
444 | 443 | |
445 | 444 | def project_role(self, project=None): |
@@ -64,6 +64,10 @@ def test_user(): | ||
64 | 64 | assert c.user.url() .endswith('/u/test-admin/') |
65 | 65 | assert c.user.script_name .endswith('/u/test-admin/') |
66 | 66 | assert set(p.shortname for p in c.user.my_projects()) == set(['test', 'test2', 'u/test-admin', 'adobe-1', '--init--']) |
67 | + # delete one of projects and make sure it's don't appear in my_projects() | |
68 | + p = M.Project.query.get(shortname='test2') | |
69 | + p.deleted = True | |
70 | + assert set(p.shortname for p in c.user.my_projects()) == set(['test', 'u/test-admin', 'adobe-1', '--init--']) | |
67 | 71 | assert M.User.anonymous().project_role().name == '*anonymous' |
68 | 72 | u = M.User.register(dict( |
69 | 73 | username='nosetest-user')) |