]> source.dussan.org Git - archiva.git/commitdiff
implements browsing root for a selected repository.
authorOlivier Lamy <olamy@apache.org>
Fri, 16 Mar 2012 14:03:33 +0000 (14:03 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 16 Mar 2012 14:03:33 +0000 (14:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1301528 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/menu.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html

index 77e251a115f5cfda89b49b368b96415cfac4e684..64996c6aebf862fde08a2f5ae5d239c34abdb148 100644 (file)
@@ -28,6 +28,7 @@ import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import java.util.List;
 
@@ -42,14 +43,15 @@ public interface BrowseService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( noPermission = true, noRestriction = true )
-    BrowseResult getRootGroups()
+    BrowseResult getRootGroups( @QueryParam( "repositoryId" ) String repositoryId )
         throws ArchivaRestServiceException;
 
     @Path( "browseGroupId/{groupId}" )
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( noPermission = true, noRestriction = true )
-    BrowseResult browseGroupId( @PathParam( "groupId" ) String groupId )
+    BrowseResult browseGroupId( @PathParam( "groupId" ) String groupId,
+                                @QueryParam( "repositoryId" ) String repositoryId )
         throws ArchivaRestServiceException;
 
     @Path( "versionsList/{g}/{a}" )
index d55771eaa282abefcf1866d1f2bfde04ad26ca31..5749fa2f5237ad334f6105552719431024c91951 100644 (file)
@@ -53,7 +53,7 @@ public class DefaultBrowseService
     implements BrowseService
 {
 
-    public BrowseResult getRootGroups()
+    public BrowseResult getRootGroups( String repositoryId )
         throws ArchivaRestServiceException
     {
         List<String> selectedRepos = getObservableRepos();
@@ -63,6 +63,17 @@ public class DefaultBrowseService
             return new BrowseResult();
         }
 
+        if ( StringUtils.isNotEmpty( repositoryId ) )
+        {
+            // check user has karma on the repository
+            if ( !selectedRepos.contains( repositoryId ) )
+            {
+                throw new ArchivaRestServiceException( "browse.root.groups.repositoy.denied",
+                                                       Response.Status.FORBIDDEN.getStatusCode() );
+            }
+            selectedRepos = Collections.singletonList( repositoryId );
+        }
+
         Set<String> namespaces = new LinkedHashSet<String>();
 
         // TODO: this logic should be optional, particularly remembering we want to keep this code simple
@@ -74,6 +85,7 @@ public class DefaultBrowseService
         {
             MetadataResolver metadataResolver = repositorySession.getResolver();
             namespacesToCollapse = new LinkedHashSet<String>();
+
             for ( String repoId : selectedRepos )
             {
                 namespacesToCollapse.addAll( metadataResolver.resolveRootNamespaces( repositorySession, repoId ) );
@@ -104,7 +116,7 @@ public class DefaultBrowseService
         return new BrowseResult( browseGroupResultEntries );
     }
 
-    public BrowseResult browseGroupId( String groupId )
+    public BrowseResult browseGroupId( String groupId, String repositoryId )
         throws ArchivaRestServiceException
     {
 
@@ -115,6 +127,17 @@ public class DefaultBrowseService
             return new BrowseResult();
         }
 
+        if ( StringUtils.isNotEmpty( repositoryId ) )
+        {
+            // check user has karma on the repository
+            if ( !selectedRepos.contains( repositoryId ) )
+            {
+                throw new ArchivaRestServiceException( "browse.root.groups.repositoy.denied",
+                                                       Response.Status.FORBIDDEN.getStatusCode() );
+            }
+            selectedRepos = Collections.singletonList( repositoryId );
+        }
+
         Set<String> projects = new LinkedHashSet<String>();
 
         RepositorySession repositorySession = repositorySessionFactory.createSession();
index b9a82da8ee754029a89c70fdab024e865b5d5409..382716dcdfda0bd66dd7f115867506bcba7a37f6 100644 (file)
@@ -18,7 +18,7 @@
  */
 require( ["order!jquery" ,"order!redback/redback"],
 function($) {
-  "use strict"
+
 $(function() {
 
   // define a container object with various datas
@@ -37,26 +37,26 @@ $(function() {
    * reccord a cookie for session with the logged user
    * @param user see user.js
    */
-  function reccordLoginCookie(user) {
+  reccordLoginCookie=function(user) {
     $.cookie('redback_login', ko.toJSON(user));
   }
 
-  function getUserFromLoginCookie(){
+  getUserFromLoginCookie=function(){
     return $.parseJSON($.cookie('redback_login'));
   }
 
-  function deleteLoginCookie(){
+  deleteLoginCookie=function(){
     $.cookie('redback_login', null);
   }
 
-  function logout(screenChange){
+  logout=function(doScreenChange){
     deleteLoginCookie();
     $("#login-link").show();
     $("#register-link").show();
     $("#logout-link").hide();
     $("#change-password-link").hide();
     hideElementWithKarma();
-    if (screenChange) screenChange();
+    if (doScreenChange) screenChange();
     $("#main-content").html("");
     $.ajax({
       url: 'restServices/redbackServices/loginService/logout'
@@ -64,7 +64,7 @@ $(function() {
   }
 
   // handle url with registration link
-  function checkUrlParams() {
+  checkUrlParams=function(){
     var validateMeId = $.urlParam('validateMe');
     if (validateMeId) {
       validateKey(validateMeId);
@@ -125,7 +125,7 @@ $(function() {
         return;
       }
       if (screen=="browse"){
-        displayBrowse();
+        displayBrowse(true);
         return;
       }
     }
@@ -134,11 +134,11 @@ $(function() {
     displaySearch();
   }
 
-  function hasKarma(karmaName){
+  hasKarma=function(karmaName){
     return $.inArray(karmaName,window.redbackModel.operatioNames)>=0;
   }
 
-  function decorateMenuWithKarma(user) {
+  decorateMenuWithKarma=function(user) {
     var username = user.username;
     $.log("decorateMenuWithKarma");
     // we can receive an observable user so take if it's a function or not
@@ -167,7 +167,7 @@ $(function() {
     });
   }
 
-  function checkElementKarma(element){
+  checkElementKarma=function(element){
     var bindingValue = $(element).attr("redback-permissions");
     $(element).hide();
     var neededKarmas = $(eval(bindingValue)).toArray();
@@ -184,7 +184,7 @@ $(function() {
     }
   }
 
-  function hideElementWithKarma(){
+  hideElementWithKarma=function(){
     $("#topbar-menu-container [redback-permissions]").each(function(element){
       $(this).hide();
     });
@@ -195,7 +195,7 @@ $(function() {
     $.log("hideElementWithKarma");
   }
 
-  function userLoggedCallbackFn(user){
+  userLoggedCallbackFn=function(user){
     $.log("userLoggedCallbackFn:"+ (user?user.username:null));
 
     if (!user) {
@@ -212,11 +212,11 @@ $(function() {
     }
   }
 
-  function checkSecurityLinks(){
+  checkSecurityLinks=function(){
     userLogged(userLoggedCallbackFn);
   }
 
-  function checkCreateAdminLink(){
+  checkCreateAdminLink=function(){
     $.ajax("restServices/redbackServices/userService/isAdminUserExists", {
       type: "GET",
       dataType: 'json',
@@ -236,7 +236,7 @@ $(function() {
 
 
 
-  function startArchivaApplication(){
+  startArchivaApplication=function(){
     $.log("startArchivaApplication");
     $('#topbar-menu-container').html($("#topbar-menu"));
     $('#sidebar-content').html($("#main-menu"));
@@ -290,12 +290,8 @@ $(function() {
                                                };;
   }
 
-
-
   startArchivaApplication();
 
-
-
 })
 });
 
index 1f9140047bb7609a769eb5d8f09033a73499e0cb..e399ee20a61610277a36ebf149ab45bbaaf0c5bb 100644 (file)
@@ -165,18 +165,21 @@ $(function() {
   /**
    * call from menu entry to display root level
    */
-  displayBrowse=function(){
+  displayBrowse=function(freshView){
     screenChange()
     var mainContent = $("#main-content");
-    mainContent.html($("#browse-tmpl" ).tmpl());
+    if(freshView){
+      mainContent.html($("#browse-tmpl" ).tmpl());
+    }
     mainContent.find("#browse_result").html(mediumSpinnerImg());
 
     $.ajax("restServices/archivaServices/browseService/userRepositories", {
         type: "GET",
         dataType: 'json',
         success: function(data) {
-          mainContent.find("#selected_repository" ).html($("#selected_repository_tmpl" ).tmpl({repositories:data}));// selected_repository_tmpl
-          $.ajax("restServices/archivaServices/browseService/rootGroups", {
+          mainContent.find("#selected_repository" ).html($("#selected_repository_tmpl" ).tmpl({repositories:data}));
+          var url="restServices/archivaServices/browseService/rootGroups"
+          $.ajax(url, {
               type: "GET",
               dataType: 'json',
               success: function(data) {
@@ -191,8 +194,22 @@ $(function() {
         }
     });
 
+  }
 
+  changeBrowseRepository=function(){
+    var selectedRepository=getSelectedBrowsingRepository();
+    //displayBrowse(false,selectedRepository);
+    displayGroupDetail(null,null,"restServices/archivaServices/browseService/rootGroups?repositoryId="+encodeURIComponent(selectedRepository));
+  }
 
+  getSelectedBrowsingRepository=function(){
+    var selectedOption=$("#main-content #select_browse_repository option:selected" );
+    if (selectedOption.length>0){
+      var repoId=selectedOption.val();
+      $.log("getSelectedBrowsingRepository:"+repoId);
+      return repoId;
+    }
+    $.log("getSelectedBrowsingRepository:none");
   }
 
   enableAutocompleBrowse=function(groupId){
@@ -301,7 +318,6 @@ $(function() {
   displayBrowseGroupIdFromAutoComplete=function(groupId){
     clearUserMessages();
     var mainContent = $("#main-content");
-    //mainContent.html($("#browse-tmpl" ).tmpl());
     mainContent.find("#browse_result").html(mediumSpinnerImg());
     var parentBrowseViewModel=new BrowseViewModel(null,null,null);
     displayGroupDetail(groupId,parentBrowseViewModel,null);
index 66f52e2006c7c8fe5aa9aaba1ae7ad23a54ca7a3..bb59636bc6ef09f8cc351b85113a23fbabfc98fc 100644 (file)
@@ -24,7 +24,7 @@
         <a href="#" id="menu-find-search-a" onclick="displaySearch(this)">${$.i18n.prop('menu.artifacts.search')}</a>
       </li>
       <li>
-        <a href="#" id="menu-find-browse-a" onclick="displayBrowse()">${$.i18n.prop('menu.artifacts.browse')}</a>
+        <a href="#" id="menu-find-browse-a" onclick="displayBrowse(true)">${$.i18n.prop('menu.artifacts.browse')}</a>
       </li>
     </ul>
 
index 489fa910e7978f8ac9413d9cb8908491324556a9..c90f4bf17301d3ba30b1037bdd25f8fe7ad76c01 100644 (file)
 
 
 <script id="selected_repository_tmpl" type="text/html">
-  <select id="repository">
+  <select id="select_browse_repository" onchange="changeBrowseRepository()">
     <option value="">All</option>
     {{each(i,repository) repositories}}
     <option value="${repository.id}">${repository.name}</option>