doortts doortts 2017-03-07
project-list: Fix wrong total page indicator
See: Yona Github issue #66
@6b1ea06f72157a20ef2fbc8900351dc2f491bcb5
app/assets/stylesheets/less/_page.less
--- app/assets/stylesheets/less/_page.less
+++ app/assets/stylesheets/less/_page.less
@@ -1646,8 +1646,7 @@
     clear:both;
     // -- project list -- //
     .project {
-        margin: 5px 0px; /*5px 20px;*/
-        padding: 10px 0px;
+        padding: 15px 0 10px 0;
         overflow: hidden;
         border-bottom: 1px solid #DCDCDC;
         .info-wrap {
app/controllers/ProjectApp.java
--- app/controllers/ProjectApp.java
+++ app/controllers/ProjectApp.java
@@ -987,6 +987,9 @@
     }
 
     private static Result getPagingProjects(String query, int pageNum) {
+        if (pageNum < 1) {
+            return notFound(ErrorViews.NotFound.render("error.notfound"));
+        }
         ExpressionList<Project> el = createProjectSearchExpressionList(query);
 
         Set<Long> labelIds = LabelApp.getLabelIds(request());
@@ -995,9 +998,16 @@
         }
 
         el.orderBy("createdDate desc");
-        Page<Project> projects = el.findPagingList(PROJECT_COUNT_PER_PAGE).getPage(pageNum - 1);
+        Page<Project> projects = getProjectPage(pageNum, el);
+        if (projects.getList().size() == 0) {
+            return notFound(ErrorViews.NotFound.render("error.notfound"));
+        }
 
         return ok(views.html.project.list.render("title.projectList", projects, query));
+    }
+
+    private static Page<Project> getProjectPage(int pageNum, ExpressionList<Project> el) {
+        return el.findPagingList(PROJECT_COUNT_PER_PAGE).getPage(pageNum - 1);
     }
 
     private static Result getProjectsToJSON(String query) {
@@ -1033,20 +1043,8 @@
         }
 
         User user = UserApp.currentUser();
-        if (!user.isSiteManager() && !Config.getDisplayPrivateRepositories()) {
-            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();
-            }
+        if (!user.isSiteManager() && !Config.displayPrivateRepositories()) {
+            el.eq("projectScope", ProjectScope.PUBLIC);
         }
 
         return el;
app/utils/Config.java
--- app/utils/Config.java
+++ app/utils/Config.java
@@ -295,7 +295,7 @@
         return System.getProperty(YONA_DATA, defaultValue);
     }
 
-    public static boolean getDisplayPrivateRepositories() {
+    public static boolean displayPrivateRepositories() {
         return Configuration.root().getBoolean("application.displayPrivateRepositories", Boolean.FALSE);
     }
 }
app/views/project/list.scala.html
--- app/views/project/list.scala.html
+++ app/views/project/list.scala.html
@@ -18,6 +18,9 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **@
+@import utils.Config
+@import utils.AccessControl
+@import models.enumeration.Operation;
 @(message: String, currentPage: com.avaje.ebean.Page[Project], filter:String)
 @import utils.TemplateHelper._
 @import utils.JodaDateUtil
@@ -25,7 +28,7 @@
 @siteLayout(message, utils.MenuType.PROJECTS) {
 <div class="site-breadcrumb-outer">
     <div class="site-breadcrumb-inner">
-        <h3>@Messages("title.projectList")</h3>
+        <h3>@Messages("project.public") @Messages("title.projectList")</h3>
     </div>
 </div>
 <div class="page-wrap-outer">
@@ -42,6 +45,7 @@
         </div>
     	<ul class="all-projects">
         @for(project <- currentPage.getList) {
+            @if(Config.displayPrivateRepositories() || AccessControl.isAllowed(UserApp.currentUser(), project.asResource(), Operation.READ)){
             <li class="project">
                 <div class="info-wrap">
                     <div class="owner-avatar-wrap">
@@ -94,6 +98,18 @@
                     }
                 </div>
             </li>
+            } else {
+                <li class="project" style="background-color: #fcfcfc;">
+                    <div class="info-wrap" style="opacity: 0.3">
+                        <div class="owner-avatar-wrap">
+                            <img src="@routes.Assets.at("images/project_default_logo.png")" alt="@project.name"/>
+                        </div>
+                        <div style="float:left; color: gray">
+                            You do not have permission to view this project's information
+                        </div>
+                    </div>
+                </li>
+            }
         }
     	</ul>
 
Add a comment
List