Skip to content
Permalink
Browse files

API / Transfer owner.

  • Loading branch information
fxprunayre committed Jun 24, 2016
1 parent 8e63d6a commit acc67c0f67438b6fd91e6ec6571a1b96f4fdb3c4
Showing with 558 additions and 67 deletions.
  1. +1 −1 code_quality/findbugs-excludes.xml
  2. +2 −2 core/src/main/java/org/fao/geonet/kernel/mef/MEFLib.java
  3. +31 −1 services/src/main/java/org/fao/geonet/api/groups/GroupsApi.java
  4. +1 −1 services/src/main/java/org/fao/geonet/api/records/formatters/XsltFormatter.java
  5. +7 −4 services/src/main/java/org/fao/geonet/api/users/UsersApi.java
  6. +64 −0 services/src/main/java/org/fao/geonet/api/users/transfer/OwnerResponse.java
  7. +4 −11 services/src/main/java/org/fao/geonet/{services/ownership → api/users/transfer}/OwnershipUtils.java
  8. +260 −0 services/src/main/java/org/fao/geonet/api/users/transfer/TransferApi.java
  9. +67 −0 services/src/main/java/org/fao/geonet/api/users/transfer/TransferRequest.java
  10. +85 −0 services/src/main/java/org/fao/geonet/api/users/transfer/UserGroupsResponse.java
  11. +1 −1 services/src/main/java/org/fao/geonet/services/metadata/PrepareBatchNewOwner.java
  12. +2 −0 services/src/main/java/org/fao/geonet/services/ownership/Editors.java
  13. +1 −1 services/src/main/java/org/fao/geonet/services/ownership/Groups.java
  14. +1 −0 services/src/main/java/org/fao/geonet/services/ownership/Transfer.java
  15. +1 −1 services/src/main/java/org/fao/geonet/services/user/UserGroups.java
  16. +1 −1 web-ui/src/main/resources/catalog/components/metadatamanager/EditorService.js
  17. +21 −32 web-ui/src/main/resources/catalog/js/admin/AdminToolsController.js
  18. +1 −1 web-ui/src/main/resources/catalog/locales/en-admin.json
  19. +7 −10 web-ui/src/main/resources/catalog/templates/admin/tools/transferownership.html
@@ -184,7 +184,7 @@
<Bug pattern="SE_COMPARATOR_SHOULD_BE_SERIALIZABLE"/>
</Match>
<Match>
<Class name="org.fao.geonet.services.ownership.OwnershipUtils$1"/>
<Class name="org.fao.geonet.api.users.transfer.OwnershipUtils$1"/>
</Match>
<Match>
<Class name="org.fao.geonet.wro4j.TemplatesUriLocator"/>
@@ -518,9 +518,9 @@ public String toString() {
* MEF file version.
*
* MEF file is composed of one or more metadata record with extra information managed by
* GeoNetwork. Metadata is in XML format. An information file (info.xml) is used to transfert
* GeoNetwork. Metadata is in XML format. An information file (info.xml) is used to transfer
* general informations, categories, privileges and file references information. A public and
* private directories allows data transfert (eg. thumbnails, data upload).
* private directories allows data transfer (eg. thumbnails, data upload).
*/
public enum Version {
/**
@@ -185,11 +185,41 @@ public Group getGroup(
if (group == null) {
throw new ResourceNotFoundException(String.format("Group not found"));
}

return group;
}


@ApiOperation(
value = "Get group users",
notes = "",
nickname = "getGroupUsers")
@RequestMapping(
value = "/{groupIdentifier}/users",
produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)
@PreAuthorize("hasRole('UserAdmin')")
@ResponseBody
public List<User> getGroupUsers(
@ApiParam(
value = "Group identifier"
)
@PathVariable
Integer groupIdentifier
) throws Exception {
ApplicationContext applicationContext = ApplicationContextHolder.get();
GroupRepository groupRepository = applicationContext.getBean(GroupRepository.class);
final Group group = groupRepository.findOne(groupIdentifier);

if (group == null) {
throw new ResourceNotFoundException(String.format("Group not found"));
}
UserRepository userRepository = applicationContext.getBean(UserRepository.class);
return userRepository.findAllUsersInUserGroups(
UserGroupSpecs.hasGroupId(groupIdentifier));
}


@ApiOperation(
value = "Update a group",
notes = "",
@@ -53,7 +53,7 @@
* name of the URL parameter eg. <xsl:param name="view"/> </p>
*
* @author Jesse on 10/15/2014.
* @author Francois on 06/01/2015: Add request parameters transfert to XSLT and metadata info.
* @author Francois on 06/01/2015: Add request parameters transfer to XSLT and metadata info.
*/
@Component
public class XsltFormatter implements FormatterImpl {
@@ -28,6 +28,7 @@
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.api.API;
import org.fao.geonet.api.ApiUtils;
import org.fao.geonet.api.exception.ResourceNotFoundException;
import org.fao.geonet.constants.Params;
import org.fao.geonet.domain.*;
import org.fao.geonet.exceptions.OperationNotAllowedEx;
@@ -36,6 +37,7 @@
import org.fao.geonet.repository.specification.UserGroupSpecs;
import org.fao.geonet.repository.specification.UserSpecs;
import org.fao.geonet.util.PasswordUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -270,11 +272,12 @@ public User getUser(

@ApiOperation(
value = "Retrieve user groups",
notes = "Retrieve the user groups.",
notes = "",
nickname = "retrieveUserGroups")
@RequestMapping(value = "/{userIdentifier}/groups",
produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.GET)
method = RequestMethod.GET
)
@ResponseStatus(value = HttpStatus.OK)
@PreAuthorize("isAuthenticated()")
@ResponseBody
@@ -338,7 +341,7 @@ public User getUser(
List<Integer> adminList = userGroupRepository.findGroupIds(where(UserGroupSpecs.hasUserId(Integer.valueOf(myUserId)))
.or(UserGroupSpecs.hasUserId(Integer.valueOf(userIdentifier))));
if (adminList.isEmpty()) {
throw new OperationNotAllowedEx("You don't have rights to do this because the user you want is not part of your group");
throw new SecurityException("You don't have rights to do this because the user you want is not part of your group");
}
}

@@ -348,7 +351,7 @@ public User getUser(

return userGroups;
} else {
throw new IllegalArgumentException("You don't have rights to do get the groups for this user");
throw new SecurityException("You don't have rights to do get the groups for this user");
}
}

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2001-2016 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
* Rome - Italy. email: geonetwork@osgeo.org
*/

package org.fao.geonet.api.users.transfer;

import org.fao.geonet.domain.User;

public class OwnerResponse {
int id;
String name;
int records;

public OwnerResponse(User u, int size) {
this.id = u.getId();
this.name = String.format("%s %s (%s)",
u.getName(), u.getSurname(), u.getUsername()
);
this.records = size;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getRecords() {
return records;
}

public void setRecords(int records) {
this.records = records;
}
}
@@ -21,14 +21,15 @@
//=== Rome - Italy. email: geonetwork@osgeo.org
//==============================================================================

package org.fao.geonet.services.ownership;
package org.fao.geonet.api.users.transfer;

import com.google.common.base.Function;
import com.google.common.collect.Lists;

import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;

import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.domain.Profile;
import org.fao.geonet.domain.User;
import org.fao.geonet.domain.UserGroup;
@@ -68,6 +69,7 @@
return getUsers(context, us, users);
}

@Deprecated
public static List<Element> getUsers(ServiceContext context, UserSession us, List<User> users) throws SQLException {

int id = us.getUserIdAsInt();
@@ -110,13 +112,7 @@ public Element apply(@Nonnull User input) {
return newList;
}

//--------------------------------------------------------------------------
//---
//--- Private methods
//---
//--------------------------------------------------------------------------

private static Set<String> getUserGroups(ServiceContext context, int id) throws SQLException {
protected static Set<String> getUserGroups(ServiceContext context, int id) throws SQLException {
HashSet<String> groupIds = new HashSet<String>();

final List<UserGroup> users = context.getBean(UserGroupRepository.class).findAll(UserGroupSpecs.hasUserId(id));
@@ -127,6 +123,3 @@ public Element apply(@Nonnull User input) {
return groupIds;
}
}

//=============================================================================

0 comments on commit acc67c0

Please sign in to comment.
You can’t perform that action at this time.