rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject svn commit: r1197192 - in /incubator/rave/trunk: rave-components/rave-core/src/main/java/org/apache/rave/portal/service/ rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/ rave-components/rave-core/src/test/java/org/apache/rav...
Date Thu, 03 Nov 2011 15:53:31 GMT
Author: jasha
Date: Thu Nov  3 15:53:30 2011
New Revision: 1197192

URL: http://svn.apache.org/viewvc?rev=1197192&view=rev
Log:
RAVE-317 start of deleting a user, not visible in the form yet
give more feedback in the admin interface after delete or update

Modified:
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java
    incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java
    incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java
    incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java
    incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/WidgetController.java
    incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/UserControllerTest.java
    incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/WidgetControllerTest.java
    incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties
    incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/userdetail.jsp
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/users.jsp
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/widgets.jsp
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/css/default.css

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java
(original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/UserService.java
Thu Nov  3 15:53:30 2011
@@ -19,7 +19,6 @@
 
 package org.apache.rave.portal.service;
 
-import java.util.Map;
 import org.apache.rave.portal.model.User;
 import org.apache.rave.portal.model.util.SearchResult;
 import org.springframework.security.core.userdetails.UserDetailsService;
@@ -100,4 +99,11 @@ public interface UserService extends Use
      * @return SearchResult
      */
     SearchResult<User> getUsersByFreeTextSearch(String searchTerm, int offset, int
pageSize);
+
+    /**
+     * Deletes a User
+     *
+     * @param userId {@link Long} id if the user
+     */
+    void deleteUser(Long userId);
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java
(original)
+++ incubator/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultUserService.java
Thu Nov  3 15:53:30 2011
@@ -19,10 +19,10 @@
 
 package org.apache.rave.portal.service.impl;
 
-import java.util.HashMap;
-import java.util.Map;
+import org.apache.rave.portal.model.Page;
 import org.apache.rave.portal.model.User;
 import org.apache.rave.portal.model.util.SearchResult;
+import org.apache.rave.portal.repository.PageRepository;
 import org.apache.rave.portal.repository.UserRepository;
 import org.apache.rave.portal.service.UserService;
 import org.slf4j.Logger;
@@ -46,14 +46,16 @@ import java.util.List;
  */
 @Service(value = "userService")
 public class DefaultUserService implements UserService {
-    protected static final Logger log = LoggerFactory.getLogger(DefaultUserService.class);
+    private static final Logger log = LoggerFactory.getLogger(DefaultUserService.class);
 
-    private UserRepository userRepository;
+    private final UserRepository userRepository;
+
+    private final PageRepository pageRepository;
 
     @Autowired
-    public DefaultUserService(UserRepository userRepository) {
+    public DefaultUserService(UserRepository userRepository, PageRepository pageRepository)
{
         this.userRepository = userRepository;
-
+        this.pageRepository = pageRepository;
     }
 
     @Override
@@ -158,4 +160,19 @@ public class DefaultUserService implemen
         searchResult.setPageSize(pageSize);
         return searchResult;
     }
+
+    @Override
+    @Transactional
+    // TODO RAVE-300: add security check that is is called by admin or the user itself
+    public void deleteUser(Long userId) {
+        User user = userRepository.get(userId);
+        if (user == null) {
+            return;
+        }
+        for (Page page : pageRepository.getAllPages(userId)) {
+            pageRepository.delete(page);
+        }
+        userRepository.delete(user);
+    }
+
 }
\ No newline at end of file

Modified: incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java
(original)
+++ incubator/rave/trunk/rave-components/rave-core/src/test/java/org/apache/rave/portal/service/impl/DefaultUserServiceTest.java
Thu Nov  3 15:53:30 2011
@@ -19,22 +19,11 @@
 
 package org.apache.rave.portal.service.impl;
 
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.rave.portal.model.Authority;
+import org.apache.rave.portal.model.Page;
 import org.apache.rave.portal.model.User;
 import org.apache.rave.portal.model.util.SearchResult;
+import org.apache.rave.portal.repository.PageRepository;
 import org.apache.rave.portal.repository.UserRepository;
 import org.apache.rave.portal.service.UserService;
 import org.junit.After;
@@ -49,18 +38,36 @@ import org.springframework.security.core
 import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
 public class DefaultUserServiceTest {
 
     private static final Long USER_ID = 1234L;
     private UserService service;
-    private UserRepository repository;
+    private UserRepository userRepository;
+    private PageRepository pageRepository;
     private static final String USER_NAME = "1234";
-     private static final String USER_EMAIL="test@test.com";
+    private static final String USER_EMAIL = "test@test.com";
 
     @Before
     public void setup() {
-        repository = createNiceMock(UserRepository.class);
-        service = new DefaultUserService(repository);
+        userRepository = createNiceMock(UserRepository.class);
+        pageRepository = createMock(PageRepository.class);
+        service = new DefaultUserService(userRepository, pageRepository);
     }
 
     @After
@@ -107,8 +114,8 @@ public class DefaultUserServiceTest {
     @Test
     public void setAuthenticatedUser_valid() {
         final User authUser = new User(USER_ID);
-        expect(repository.get(USER_ID)).andReturn(authUser).anyTimes();
-        replay(repository);
+        expect(userRepository.get(USER_ID)).andReturn(authUser).anyTimes();
+        replay(userRepository);
 
         service.setAuthenticatedUser(USER_ID);
         assertThat((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(),
@@ -121,8 +128,8 @@ public class DefaultUserServiceTest {
         final Authority userRole = new Authority();
         userRole.setAuthority("admin");
         authUser.addAuthority(userRole);
-        expect(repository.get(USER_ID)).andReturn(authUser).anyTimes();
-        replay(repository);
+        expect(userRepository.get(USER_ID)).andReturn(authUser).anyTimes();
+        replay(userRepository);
 
         service.setAuthenticatedUser(USER_ID);
         assertThat((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(),
@@ -135,8 +142,8 @@ public class DefaultUserServiceTest {
 
     @Test(expected = UsernameNotFoundException.class)
     public void setAuthenticatedUser_invalid_null() {
-        expect(repository.get(USER_ID)).andReturn(null).anyTimes();
-        replay(repository);
+        expect(userRepository.get(USER_ID)).andReturn(null).anyTimes();
+        replay(userRepository);
 
         service.setAuthenticatedUser(USER_ID);
     }
@@ -144,8 +151,8 @@ public class DefaultUserServiceTest {
     @Test
     public void loadByUsername_valid() {
         final User authUser = new User(USER_ID, USER_NAME);
-        expect(repository.getByUsername(USER_NAME)).andReturn(authUser).anyTimes();
-        replay(repository);
+        expect(userRepository.getByUsername(USER_NAME)).andReturn(authUser).anyTimes();
+        replay(userRepository);
 
         UserDetails result = service.loadUserByUsername(USER_NAME);
         assertThat((User)result, is(sameInstance(authUser)));
@@ -153,16 +160,16 @@ public class DefaultUserServiceTest {
 
     @Test(expected = UsernameNotFoundException.class)
     public void loadByUsername_invalid_exception() {
-        expect(repository.getByUsername(USER_NAME)).andThrow(new IncorrectResultSizeDataAccessException(1));
-        replay(repository);
+        expect(userRepository.getByUsername(USER_NAME)).andThrow(new IncorrectResultSizeDataAccessException(1));
+        replay(userRepository);
 
         service.setAuthenticatedUser(USER_ID);
     }
 
     @Test(expected = UsernameNotFoundException.class)
     public void loadByUsername_invalid_null() {
-        expect(repository.get(USER_ID)).andReturn(null).anyTimes();
-        replay(repository);
+        expect(userRepository.get(USER_ID)).andReturn(null).anyTimes();
+        replay(userRepository);
 
         service.setAuthenticatedUser(USER_ID);
     }
@@ -171,8 +178,8 @@ public class DefaultUserServiceTest {
      public void getUserByEmail_valid() {
           final User authUser=new User(USER_ID,USER_NAME);
           authUser.setEmail(USER_EMAIL);
-        expect(repository.getByUserEmail(USER_EMAIL)).andReturn(authUser).anyTimes();
-        replay(repository);
+        expect(userRepository.getByUserEmail(USER_EMAIL)).andReturn(authUser).anyTimes();
+        replay(userRepository);
 
         UserDetails result = service.getUserByEmail(USER_EMAIL);
         assertThat((User)result, is(sameInstance(authUser)));
@@ -196,8 +203,8 @@ public class DefaultUserServiceTest {
         users.add(user2);
         final int offset = 0;
         final int pageSize = 10;
-        expect(repository.getLimitedList(offset, pageSize)).andReturn(users);
-        replay(repository);
+        expect(userRepository.getLimitedList(offset, pageSize)).andReturn(users);
+        replay(userRepository);
 
         SearchResult<User> result = service.getLimitedListOfUsers(offset, pageSize);
         assertEquals(pageSize, result.getPageSize());
@@ -215,8 +222,8 @@ public class DefaultUserServiceTest {
         users.add(user2);
         final int offset = 0;
         final int pageSize = 10;
-        expect(repository.findByUsernameOrEmail(searchTerm, offset, pageSize)).andReturn(users);
-        replay(repository);
+        expect(userRepository.findByUsernameOrEmail(searchTerm, offset, pageSize)).andReturn(users);
+        replay(userRepository);
 
         SearchResult<User> result = service.getUsersByFreeTextSearch(searchTerm, offset,
pageSize);
         assertEquals(pageSize, result.getPageSize());
@@ -227,10 +234,29 @@ public class DefaultUserServiceTest {
     @Test
     public void updateUserProfile() {
         User user = new User(USER_ID, USER_NAME);
-        expect(repository.save(user)).andReturn(user).once();
-        replay(repository);
+        expect(userRepository.save(user)).andReturn(user).once();
+        replay(userRepository);
 
         service.updateUserProfile(user);
         assertTrue("Save called", true);
     }
+
+    @Test
+    public void deleteUserProfile() {
+        User user = new User(USER_ID, USER_NAME);
+        Page page = new Page(1L, user);
+        List<Page> pages = new ArrayList<Page>();
+        pages.add(page);
+        expect(pageRepository.getAllPages(USER_ID)).andReturn(pages);
+        expect(userRepository.get(USER_ID)).andReturn(user).times(1);
+        pageRepository.delete(page);
+        expectLastCall();
+        replay(userRepository, pageRepository);
+
+        service.deleteUser(USER_ID);
+        verify(userRepository, pageRepository);
+
+        assertTrue("Deleted", true);
+    }
+
 }

Modified: incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java
(original)
+++ incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/UserController.java
Thu Nov  3 15:53:30 2011
@@ -30,6 +30,7 @@ import org.apache.rave.portal.web.valida
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
+import org.springframework.ui.ModelMap;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.WebDataBinder;
 import org.springframework.web.bind.annotation.InitBinder;
@@ -69,14 +70,25 @@ public class UserController {
         dataBinder.setDisallowedFields("entityId", "username", "password", "confirmPassword");
     }
 
-    @RequestMapping(value = "/admin/users", method = RequestMethod.GET)
-    public String viewUsers(@RequestParam(required = false, defaultValue = "0") int offset,
Model model) {
+    @RequestMapping(value = {"/admin/users"}, method = RequestMethod.GET)
+    public String viewUsers(@RequestParam(required = false, defaultValue = "0") int offset,
+                            @RequestParam(required = false) final String action,
+                            Model model) {
         AdminControllerUtil.addNavigationMenusToModel(SELECTED_ITEM, model);
         final SearchResult<User> users = userService.getLimitedListOfUsers(offset,
DEFAULT_PAGE_SIZE);
         model.addAttribute(ModelKeys.SEARCHRESULT, users);
+
+        if (isDeleteOrUpdate(action)) {
+            model.addAttribute("actionresult", action);
+        }
+
         return ViewNames.ADMIN_USERS;
     }
 
+    private boolean isDeleteOrUpdate(String action) {
+        return "update".equals(action) || "delete".equals(action);
+    }
+
     @RequestMapping(value = "/admin/users/search", method = RequestMethod.GET)
     public String searchUsers(@RequestParam(required = true) String searchTerm,
                               @RequestParam(required = false, defaultValue = "0") int offset,
Model model) {
@@ -100,17 +112,39 @@ public class UserController {
     public String updateUserDetail(@ModelAttribute("user") User user, BindingResult result,
                                    @ModelAttribute(ModelKeys.TOKENCHECK) String sessionToken,
                                    @RequestParam() String token,
+                                   ModelMap modelMap,
                                    SessionStatus status) {
         AdminControllerUtil.checkTokens(sessionToken, token, status);
         userProfileValidator.validate(user, result);
         if (result.hasErrors()) {
+            AdminControllerUtil.addNavigationMenusToModel(SELECTED_ITEM, (Model) modelMap);
             return ViewNames.ADMIN_USERDETAIL;
         }
         userService.updateUserProfile(user);
+        modelMap.clear();
         status.setComplete();
-        return "redirect:" + user.getEntityId();
+        return "redirect:/app/admin/users?action=update";
     }
 
+    @RequestMapping(value = "/admin/userdetail/delete", method = RequestMethod.POST)
+    public String deleteUserDetail(@ModelAttribute("user") User user,
+                                   @ModelAttribute(ModelKeys.TOKENCHECK) String sessionToken,
+                                   @RequestParam String token,
+                                   @RequestParam(required = false) String confirmdelete,
+                                   ModelMap modelMap,
+                                   SessionStatus status) {
+        AdminControllerUtil.checkTokens(sessionToken, token, status);
+        if (!Boolean.parseBoolean(confirmdelete)) {
+            AdminControllerUtil.addNavigationMenusToModel(SELECTED_ITEM, (Model) modelMap);
+            modelMap.addAttribute("missingConfirm", true);
+            return ViewNames.ADMIN_USERDETAIL;
+        }
+        userService.deleteUser(user.getEntityId());
+        modelMap.clear();
+        status.setComplete();
+        return "redirect:/app/admin/users?action=delete";
+    }
+    
     @ModelAttribute("authorities")
     public SearchResult<Authority> populateAuthorityList() {
         return authorityService.getAllAuthorities();

Modified: incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/WidgetController.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/WidgetController.java?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/WidgetController.java
(original)
+++ incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/admin/WidgetController.java
Thu Nov  3 15:53:30 2011
@@ -29,6 +29,7 @@ import org.apache.rave.portal.web.valida
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
+import org.springframework.ui.ModelMap;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.WebDataBinder;
 import org.springframework.web.bind.annotation.InitBinder;
@@ -64,14 +65,25 @@ public class WidgetController {
     }
 
     @RequestMapping(value = "/admin/widgets", method = RequestMethod.GET)
-    public String viewWidgets(@RequestParam(required = false, defaultValue = "0") int offset,
Model model) {
+    public String viewWidgets(@RequestParam(required = false, defaultValue = "0") int offset,
+                              @RequestParam(required = false) final String action,
+                              Model model) {
         AdminControllerUtil.addNavigationMenusToModel(SELECTED_ITEM, model);
         final SearchResult<Widget> widgets =
                 widgetService.getLimitedListOfWidgets(offset, DEFAULT_PAGE_SIZE);
         model.addAttribute(ModelKeys.SEARCHRESULT, widgets);
+
+        if (isDeleteOrUpdate(action)) {
+            model.addAttribute("actionresult", action);
+        }
+
         return ViewNames.ADMIN_WIDGETS;
     }
 
+    private boolean isDeleteOrUpdate(String action) {
+        return "update".equals(action) || "delete".equals(action);
+    }
+
     @RequestMapping(value = "/admin/widgets/search", method = RequestMethod.GET)
     public String searchWidgets(@RequestParam(required = false) String searchTerm,
                                 @RequestParam(required = false) String widgettype,
@@ -98,16 +110,19 @@ public class WidgetController {
     @RequestMapping(value = "/admin/widgetdetail/update", method = RequestMethod.POST)
     public String updateWidgetDetail(@ModelAttribute(ModelKeys.WIDGET) Widget widget, BindingResult
result,
                                      @ModelAttribute(ModelKeys.TOKENCHECK) String sessionToken,
-                                     @RequestParam() String token,
+                                     @RequestParam String token,
+                                     ModelMap modelMap,
                                      SessionStatus status) {
         AdminControllerUtil.checkTokens(sessionToken, token, status);
         widgetValidator.validate(widget, result);
         if (result.hasErrors()) {
+            AdminControllerUtil.addNavigationMenusToModel(SELECTED_ITEM, (Model) modelMap);
             return ViewNames.ADMIN_WIDGETDETAIL;
         }
         widgetService.updateWidget(widget);
+        modelMap.clear();
         status.setComplete();
-        return "redirect:" + widget.getEntityId();
+        return "redirect:/app/admin/widgets?action=update";
     }
 
     @ModelAttribute("widgetStatus")

Modified: incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/UserControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/UserControllerTest.java?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/UserControllerTest.java
(original)
+++ incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/UserControllerTest.java
Thu Nov  3 15:53:30 2011
@@ -31,6 +31,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.springframework.ui.ExtendedModelMap;
 import org.springframework.ui.Model;
+import org.springframework.ui.ModelMap;
 import org.springframework.validation.BeanPropertyBindingResult;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.support.SessionStatus;
@@ -64,12 +65,13 @@ public class UserControllerTest {
         Model model = new ExtendedModelMap();
         final int offset = 0;
         final int pageSize = 10;
+        final String referer = "http://example.com/index.html";
         SearchResult<User> searchResult = createSearchResultWithTwoUsers();
 
         expect(userService.getLimitedListOfUsers(offset, pageSize)).andReturn(searchResult);
         replay(userService);
 
-        String adminUsersView = controller.viewUsers(offset, model);
+        String adminUsersView = controller.viewUsers(offset, referer, model);
         assertEquals(ViewNames.ADMIN_USERS, adminUsersView);
         assertEquals(searchResult, model.asMap().get(ModelKeys.SEARCHRESULT));
         assertTrue(model.containsAttribute(TABS));
@@ -115,6 +117,7 @@ public class UserControllerTest {
 
     @Test
     public void updateUserDetail_success() {
+        ModelMap modelMap = new ExtendedModelMap();
         final Long userid = 123L;
         final String email = "john.doe.sr@example.net";
         User user = new User(userid, "john.doe.sr");
@@ -131,22 +134,23 @@ public class UserControllerTest {
         expectLastCall();
         replay(userService, sessionStatus);
 
-        final String view = controller.updateUserDetail(user, errors, validToken, validToken,
sessionStatus);
+        final String view = controller.updateUserDetail(user, errors, validToken, validToken,
modelMap, sessionStatus);
         verify(userService, sessionStatus);
 
         assertFalse(errors.hasErrors());
-        assertEquals("redirect:" + userid, view);
+        assertEquals("redirect:/app/admin/users?action=update", view);
     }
 
     @Test
     public void updateUserDetail_withErrors() {
+        ModelMap modelMap = new ExtendedModelMap();
         Long userid = 123L;
         User user = new User(userid, "john.doe.sr");
         final BindingResult errors = new BeanPropertyBindingResult(user, "user");
 
         SessionStatus sessionStatus = createMock(SessionStatus.class);
         replay(sessionStatus);
-        final String view = controller.updateUserDetail(user, errors, validToken, validToken,
sessionStatus);
+        final String view = controller.updateUserDetail(user, errors, validToken, validToken,
modelMap, sessionStatus);
         verify(sessionStatus);
 
         assertTrue(errors.hasErrors());
@@ -155,6 +159,7 @@ public class UserControllerTest {
 
     @Test(expected = SecurityException.class)
     public void updateUserDetail_wrongToken() {
+        ModelMap modelMap = new ExtendedModelMap();
         User user = new User(123L, "john.doe.sr");
         final BindingResult errors = new BeanPropertyBindingResult(user, "user");
         SessionStatus sessionStatus = createMock(SessionStatus.class);
@@ -165,7 +170,62 @@ public class UserControllerTest {
 
         String otherToken = AdminControllerUtil.generateSessionToken();
 
-        controller.updateUserDetail(user, errors, validToken, otherToken, sessionStatus);
+        controller.updateUserDetail(user, errors, validToken, otherToken, modelMap, sessionStatus);
+        verify(sessionStatus);
+
+        assertFalse("SecurityException", true);
+
+    }
+    @Test
+    public void deleteUserDetail_success() {
+        ModelMap modelMap = new ExtendedModelMap();
+        final Long userid = 123L;
+        final String email = "john.doe.sr@example.net";
+        User user = new User(userid, "john.doe.sr");
+        user.setPassword("secrect");
+        user.setConfirmPassword(user.getConfirmPassword());
+        user.setEmail(email);
+
+        SessionStatus sessionStatus = createMock(SessionStatus.class);
+
+        userService.deleteUser(user.getEntityId());
+        sessionStatus.setComplete();
+        expectLastCall();
+        replay(userService, sessionStatus);
+
+        final String view = controller.deleteUserDetail(user, validToken, validToken, "true",
modelMap, sessionStatus);
+        verify(userService, sessionStatus);
+
+        assertEquals("redirect:/app/admin/users?action=delete", view);
+    }
+
+    @Test
+    public void deleteUserDetail_noConfirmChecked() {
+        ModelMap modelMap = new ExtendedModelMap();
+        Long userid = 123L;
+        User user = new User(userid, "john.doe.sr");
+
+        SessionStatus sessionStatus = createMock(SessionStatus.class);
+        replay(sessionStatus);
+        final String view = controller.deleteUserDetail(user, validToken, validToken, null,
modelMap, sessionStatus);
+        verify(sessionStatus);
+
+        assertEquals(ViewNames.ADMIN_USERDETAIL, view);
+    }
+
+    @Test(expected = SecurityException.class)
+    public void deleteUserDetail_wrongToken() {
+        ModelMap modelMap = new ExtendedModelMap();
+        User user = new User(123L, "john.doe.sr");
+        SessionStatus sessionStatus = createMock(SessionStatus.class);
+        sessionStatus.setComplete();
+
+        expectLastCall();
+        replay(sessionStatus);
+
+        String otherToken = AdminControllerUtil.generateSessionToken();
+
+        controller.deleteUserDetail(user, validToken, otherToken, "true", modelMap, sessionStatus);
         verify(sessionStatus);
 
         assertFalse("SecurityException", true);

Modified: incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/WidgetControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/WidgetControllerTest.java?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/WidgetControllerTest.java
(original)
+++ incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/admin/WidgetControllerTest.java
Thu Nov  3 15:53:30 2011
@@ -29,6 +29,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.springframework.ui.ExtendedModelMap;
 import org.springframework.ui.Model;
+import org.springframework.ui.ModelMap;
 import org.springframework.validation.BeanPropertyBindingResult;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.support.SessionStatus;
@@ -66,7 +67,7 @@ public class WidgetControllerTest {
         SearchResult<Widget> widgetSearchResult = populateWidgetSearchResult();
         expect(service.getLimitedListOfWidgets(DEFAULT_OFFSET, DEFAULT_PAGESIZE)).andReturn(widgetSearchResult);
         replay(service);
-        String adminWidgetsView = controller.viewWidgets(DEFAULT_OFFSET, model);
+        String adminWidgetsView = controller.viewWidgets(DEFAULT_OFFSET, null, model);
         verify(service);
         assertEquals(ViewNames.ADMIN_WIDGETS, adminWidgetsView);
         assertEquals(widgetSearchResult, model.asMap().get(ModelKeys.SEARCHRESULT));
@@ -119,16 +120,17 @@ public class WidgetControllerTest {
         widget.setType("OpenSocial");
         BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
         SessionStatus sessionStatus = createMock(SessionStatus.class);
+        ModelMap modelMap = new ExtendedModelMap();
 
         service.updateWidget(widget);
         sessionStatus.setComplete();
         expectLastCall();
         replay(service, sessionStatus);
-        String view = controller.updateWidgetDetail(widget, errors, validToken, validToken,
sessionStatus);
+        String view = controller.updateWidgetDetail(widget, errors, validToken, validToken,
modelMap, sessionStatus);
         verify(service, sessionStatus);
 
         assertFalse("No errors", errors.hasErrors());
-        assertEquals("redirect:123", view);
+        assertEquals("redirect:/app/admin/widgets?action=update", view);
 
     }
 
@@ -137,6 +139,7 @@ public class WidgetControllerTest {
         Widget widget = new Widget();
         BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
         SessionStatus sessionStatus = createMock(SessionStatus.class);
+        ModelMap modelMap = new ExtendedModelMap();
 
         sessionStatus.setComplete();
         expectLastCall();
@@ -144,7 +147,7 @@ public class WidgetControllerTest {
 
         String otherToken = AdminControllerUtil.generateSessionToken();
 
-        controller.updateWidgetDetail(widget, errors, "sessionToken", otherToken, sessionStatus);
+        controller.updateWidgetDetail(widget, errors, "sessionToken", otherToken, modelMap,
sessionStatus);
 
         verify(sessionStatus);
         assertFalse("Can't come here", true);
@@ -155,8 +158,9 @@ public class WidgetControllerTest {
         Widget widget = new Widget(123L, "http://broken/url");
         BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
         SessionStatus sessionStatus = createMock(SessionStatus.class);
+        ModelMap modelMap = new ExtendedModelMap();
 
-        String view = controller.updateWidgetDetail(widget, errors, validToken, validToken,
sessionStatus);
+        String view = controller.updateWidgetDetail(widget, errors, validToken, validToken,
modelMap, sessionStatus);
 
         assertTrue("Errors", errors.hasErrors());
         assertEquals(ViewNames.ADMIN_WIDGETDETAIL, view);

Modified: incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties Thu
Nov  3 15:53:30 2011
@@ -127,6 +127,8 @@ admin.users.add=Add user
 admin.userdetail.title=Rave admin interface - User detail
 admin.userdetail.goback=\u00AB Back to users
 admin.userdetail.editdata=Edit user data
+admin.userdetail.action.delete.success=The user profile has been removed
+admin.userdetail.action.update.success=The user profile has been updated
 admin.userdata.username=Username
 admin.userdata.email=Email
 admin.userdata.accountstatus=Account status:
@@ -141,6 +143,8 @@ admin.widgetdetail.title=Rave admin inte
 admin.widgetdetail.goback=\u00AB Back to widgets
 admin.widgetdetail.editdata=Edit widget data
 admin.widgetdetail.updatebutton=Update widget
+admin.widgetdetail.action.delete.success=The widget has been removed
+admin.widgetdetail.action.update.success=The widget has been updated
 admin.clearsearch=Clear search
 
 admin.list.noresult=No results found

Modified: incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties Thu
Nov  3 15:53:30 2011
@@ -127,6 +127,8 @@ admin.users.add=Voeg Gebruiker toe
 admin.userdetail.title=Rave admin interface - Gebruiker details
 admin.userdetail.goback=\u00AB Terug naar gebruikers
 admin.userdetail.editdata=Pas gebruikers gegevens aan
+admin.userdetail.action.delete.success=Het gebruikersprofiel is verwijderd
+admin.userdetail.action.update.success=Het gebruikersprofiel is bijgewerkt
 admin.userdata.username=Gebruikersnaam
 admin.userdata.email=Email
 admin.userdata.accountstatus=Account status:
@@ -141,6 +143,8 @@ admin.widgetdetail.title=Rave admin inte
 admin.widgetdetail.goback=\u00AB Terug naar widgets
 admin.widgetdetail.editdata=Pas widget gegevens aan
 admin.widgetdetail.updatebutton=Update widget
+admin.widgetdetail.action.delete.success=De widget is verwijderd
+admin.widgetdetail.action.update.success=De widget is bijgewerkt
 admin.clearsearch=Maak zoekveld leeg
 
 admin.list.noresult=Geen resultaten gevonden

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/userdetail.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/userdetail.jsp?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/userdetail.jsp
(original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/userdetail.jsp
Thu Nov  3 15:53:30 2011
@@ -41,7 +41,30 @@
             <h2><c:out value="${user.username}"/></h2>
 
             <div class="rightcolumn">
-
+                <%--<section class="formbox">
+                    <h3>_Delete <c:out value=" ${user.username}"/></h3>
+                    <form:form id="deleteUserProfile" action="delete" commandName="user"
method="POST">
+                        <fieldset>
+                            <input type="hidden" name="token" value="<c:out value="${tokencheck}"/>"/>
+                            <div>
+                                <ul class="checkboxlist">
+                                    <li>
+                                        <input type="checkbox" name="confirmdelete" id="confirmdelete"
value="true"/>
+                                        <label for="confirmdelete"> _Yes I want to
delete this user</label>
+                                        <c:if test="${missingConfirm}">
+                                            <p class="error">_Please check</p>
+                                        </c:if>
+                                    </li>
+                                </ul>
+                            </div>
+                            </fieldset>
+                        <fieldset>
+                            <p>
+                                <input type="submit" value="Delete the user"/>
+                            </p>
+                        </fieldset>
+                    </form:form>
+                </section>--%>
             </div>
 
             <div class="leftcolumn">

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/users.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/users.jsp?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/users.jsp
(original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/users.jsp
Thu Nov  3 15:53:30 2011
@@ -32,6 +32,14 @@
 
     <div class="pageContent">
         <article class="admincontent">
+            <c:if test="${actionresult eq 'delete' or actionresult eq 'update'}">
+                <div class="alert-message success">
+                    <p>
+                        <fmt:message key="admin.userdetail.action.${actionresult}.success"/>
+                    </p>
+                </div>
+            </c:if>
+
             <ul class="horizontal-list searchbox">
                 <li><a href="<spring:url value="/app/newaccount.jsp"/>"><fmt:message
key="admin.users.add"/></a></li>
                 <li>

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/widgets.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/widgets.jsp?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/widgets.jsp
(original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/views/admin/widgets.jsp
Thu Nov  3 15:53:30 2011
@@ -31,6 +31,13 @@
     <rave:admin_tabsheader/>
     <div class="pageContent">
         <article class="admincontent">
+            <c:if test="${actionresult eq 'delete' or actionresult eq 'update'}">
+                <div class="alert-message success">
+                    <p>
+                        <fmt:message key="admin.widgetdetail.action.${actionresult}.success"/>
+                    </p>
+                </div>
+            </c:if>
             <ul class="horizontal-list searchbox">
                 <li>
                     <form action="<spring:url value="/app/admin/widgets/search"/>"
method="GET">

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/css/default.css
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/css/default.css?rev=1197192&r1=1197191&r2=1197192&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/css/default.css (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/css/default.css Thu Nov  3
15:53:30 2011
@@ -624,7 +624,7 @@ span.error, label.error {
 .admincontent {
     margin: 0 auto;
     width: 80%;
-    padding:0 20px;
+    padding:1em 20px;
     font-size:1.1em;
 }
 
@@ -768,9 +768,64 @@ span.error, label.error {
 .booleancell {
     width: 50px;
 }
+
 .textcell {
     width: 150px;
 }
+
 .largetextcell {
     width: 300px
 }
+
+.alert-message {
+    color: #FFFFFF;
+    position: relative;
+    padding: 7px 15px;
+    margin-top: 1em;
+    margin-bottom: 1em;
+    background-color: #eedc94;
+    background-repeat: repeat-x;
+    background-image: -moz-linear-gradient(top, #fceec1, #eedc94);
+    background-image: -ms-linear-gradient(top, #fceec1, #eedc94);
+    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fceec1),
color-stop(100%, #eedc94));
+    background-image: -webkit-linear-gradient(top, #fceec1, #eedc94);
+    background-image: linear-gradient(top, #fceec1, #eedc94);
+    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#fceec1', endColorstr
= '#eedc94', GradientType = 0);
+    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
+    border-color: #eedc94 #eedc94 #e4c652;
+    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
+    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
+    border-width: 1px;
+    border-style: solid;
+    -webkit-border-radius: 4px;
+    -moz-border-radius: 4px;
+    border-radius: 4px;
+    -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
+    -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
+    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
+}
+
+.alert-message p {
+    margin: 0;
+}
+
+.alert-message div {
+    margin-top: 5px;
+    margin-bottom: 2px;
+    line-height: 28px;
+}
+
+.alert-message.success {
+    background-color: #57a957;
+    background-repeat: repeat-x;
+    background-image: -moz-linear-gradient(top, #62c462, #57a957);
+    background-image: -ms-linear-gradient(top, #62c462, #57a957);
+    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #62c462),
color-stop(100%, #57a957));
+    background-image: -webkit-linear-gradient(top, #62c462, #57a957);
+    background-image: -o-linear-gradient(top, #62c462, #57a957);
+    background-image: linear-gradient(top, #62c462, #57a957);
+    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#62c462', endColorstr
= '#57a957', GradientType = 0);
+    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
+    border-color: #57a957 #57a957 #3d773d;
+    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
+}
\ No newline at end of file



Mime
View raw message