Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Search: made the /projects show more projects
Browse files Browse the repository at this point in the history
`/projects` request provides more projects related with the user including
all public projects, proteced projects of the gourps of the user joined in,
and the private projects of the user joined in.
  • Loading branch information
Keesun Baik committed Aug 20, 2014
1 parent d921ca8 commit 2e70827
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 16 additions & 2 deletions app/controllers/ProjectApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package controllers;

import actions.DefaultProjectCheckAction;
import com.avaje.ebean.Expr;
import com.avaje.ebean.ExpressionList;
import com.avaje.ebean.Junction;
import com.avaje.ebean.Page;
Expand Down Expand Up @@ -980,8 +981,21 @@ private static ExpressionList<Project> createProjectSearchExpressionList(String
junction.endJunction();
}

if (!UserApp.currentUser().isSiteManager()) {
el.eq("projectScope", ProjectScope.PUBLIC);
User user = UserApp.currentUser();
if (!user.isSiteManager()) {
if(user.isAnonymous()) {
el.eq("projectScope", ProjectScope.PUBLIC);
} else {
Junction<Project> junction = el.conjunction();
Junction<Project> pj = junction.disjunction();
pj.add(Expr.eq("projectScope", ProjectScope.PUBLIC)); // public
List<Organization> orgs = Organization.findOrganizationsByUserLoginId(user.loginId); // protected
if(!orgs.isEmpty()) {
pj.and(Expr.in("organization", orgs), Expr.eq("projectScope", ProjectScope.PROTECTED));
}
pj.add(Expr.eq("projectUser.user.id", user.id)); // private
pj.endJunction();
}
}

return el;
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/ProjectAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,25 +271,25 @@ public void adminCanSearchPublicProjectsAsJson() {
}

@Test
public void memberCannotSearchPrivateProjects() {
public void memberCanSearchPrivateProjects() {
// Given
User member = User.find.byId(3L);
Project project = Project.findByOwnerAndProjectName("laziel", "Jindo");

// When
// Then
testProjectSearch(member, project, acceptHtml, doesNotContains(routes.ProjectApp.project(project.owner,project.name).url()));
testProjectSearch(member, project, acceptHtml, contains(routes.ProjectApp.project(project.owner,project.name).url()));
}

@Test
public void memberCannotSearchPrivateProjectsAsJson() {
public void memberCanSearchPrivateProjectsAsJson() {
// Given
User member = User.find.byId(3L);
Project project = Project.findByOwnerAndProjectName("laziel", "Jindo");

// When
// Then
testProjectSearch(member, project, acceptJson, doesNotContains(project.owner + "/" + project.name));
testProjectSearch(member, project, acceptJson, contains(project.owner + "/" + project.name));
}

@Test
Expand Down

0 comments on commit 2e70827

Please sign in to comment.