Skip to content

Commit

Permalink
API / Transfer owner.
Browse files Browse the repository at this point in the history
  • Loading branch information
fxprunayre committed Jun 24, 2016
1 parent 8e63d6a commit acc67c0
Show file tree
Hide file tree
Showing 19 changed files with 558 additions and 67 deletions.
2 changes: 1 addition & 1 deletion code_quality/findbugs-excludes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/fao/geonet/kernel/mef/MEFLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
32 changes: 31 additions & 1 deletion services/src/main/java/org/fao/geonet/api/groups/GroupsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions services/src/main/java/org/fao/geonet/api/users/UsersApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -270,11 +272,12 @@ public ResponseEntity<String> resetUserPassword(

@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
Expand Down Expand Up @@ -338,7 +341,7 @@ public List<UserGroup> retrieveUserGroups(
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");
}
}

Expand All @@ -348,7 +351,7 @@ public List<UserGroup> retrieveUserGroups(

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");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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: [email protected]
*/

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
//=== Rome - Italy. email: [email protected]
//==============================================================================

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;
Expand Down Expand Up @@ -68,6 +69,7 @@ public static List<Element> getEditorUsers(ServiceContext context, UserSession u
return getUsers(context, us, users);
}

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

int id = us.getUserIdAsInt();
Expand Down Expand Up @@ -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));
Expand All @@ -127,6 +123,3 @@ private static Set<String> getUserGroups(ServiceContext context, int id) throws
return groupIds;
}
}

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

Loading

0 comments on commit acc67c0

Please sign in to comment.