From 8c4dbe2fc99fb70d925f4cdf6fce333c755daa56 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 16 Mar 2012 14:03:33 +0000 Subject: [PATCH] implements browsing root for a selected repository. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1301528 13f79535-47bb-0310-9956-ffa450edef68 --- .../rest/api/services/BrowseService.java | 6 ++-- .../rest/services/DefaultBrowseService.java | 27 ++++++++++++-- .../src/main/webapp/js/archiva/main.js | 36 +++++++++---------- .../src/main/webapp/js/archiva/search.js | 26 +++++++++++--- .../webapp/js/archiva/templates/menu.html | 2 +- .../webapp/js/archiva/templates/search.html | 2 +- 6 files changed, 68 insertions(+), 31 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java index 77e251a11..64996c6ae 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java @@ -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}" ) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index d55771eaa..5749fa2f5 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -53,7 +53,7 @@ public class DefaultBrowseService implements BrowseService { - public BrowseResult getRootGroups() + public BrowseResult getRootGroups( String repositoryId ) throws ArchivaRestServiceException { List 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 namespaces = new LinkedHashSet(); // 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(); + 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 projects = new LinkedHashSet(); RepositorySession repositorySession = repositorySessionFactory.createSession(); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js index b9a82da8e..382716dcd 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js @@ -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(); - - }) }); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js index 1f9140047..e399ee20a 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js @@ -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); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/menu.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/menu.html index 66f52e200..bb59636bc 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/menu.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/menu.html @@ -24,7 +24,7 @@ ${$.i18n.prop('menu.artifacts.search')}
  • - ${$.i18n.prop('menu.artifacts.browse')} + ${$.i18n.prop('menu.artifacts.browse')}
  • diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html index 489fa910e..c90f4bf17 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html @@ -381,7 +381,7 @@