mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-05 07:03:24 +01:00
Improve delete message.
Add unit test.
This commit is contained in:
parent
a8f7d28c11
commit
adfc6c08f2
@ -45,6 +45,6 @@ public interface UserManager {
|
|||||||
|
|
||||||
public User createUser(User user, Collaborator col);
|
public User createUser(User user, Collaborator col);
|
||||||
|
|
||||||
public void deleteUser(User user);
|
public void removeUser(@NotNull User user);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,9 +110,8 @@ public class UserManagerImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteUser(@NotNull final User user) {
|
public void removeUser(@NotNull final User user) {
|
||||||
getHibernateTemplate().delete(user);
|
getHibernateTemplate().delete(user);
|
||||||
getHibernateTemplate().flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void auditLogin(@NotNull AccessAuditory accessAuditory) {
|
public void auditLogin(@NotNull AccessAuditory accessAuditory) {
|
||||||
|
@ -79,7 +79,7 @@ public class AccountController extends BaseController {
|
|||||||
throw new IllegalArgumentException("Firstname can not be null");
|
throw new IllegalArgumentException("Firstname can not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
final User user = Utils.getUser();
|
final User user = Utils.getUser(true);
|
||||||
user.setFirstname(firstname);
|
user.setFirstname(firstname);
|
||||||
userService.updateUser(user);
|
userService.updateUser(user);
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ public class AccountController extends BaseController {
|
|||||||
throw new IllegalArgumentException("lastname can not be null");
|
throw new IllegalArgumentException("lastname can not be null");
|
||||||
|
|
||||||
}
|
}
|
||||||
final User user = Utils.getUser();
|
final User user = Utils.getUser(true);
|
||||||
user.setLastname(lastname);
|
user.setLastname(lastname);
|
||||||
userService.updateUser(user);
|
userService.updateUser(user);
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ public class AccountController extends BaseController {
|
|||||||
userService.updateUser(user);
|
userService.updateUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.DELETE, value = "account", consumes = {"text/plain"})
|
@RequestMapping(method = RequestMethod.DELETE, value = "account")
|
||||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||||
public void deleleteUser() throws WiseMappingException
|
public void deleleteUser() throws WiseMappingException
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ public class AccountController extends BaseController {
|
|||||||
final Mindmap mindmap = collaboration.getMindMap();
|
final Mindmap mindmap = collaboration.getMindMap();
|
||||||
mindmapService.removeMindmap(mindmap,user);
|
mindmapService.removeMindmap(mindmap,user);
|
||||||
}
|
}
|
||||||
userService.deleteUser(user);
|
userService.removeUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package com.wisemapping.rest;
|
package com.wisemapping.rest;
|
||||||
|
|
||||||
import com.mangofactory.swagger.annotations.ApiModel;
|
|
||||||
import com.wisemapping.exceptions.WiseMappingException;
|
import com.wisemapping.exceptions.WiseMappingException;
|
||||||
import com.wisemapping.model.AuthenticationType;
|
import com.wisemapping.model.AuthenticationType;
|
||||||
import com.wisemapping.model.Collaboration;
|
import com.wisemapping.model.Collaboration;
|
||||||
@ -146,7 +145,7 @@ public class AdminController extends BaseController {
|
|||||||
mindmapService.removeMindmap(mindmap,user);
|
mindmapService.removeMindmap(mindmap,user);
|
||||||
}
|
}
|
||||||
|
|
||||||
userService.deleteUser(user);
|
userService.removeUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("Note: Administration permissions required.")
|
@ApiOperation("Note: Administration permissions required.")
|
||||||
|
@ -21,12 +21,9 @@ package com.wisemapping.security;
|
|||||||
import com.wisemapping.model.User;
|
import com.wisemapping.model.User;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
final public class Utils {
|
final public class Utils {
|
||||||
private Utils() {
|
private Utils() {
|
||||||
}
|
}
|
||||||
@ -37,7 +34,7 @@ final public class Utils {
|
|||||||
return getUser(false);
|
return getUser(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NotNull
|
||||||
public static User getUser(boolean forceCheck) {
|
public static User getUser(boolean forceCheck) {
|
||||||
User result = null;
|
User result = null;
|
||||||
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
@ -46,8 +46,6 @@ public interface MindmapService {
|
|||||||
|
|
||||||
void removeCollaboration(@NotNull Mindmap mindmap, @NotNull Collaboration collaboration) throws CollaborationException;
|
void removeCollaboration(@NotNull Mindmap mindmap, @NotNull Collaboration collaboration) throws CollaborationException;
|
||||||
|
|
||||||
void addTags(@NotNull Mindmap mindmap, String tags);
|
|
||||||
|
|
||||||
void removeMindmap(@NotNull final Mindmap mindmap, @NotNull final User user) throws WiseMappingException;
|
void removeMindmap(@NotNull final Mindmap mindmap, @NotNull final User user) throws WiseMappingException;
|
||||||
|
|
||||||
List<Mindmap> search(MindMapCriteria criteria);
|
List<Mindmap> search(MindMapCriteria criteria);
|
||||||
|
@ -231,28 +231,6 @@ public class MindmapServiceImpl
|
|||||||
return collaborator;
|
return collaborator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addTags(@NotNull Mindmap mindmap, String tags) {
|
|
||||||
mindmap.setTags(tags);
|
|
||||||
mindmapManager.updateMindmap(mindmap, false);
|
|
||||||
if (tags != null && tags.length() > 0) {
|
|
||||||
final String tag[] = tags.split(TAG_SEPARATOR);
|
|
||||||
final User user = mindmap.getCreator();
|
|
||||||
// Add new Tags to User
|
|
||||||
boolean updateUser = false;
|
|
||||||
for (String userTag : tag) {
|
|
||||||
if (!user.getTags().contains(userTag)) {
|
|
||||||
user.getTags().add(userTag);
|
|
||||||
updateUser = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (updateUser) {
|
|
||||||
//update user
|
|
||||||
userService.updateUser(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MindMapHistory> findMindmapHistory(int mindmapId) {
|
public List<MindMapHistory> findMindmapHistory(int mindmapId) {
|
||||||
|
@ -38,7 +38,7 @@ public interface UserService {
|
|||||||
|
|
||||||
public void resetPassword(@NotNull String email) throws InvalidUserEmailException, InvalidAuthSchemaException;
|
public void resetPassword(@NotNull String email) throws InvalidUserEmailException, InvalidAuthSchemaException;
|
||||||
|
|
||||||
public void deleteUser(@NotNull User user);
|
public void removeUser(@NotNull User user);
|
||||||
|
|
||||||
public void auditLogin(@NotNull User user);
|
public void auditLogin(@NotNull User user);
|
||||||
|
|
||||||
|
@ -102,8 +102,10 @@ public class UserServiceImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteUser(@NotNull User user) {
|
public void removeUser(@NotNull User user) {
|
||||||
userManager.deleteUser(user);
|
// Force object reload before removing....
|
||||||
|
final User userBy = userManager.getUserBy(user.getEmail());
|
||||||
|
userManager.removeUser(userBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,7 +15,7 @@ LOGOUT=Logout
|
|||||||
PASSWORD=Password
|
PASSWORD=Password
|
||||||
NEW_PASSWORD=New password
|
NEW_PASSWORD=New password
|
||||||
CONFIRM_NEW_PASSWORD=Confirm new password
|
CONFIRM_NEW_PASSWORD=Confirm new password
|
||||||
DELETE__ACCOUNT=Delete account
|
DELETE__ACCOUNT=Delete My Account
|
||||||
MY_WISEMAPS=My Wisemaps
|
MY_WISEMAPS=My Wisemaps
|
||||||
RETYPE_PASSWORD=Retype Password
|
RETYPE_PASSWORD=Retype Password
|
||||||
REGISTER=Register
|
REGISTER=Register
|
||||||
@ -32,7 +32,7 @@ YOUR_ROLE=Your Role
|
|||||||
FORGOT_PASSWORD=Forgot Password ?
|
FORGOT_PASSWORD=Forgot Password ?
|
||||||
CHANGE_PASSWORD=Change Password
|
CHANGE_PASSWORD=Change Password
|
||||||
CHANGE_LANGUAGE=Change Language
|
CHANGE_LANGUAGE=Change Language
|
||||||
WARNING_DELETE_USER=Warning! This action cannot be undone.
|
WARNING_DELETE_USER=If you do not think you will use WiseMapping again and would like your account deleted, we can take care of this for you. Keep in mind that you will not be able retrieve any mindmap you have added. <br/><br/> If you would still like your account deleted, click "Delete My Account".
|
||||||
FAQ=Frequent Asked Questions
|
FAQ=Frequent Asked Questions
|
||||||
SHORT_FAQ=FAQ
|
SHORT_FAQ=FAQ
|
||||||
LOGIN=Login
|
LOGIN=Login
|
||||||
|
@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2012] [wisemapping]
|
||||||
|
*
|
||||||
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||||
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||||
|
* "powered by wisemapping" text requirement on every single page;
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the license at
|
||||||
|
*
|
||||||
|
* http://www.wisemapping.org/license
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.wisemapping.test.rest;
|
||||||
|
|
||||||
|
|
||||||
|
import com.wisemapping.rest.model.RestUser;
|
||||||
|
import org.jetbrains.annotations.NonNls;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
|
import org.springframework.security.crypto.codec.Base64;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.testng.annotations.DataProvider;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public class RestAccountITCase {
|
||||||
|
|
||||||
|
@NonNls
|
||||||
|
private static final String HOST_PORT = "http://localhost:8080";
|
||||||
|
private static final String BASE_REST_URL = HOST_PORT + "/service";
|
||||||
|
private static final String ADMIN_CREDENTIALS = "admin@wisemapping.org" + ":" + "admin";
|
||||||
|
|
||||||
|
|
||||||
|
@Test(dataProvider = "ContentType-Provider-Function")
|
||||||
|
public void deleteUser(final @NotNull MediaType mediaType) { // Configure media types ...
|
||||||
|
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||||
|
final RestTemplate adminTemplate = createTemplate(ADMIN_CREDENTIALS);
|
||||||
|
|
||||||
|
final RestUser dummyUser = createDummyUser();
|
||||||
|
createUser(requestHeaders, adminTemplate, dummyUser);
|
||||||
|
|
||||||
|
// Delete user ...
|
||||||
|
final RestTemplate dummyTemplate = createTemplate(dummyUser.getEmail() + ":fooPassword");
|
||||||
|
dummyTemplate.delete(BASE_REST_URL + "/account");
|
||||||
|
|
||||||
|
// Is the user there ?
|
||||||
|
// Check that the user has been created ...
|
||||||
|
// try {
|
||||||
|
// findUser(requestHeaders, adminTemplate, location);
|
||||||
|
// fail("User could not be deleted !");
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public String createNewUser(final @NotNull MediaType mediaType) {
|
||||||
|
|
||||||
|
// Configure media types ...
|
||||||
|
final HttpHeaders requestHeaders = createHeaders(mediaType);
|
||||||
|
final RestTemplate templateRest = createTemplate(ADMIN_CREDENTIALS);
|
||||||
|
|
||||||
|
// Fill user data ...
|
||||||
|
final RestUser restUser = createDummyUser();
|
||||||
|
|
||||||
|
// Create a new user ...
|
||||||
|
final URI location = createUser(requestHeaders, templateRest, restUser);
|
||||||
|
|
||||||
|
// Check that the user has been created ...
|
||||||
|
ResponseEntity<RestUser> result = findUser(requestHeaders, templateRest, location);
|
||||||
|
assertEquals(result.getBody().getEmail(), restUser.getEmail(), "Returned object object seems not be the same.");
|
||||||
|
|
||||||
|
// Find by email and check ...
|
||||||
|
result = findUserByEmail(requestHeaders, templateRest, restUser.getEmail());
|
||||||
|
assertEquals(result.getBody().getEmail(), restUser.getEmail(), "Returned object object seems not be the same.");
|
||||||
|
|
||||||
|
return restUser.getEmail();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ResponseEntity<RestUser> findUser(HttpHeaders requestHeaders, RestTemplate templateRest, URI location) {
|
||||||
|
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
||||||
|
final String url = HOST_PORT + location;
|
||||||
|
return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResponseEntity<RestUser> findUserByEmail(HttpHeaders requestHeaders, RestTemplate templateRest, final String email) {
|
||||||
|
HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders);
|
||||||
|
|
||||||
|
// Add extension only to avoid the fact that the last part is extracted ...
|
||||||
|
final String url = BASE_REST_URL + "/admin/users/email/{email}.json";
|
||||||
|
return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class, email);
|
||||||
|
}
|
||||||
|
|
||||||
|
private URI createUser(HttpHeaders requestHeaders, RestTemplate templateRest, RestUser restUser) {
|
||||||
|
HttpEntity<RestUser> createUserEntity = new HttpEntity<RestUser>(restUser, requestHeaders);
|
||||||
|
return templateRest.postForLocation(BASE_REST_URL + "/admin/users", createUserEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpHeaders createHeaders(@NotNull MediaType mediaType) {
|
||||||
|
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
|
||||||
|
acceptableMediaTypes.add(mediaType);
|
||||||
|
|
||||||
|
final HttpHeaders result = new HttpHeaders();
|
||||||
|
result.setAccept(acceptableMediaTypes);
|
||||||
|
result.setContentType(mediaType);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RestTemplate createTemplate(@NotNull final String authorisation) {
|
||||||
|
SimpleClientHttpRequestFactory s = new SimpleClientHttpRequestFactory() {
|
||||||
|
@Override
|
||||||
|
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
|
||||||
|
super.prepareConnection(connection, httpMethod);
|
||||||
|
|
||||||
|
byte[] encodedAuthorisation = Base64.encode(authorisation.getBytes());
|
||||||
|
connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuthorisation));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
return new RestTemplate(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RestUser createDummyUser() {
|
||||||
|
final RestUser restUser = new RestUser();
|
||||||
|
final String username = "foo-to-delete" + System.nanoTime();
|
||||||
|
final String email = username + "@example.org";
|
||||||
|
restUser.setEmail(email);
|
||||||
|
restUser.setFirstname("foo first name");
|
||||||
|
restUser.setLastname("foo last name");
|
||||||
|
restUser.setPassword("fooPassword");
|
||||||
|
return restUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@DataProvider(name = "ContentType-Provider-Function")
|
||||||
|
public Object[][] contentTypes() {
|
||||||
|
return new Object[][]{{MediaType.APPLICATION_XML}, {MediaType.APPLICATION_JSON}};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user