[kune-commits] r833 - in trunk/src/main/java/org/ourproject/kune: platf/client/services platf/server platf/server/access platf/server/auth platf/server/manager/impl platf/server/rpc workspace/client/socialnet

vjrj vjrj at ourproject.org
Thu Aug 7 14:07:11 CEST 2008


Author: vjrj
Date: 2008-08-07 14:07:05 +0200 (Thu, 07 Aug 2008)
New Revision: 833

Added:
   trunk/src/main/java/org/ourproject/kune/platf/server/auth/GroupAuthorizated.java
   trunk/src/main/java/org/ourproject/kune/platf/server/auth/GroupAuthorizatedMethodInterceptor.java
Modified:
   trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java
   trunk/src/main/java/org/ourproject/kune/platf/server/PlatformServerModule.java
   trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessRightsService.java
   trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessRightsServiceDefault.java
   trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessServiceDefault.java
   trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/GroupManagerDefault.java
   trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/SocialNetworkManagerDefault.java
   trunk/src/main/java/org/ourproject/kune/platf/server/rpc/GroupRPC.java
   trunk/src/main/java/org/ourproject/kune/platf/server/rpc/SocialNetworkRPC.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/socialnet/GroupMembersSummaryPresenter.java
Log:
Group authorization annotation for check authRights in methods 


Modified: trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/services/KuneModule.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -501,7 +501,7 @@
 	    public GroupMembersSummary create() {
 		final GroupMembersSummaryPresenter presenter = new GroupMembersSummaryPresenter(i18n,
 			$(StateManager.class), $(ImageUtils.class), $(Session.class),
-			$$(SocialNetworkServiceAsync.class), $$(UserLiveSearcher.class), $(WsThemePresenter.class));
+			$$(SocialNetworkServiceAsync.class), $$(GroupLiveSearcher.class), $(WsThemePresenter.class));
 		final GroupMembersSummaryView view = new GroupMembersSummaryPanel(presenter, i18n, ws);
 		presenter.init(view);
 		return presenter;

Modified: trunk/src/main/java/org/ourproject/kune/platf/server/PlatformServerModule.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/PlatformServerModule.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/PlatformServerModule.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -31,6 +31,8 @@
 import org.ourproject.kune.platf.client.rpc.SiteService;
 import org.ourproject.kune.platf.client.rpc.SocialNetworkService;
 import org.ourproject.kune.platf.client.services.I18nTranslationService;
+import org.ourproject.kune.platf.server.access.AccessRightsService;
+import org.ourproject.kune.platf.server.access.AccessRightsServiceDefault;
 import org.ourproject.kune.platf.server.access.AccessService;
 import org.ourproject.kune.platf.server.access.AccessServiceDefault;
 import org.ourproject.kune.platf.server.access.FinderService;
@@ -39,6 +41,8 @@
 import org.ourproject.kune.platf.server.auth.AuthenticatedMethodInterceptor;
 import org.ourproject.kune.platf.server.auth.Authorizated;
 import org.ourproject.kune.platf.server.auth.AuthorizatedMethodInterceptor;
+import org.ourproject.kune.platf.server.auth.GroupAuthorizated;
+import org.ourproject.kune.platf.server.auth.GroupAuthorizatedMethodInterceptor;
 import org.ourproject.kune.platf.server.auth.SessionService;
 import org.ourproject.kune.platf.server.auth.SessionServiceDefault;
 import org.ourproject.kune.platf.server.content.CommentManager;
@@ -94,55 +98,58 @@
 public class PlatformServerModule extends AbstractExtendedModule {
     @Override
     protected void configure() {
-        install(PersistenceService.usingJpa().across(UnitOfWork.TRANSACTION).buildModule());
-        bind(KunePersistenceService.class);
+	install(PersistenceService.usingJpa().across(UnitOfWork.TRANSACTION).buildModule());
+	bind(KunePersistenceService.class);
 
-        bindManagers();
-        bindRPC();
-        bindServices();
-        bind(KuneProperties.class).to(KunePropertiesDefault.class);
-        bind(Mapper.class).to(DozerMapper.class);
-        bind(ToolRegistry.class);
+	bindManagers();
+	bindRPC();
+	bindServices();
+	bind(KuneProperties.class).to(KunePropertiesDefault.class);
+	bind(Mapper.class).to(DozerMapper.class);
+	bind(ToolRegistry.class);
 
-        bindInterceptor(Matchers.any(), Matchers.annotatedWith(Authenticated.class),
-                outermostCall(new AuthenticatedMethodInterceptor()));
-        bindInterceptor(Matchers.any(), Matchers.annotatedWith(Authorizated.class),
-                outermostCall(new AuthorizatedMethodInterceptor()));
+	bindInterceptor(Matchers.any(), Matchers.annotatedWith(Authenticated.class),
+		outermostCall(new AuthenticatedMethodInterceptor()));
+	bindInterceptor(Matchers.any(), Matchers.annotatedWith(Authorizated.class),
+		outermostCall(new AuthorizatedMethodInterceptor()));
+	bindInterceptor(Matchers.any(), Matchers.annotatedWith(GroupAuthorizated.class),
+		outermostCall(new GroupAuthorizatedMethodInterceptor()));
     }
 
     private void bindManagers() {
-        bind(UserManager.class).to(UserManagerDefault.class);
-        bind(GroupManager.class).to(GroupManagerDefault.class);
-        bind(ContentManager.class).to(ContentManagerDefault.class);
-        bind(ToolConfigurationManager.class).to(ToolConfigurationManagerDefault.class);
-        bind(ContainerManager.class).to(ContainerManagerDefault.class);
-        bind(LicenseManager.class).to(LicenseManagerDefault.class);
-        bind(SocialNetworkManager.class).to(SocialNetworkManagerDefault.class);
-        bind(XmppManager.class).to(XmppManagerDefault.class);
-        bind(RateManager.class).to(RateManagerDefault.class);
-        bind(I18nCountryManager.class).to(I18nCountryManagerDefault.class);
-        bind(I18nLanguageManager.class).to(I18nLanguageManagerDefault.class);
-        bind(I18nTranslationManager.class).to(I18nTranslationManagerDefault.class);
-        bind(TagManager.class).to(TagManagerDefault.class);
-        bind(CommentManager.class).to(CommentManagerDefault.class);
+	bind(UserManager.class).to(UserManagerDefault.class);
+	bind(GroupManager.class).to(GroupManagerDefault.class);
+	bind(ContentManager.class).to(ContentManagerDefault.class);
+	bind(ToolConfigurationManager.class).to(ToolConfigurationManagerDefault.class);
+	bind(ContainerManager.class).to(ContainerManagerDefault.class);
+	bind(LicenseManager.class).to(LicenseManagerDefault.class);
+	bind(SocialNetworkManager.class).to(SocialNetworkManagerDefault.class);
+	bind(XmppManager.class).to(XmppManagerDefault.class);
+	bind(RateManager.class).to(RateManagerDefault.class);
+	bind(I18nCountryManager.class).to(I18nCountryManagerDefault.class);
+	bind(I18nLanguageManager.class).to(I18nLanguageManagerDefault.class);
+	bind(I18nTranslationManager.class).to(I18nTranslationManagerDefault.class);
+	bind(TagManager.class).to(TagManagerDefault.class);
+	bind(CommentManager.class).to(CommentManagerDefault.class);
     }
 
     private void bindRPC() {
-        bind(SiteService.class).to(SiteRPC.class);
-        bind(GroupService.class).to(GroupRPC.class);
-        bind(ContentService.class).to(ContentRPC.class);
-        bind(UserService.class).to(UserRPC.class);
-        bind(SocialNetworkService.class).to(SocialNetworkRPC.class);
-        bind(I18nService.class).to(I18nRPC.class);
+	bind(SiteService.class).to(SiteRPC.class);
+	bind(GroupService.class).to(GroupRPC.class);
+	bind(ContentService.class).to(ContentRPC.class);
+	bind(UserService.class).to(UserRPC.class);
+	bind(SocialNetworkService.class).to(SocialNetworkRPC.class);
+	bind(I18nService.class).to(I18nRPC.class);
     }
 
     private void bindServices() {
-        bind(UserInfoService.class).to(UserInfoServiceDefault.class);
-        bind(CreationService.class).to(CreationServiceDefault.class);
-        bind(AccessService.class).to(AccessServiceDefault.class);
-        bind(FinderService.class).to(FinderServiceDefault.class);
-        bind(StateService.class).to(StateServiceDefault.class);
-        bind(I18nTranslationService.class).to(I18nTranslationServiceDefault.class);
-        bind(SessionService.class).to(SessionServiceDefault.class);
+	bind(UserInfoService.class).to(UserInfoServiceDefault.class);
+	bind(CreationService.class).to(CreationServiceDefault.class);
+	bind(AccessRightsService.class).to(AccessRightsServiceDefault.class);
+	bind(AccessService.class).to(AccessServiceDefault.class);
+	bind(FinderService.class).to(FinderServiceDefault.class);
+	bind(StateService.class).to(StateServiceDefault.class);
+	bind(I18nTranslationService.class).to(I18nTranslationServiceDefault.class);
+	bind(SessionService.class).to(SessionServiceDefault.class);
     }
 }

Modified: trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessRightsService.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessRightsService.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessRightsService.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -23,7 +23,7 @@
 import org.ourproject.kune.platf.server.domain.AccessLists;
 import org.ourproject.kune.platf.server.domain.User;
 
-interface AccessRightsService {
+public interface AccessRightsService {
 
     public AccessRights get(User user, AccessLists lists);
 

Modified: trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessRightsServiceDefault.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessRightsServiceDefault.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessRightsServiceDefault.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -29,52 +29,55 @@
 import org.ourproject.kune.platf.server.domain.SocialNetwork;
 import org.ourproject.kune.platf.server.domain.User;
 
+import com.google.inject.Singleton;
+
+ at Singleton
 public class AccessRightsServiceDefault implements AccessRightsService {
     // TODO: check performance
 
-    public AccessRights get(final User user, final AccessLists lists) {
-        return get(user.getUserGroup(), lists);
-    }
-
     public AccessRights get(final Group userGroup, final AccessLists accessList) {
-        boolean isAdministrable = false;
-        boolean isEditable = false;
-        boolean isVisible = false;
+	boolean isAdministrable = false;
+	boolean isEditable = false;
+	boolean isVisible = false;
 
-        // FIXME, future: admin users can admin, edit, view everything
-        // (not now while we are doing tests)
-        isVisible = isEditable = isAdministrable = canAccess(userGroup, accessList, AccessRol.Administrator);
-        if (!isEditable) {
-            isVisible = isEditable = canAccess(userGroup, accessList, AccessRol.Editor);
-        }
-        if (!isVisible) {
-            isVisible = accessList.getViewers().isEmpty() || canAccess(userGroup, accessList, AccessRol.Viewer);
-        }
+	// FIXME, future: admin users can admin, edit, view everything
+	// (not now while we are doing tests)
+	isVisible = isEditable = isAdministrable = canAccess(userGroup, accessList, AccessRol.Administrator);
+	if (!isEditable) {
+	    isVisible = isEditable = canAccess(userGroup, accessList, AccessRol.Editor);
+	}
+	if (!isVisible) {
+	    isVisible = accessList.getViewers().isEmpty() || canAccess(userGroup, accessList, AccessRol.Viewer);
+	}
 
-        return new AccessRights(isAdministrable, isEditable, isVisible);
+	return new AccessRights(isAdministrable, isEditable, isVisible);
     }
 
+    public AccessRights get(final User user, final AccessLists lists) {
+	return get(user.getUserGroup(), lists);
+    }
+
     private boolean canAccess(final Group searchedGroup, final AccessLists lists, final AccessRol rol) {
-        GroupList list = lists.getList(rol);
-        return depthFirstSearch(new HashSet<Group>(), searchedGroup, list, rol);
+	final GroupList list = lists.getList(rol);
+	return depthFirstSearch(new HashSet<Group>(), searchedGroup, list, rol);
     }
 
     /*
      * http://en.wikipedia.org/wiki/Depth-first_search
      */
     private boolean depthFirstSearch(final HashSet<Group> visited, final Group searchedGroup, final GroupList list,
-            final AccessRol rol) {
-        if (list.includes(searchedGroup)) {
-            return true;
-        }
-        ArrayList<Group> noVisitedYet = list.duplicate();
-        noVisitedYet.removeAll(visited);
-        for (Group group : noVisitedYet) {
-            visited.add(group);
-            SocialNetwork socialNetwork = group.getSocialNetwork();
-            GroupList groupList = socialNetwork.getAccessLists().getList(rol);
-            return depthFirstSearch(visited, searchedGroup, groupList, rol);
-        }
-        return false;
+	    final AccessRol rol) {
+	if (list.includes(searchedGroup)) {
+	    return true;
+	}
+	final ArrayList<Group> noVisitedYet = list.duplicate();
+	noVisitedYet.removeAll(visited);
+	for (final Group group : noVisitedYet) {
+	    visited.add(group);
+	    final SocialNetwork socialNetwork = group.getSocialNetwork();
+	    final GroupList groupList = socialNetwork.getAccessLists().getList(rol);
+	    return depthFirstSearch(visited, searchedGroup, groupList, rol);
+	}
+	return false;
     }
 }

Modified: trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessServiceDefault.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessServiceDefault.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/access/AccessServiceDefault.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -41,6 +41,7 @@
     private final AccessRightsService accessRightsService;
     private final Group groupFinder;
 
+    @Inject
     public AccessServiceDefault(final FinderService finder, final AccessRightsService accessRightsService,
 	    final Group groupFinder) {
 	this.finder = finder;
@@ -48,11 +49,6 @@
 	this.groupFinder = groupFinder;
     }
 
-    @Inject
-    public AccessServiceDefault(final FinderService finder, final Group groupFinder) {
-	this(finder, new AccessRightsServiceDefault(), groupFinder);
-    }
-
     public Content accessToContent(final Long contentId, final User user, final AccessType accessType)
 	    throws DefaultException {
 	final Content descriptor = finder.getContent(contentId);

Added: trunk/src/main/java/org/ourproject/kune/platf/server/auth/GroupAuthorizated.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/auth/GroupAuthorizated.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/auth/GroupAuthorizated.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -0,0 +1,24 @@
+package org.ourproject.kune.platf.server.auth;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.ourproject.kune.platf.server.access.AccessType;
+
+import com.google.inject.BindingAnnotation;
+
+/**
+ * Use in RPC methods, for instance: <code>
+ * GroupAuthorizated(authLevelRequired = AuthLevelRequired.COLLAB) </code>
+ * 
+ * The first parameter in the method must be the userHash, the second the group
+ * shortName
+ * 
+ */
+ at BindingAnnotation
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface GroupAuthorizated {
+
+    AccessType accessTypeRequired() default AccessType.READ;
+
+}

Added: trunk/src/main/java/org/ourproject/kune/platf/server/auth/GroupAuthorizatedMethodInterceptor.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/auth/GroupAuthorizatedMethodInterceptor.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/auth/GroupAuthorizatedMethodInterceptor.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -0,0 +1,89 @@
+/*
+ *
+ * Copyright (C) 2007-2008 The kune development team (see CREDITS for details)
+ * This file is part of kune.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.ourproject.kune.platf.server.auth;
+
+import javax.persistence.NoResultException;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.ourproject.kune.platf.client.errors.AccessViolationException;
+import org.ourproject.kune.platf.server.UserSession;
+import org.ourproject.kune.platf.server.access.AccessRights;
+import org.ourproject.kune.platf.server.access.AccessRightsService;
+import org.ourproject.kune.platf.server.access.AccessType;
+import org.ourproject.kune.platf.server.domain.Group;
+import org.ourproject.kune.platf.server.domain.User;
+import org.ourproject.kune.platf.server.manager.GroupManager;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+public class GroupAuthorizatedMethodInterceptor implements MethodInterceptor {
+
+    @Inject
+    Provider<UserSession> userSessionProvider;
+    @Inject
+    Provider<GroupManager> groupManagerProvider;
+    @Inject
+    Provider<AccessRightsService> accessRightsServiceProvider;
+
+    public Object invoke(final MethodInvocation invocation) throws Throwable {
+	final Object[] arguments = invocation.getArguments();
+	final String groupShortName = (String) arguments[1];
+
+	final UserSession userSession = userSessionProvider.get();
+	final GroupManager groupManager = groupManagerProvider.get();
+
+	final GroupAuthorizated authoAnnotation = invocation.getStaticPart().getAnnotation(GroupAuthorizated.class);
+	final AccessType accessType = authoAnnotation.accessTypeRequired();
+
+	final User user = userSession.getUser();
+
+	Group group = Group.NO_GROUP;
+	try {
+	    group = groupManager.findByShortName(groupShortName);
+	} catch (final NoResultException e) {
+	    throw new AccessViolationException();
+	}
+
+	if (!correctMember(user, group, accessType)) {
+	    throw new AccessViolationException();
+	}
+
+	final Object result = invocation.proceed();
+	return result;
+    }
+
+    private boolean correctMember(final User user, final Group group, final AccessType memberType)
+	    throws AccessViolationException {
+	final AccessRightsService accessRightsService = accessRightsServiceProvider.get();
+	final AccessRights accessRights = accessRightsService.get(user, group.getSocialNetwork().getAccessLists());
+
+	switch (memberType) {
+	case ADMIN:
+	    return accessRights.isAdministrable();
+	case EDIT:
+	    return accessRights.isEditable();
+	default:
+	    return accessRights.isVisible();
+	}
+    }
+
+}

Modified: trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/GroupManagerDefault.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/GroupManagerDefault.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/GroupManagerDefault.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -64,135 +64,131 @@
 
     @Inject
     public GroupManagerDefault(final Provider<EntityManager> provider, final Group finder, final User userFinder,
-            final KuneProperties kuneProperties, final DatabaseProperties properties, final ToolRegistry registry,
-            final License licenseFinder) {
-        super(provider, Group.class);
-        this.finder = finder;
-        this.userFinder = userFinder;
-        this.kuneProperties = kuneProperties;
-        this.properties = properties;
-        this.registry = registry;
-        this.licenseFinder = licenseFinder;
+	    final KuneProperties kuneProperties, final DatabaseProperties properties, final ToolRegistry registry,
+	    final License licenseFinder) {
+	super(provider, Group.class);
+	this.finder = finder;
+	this.userFinder = userFinder;
+	this.kuneProperties = kuneProperties;
+	this.properties = properties;
+	this.registry = registry;
+	this.licenseFinder = licenseFinder;
     }
 
-    public Group getDefaultGroup() {
-        final String shortName = properties.getDefaultSiteShortName();
-        return findByShortName(shortName);
+    public void changeWsTheme(final User user, final Group group, final String theme) throws AccessViolationException {
+	// TODO: check theme
+	group.setWorkspaceTheme(theme);
     }
 
-    public Group findByShortName(final String shortName) {
-        return finder.findByShortName(shortName);
+    public Group createGroup(final Group group, final User user) throws GroupNameInUseException,
+	    UserMustBeLoggedException {
+	final String defaultSiteWorkspaceTheme = kuneProperties.get(KuneProperties.WS_THEMES_DEF);
+	if (User.isKnownUser(user)) {
+	    if (group.getType().equals(GroupType.COMMUNITY)) {
+		group.setAdmissionType(AdmissionType.Open);
+	    } else if (group.getType().equals(GroupType.ORGANIZATION)) {
+		group.setAdmissionType(AdmissionType.Moderated);
+	    } else if (group.getType().equals(GroupType.PROJECT)) {
+		group.setAdmissionType(AdmissionType.Moderated);
+	    } else if (group.getType().equals(GroupType.ORPHANED_PROJECT)) {
+		group.setAdmissionType(AdmissionType.Open);
+	    }
+	    final String licName = group.getDefaultLicense().getShortName();
+	    final License license = licenseFinder.findByShortName(licName);
+	    group.setDefaultLicense(license);
+	    group.setWorkspaceTheme(defaultSiteWorkspaceTheme);
+	    initSocialNetwork(group, user.getUserGroup());
+	    initGroup(user, group);
+	    return group;
+	} else {
+	    throw new UserMustBeLoggedException();
+	}
+
     }
 
-    public List<Group> findAdminInGroups(final Long groupId) {
-        return finder.findAdminInGroups(groupId);
+    public Group createUserGroup(final User user) throws GroupNameInUseException, EmailAddressInUseException {
+	final String defaultSiteWorkspaceTheme = kuneProperties.get(KuneProperties.WS_THEMES_DEF);
+	final String licenseDefId = properties.getDefaultLicense();
+	final License licenseDef = licenseFinder.findByShortName(licenseDefId);
+	final Group group = new Group(user.getShortName(), user.getName(), licenseDef, GroupType.PERSONAL);
+	User userSameEmail = null;
+	try {
+	    userSameEmail = userFinder.getByEmail(user.getEmail());
+	} catch (final NoResultException e) {
+	    // Ok, no more with this email
+	}
+	if (userSameEmail != null) {
+	    throw new EmailAddressInUseException();
+	}
+	group.setAdmissionType(AdmissionType.Closed);
+	group.setWorkspaceTheme(defaultSiteWorkspaceTheme);
+	user.setUserGroup(group);
+	initSocialNetwork(group, group);
+	try {
+	    initGroup(user, group);
+	    super.persist(user, User.class);
+	} catch (final EntityExistsException e) {
+	    throw new GroupNameInUseException();
+	}
+	return group;
     }
 
-    public List<Group> findCollabInGroups(final Long groupId) {
-        return finder.findCollabInGroups(groupId);
+    public List<Group> findAdminInGroups(final Long groupId) {
+	return finder.findAdminInGroups(groupId);
     }
 
-    public Group createUserGroup(final User user) throws GroupNameInUseException, EmailAddressInUseException {
-        String defaultSiteWorkspaceTheme = kuneProperties.get(KuneProperties.WS_THEMES_DEF);
-        final String licenseDefId = properties.getDefaultLicense();
-        final License licenseDef = licenseFinder.findByShortName(licenseDefId);
-        final Group group = new Group(user.getShortName(), user.getName(), licenseDef, GroupType.PERSONAL);
-        User userSameEmail = null;
-        try {
-            userSameEmail = userFinder.getByEmail(user.getEmail());
-        } catch (NoResultException e) {
-            // Ok, no more with this email
-        }
-        if (userSameEmail != null) {
-            throw new EmailAddressInUseException();
-        }
-        group.setAdmissionType(AdmissionType.Closed);
-        group.setWorkspaceTheme(defaultSiteWorkspaceTheme);
-        user.setUserGroup(group);
-        initSocialNetwork(group, group);
-        try {
-            initGroup(user, group);
-            super.persist(user, User.class);
-        } catch (final EntityExistsException e) {
-            throw new GroupNameInUseException();
-        }
-        return group;
+    public Group findByShortName(final String shortName) {
+	return finder.findByShortName(shortName);
     }
 
-    public Group createGroup(final Group group, final User user) throws GroupNameInUseException,
-            UserMustBeLoggedException {
-        String defaultSiteWorkspaceTheme = kuneProperties.get(KuneProperties.WS_THEMES_DEF);
-        if (User.isKnownUser(user)) {
-            if (group.getType().equals(GroupType.COMMUNITY)) {
-                group.setAdmissionType(AdmissionType.Open);
-            } else if (group.getType().equals(GroupType.ORGANIZATION)) {
-                group.setAdmissionType(AdmissionType.Moderated);
-            } else if (group.getType().equals(GroupType.PROJECT)) {
-                group.setAdmissionType(AdmissionType.Moderated);
-            } else if (group.getType().equals(GroupType.ORPHANED_PROJECT)) {
-                group.setAdmissionType(AdmissionType.Open);
-            }
-            String licName = group.getDefaultLicense().getShortName();
-            License license = licenseFinder.findByShortName(licName);
-            group.setDefaultLicense(license);
-            group.setWorkspaceTheme(defaultSiteWorkspaceTheme);
-            initSocialNetwork(group, user.getUserGroup());
-            initGroup(user, group);
-            return group;
-        } else {
-            throw new UserMustBeLoggedException();
-        }
-
+    public List<Group> findCollabInGroups(final Long groupId) {
+	return finder.findCollabInGroups(groupId);
     }
 
-    public void changeWsTheme(final User user, final Group group, final String theme) throws AccessViolationException {
-        if (group.getSocialNetwork().isAdmin(user.getUserGroup())) {
-            group.setWorkspaceTheme(theme);
-            // Check themes...
-        } else {
-            throw new AccessViolationException();
-        }
+    public Group getDefaultGroup() {
+	final String shortName = properties.getDefaultSiteShortName();
+	return findByShortName(shortName);
     }
 
     public Group getGroupOfUserWithId(final Long userId) {
-        return userId != null ? find(User.class, userId).getUserGroup() : null;
+	return userId != null ? find(User.class, userId).getUserGroup() : null;
     }
 
     public SearchResult<Group> search(final String search) {
-        return this.search(search, null, null);
+	return this.search(search, null, null);
     }
 
     public SearchResult<Group> search(final String search, final Integer firstResult, final Integer maxResults) {
-        MultiFieldQueryParser parser = new MultiFieldQueryParser(
-                new String[] { "longName", "shortName", "publicDesc" }, new StandardAnalyzer());
-        Query query;
-        try {
-            query = parser.parse(search);
-        } catch (ParseException e) {
-            throw new RuntimeException("Error parsing search");
-        }
-        return super.search(query, firstResult, maxResults);
+	final MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[] { "longName", "shortName",
+		"publicDesc" }, new StandardAnalyzer());
+	Query query;
+	try {
+	    query = parser.parse(search);
+	} catch (final ParseException e) {
+	    throw new RuntimeException("Error parsing search");
+	}
+	return super.search(query, firstResult, maxResults);
     }
 
-    private void initSocialNetwork(final Group group, final Group userGroup) {
-        final SocialNetwork network = group.getSocialNetwork();
-        final AccessLists lists = network.getAccessLists();
-        lists.getEditors().setMode(GroupListMode.NOBODY);
-        lists.getViewers().setMode(GroupListMode.EVERYONE);
-        if (!group.getType().equals(GroupType.ORPHANED_PROJECT)) {
-            network.addAdmin(userGroup);
-        }
+    private void initGroup(final User user, final Group group) throws GroupNameInUseException {
+	try {
+	    persist(group);
+	} catch (final EntityExistsException e) {
+	    throw new GroupNameInUseException();
+	}
+	for (final ServerTool tool : registry.all()) {
+	    tool.initGroup(user, group);
+	}
     }
 
-    private void initGroup(final User user, final Group group) throws GroupNameInUseException {
-        try {
-            persist(group);
-        } catch (final EntityExistsException e) {
-            throw new GroupNameInUseException();
-        }
-        for (final ServerTool tool : registry.all()) {
-            tool.initGroup(user, group);
-        }
+    private void initSocialNetwork(final Group group, final Group userGroup) {
+	final SocialNetwork network = group.getSocialNetwork();
+	final AccessLists lists = network.getAccessLists();
+	lists.getEditors().setMode(GroupListMode.NOBODY);
+	lists.getViewers().setMode(GroupListMode.EVERYONE);
+	if (!group.getType().equals(GroupType.ORPHANED_PROJECT)) {
+	    network.addAdmin(userGroup);
+	}
     }
 
 }

Modified: trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/SocialNetworkManagerDefault.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/SocialNetworkManagerDefault.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/manager/impl/SocialNetworkManagerDefault.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -34,6 +34,7 @@
 import org.ourproject.kune.platf.client.errors.LastAdminInGroupException;
 import org.ourproject.kune.platf.client.errors.UserMustBeLoggedException;
 import org.ourproject.kune.platf.server.ParticipationData;
+import org.ourproject.kune.platf.server.access.AccessRightsService;
 import org.ourproject.kune.platf.server.domain.AdmissionType;
 import org.ourproject.kune.platf.server.domain.Group;
 import org.ourproject.kune.platf.server.domain.GroupListMode;
@@ -51,11 +52,14 @@
 public class SocialNetworkManagerDefault extends DefaultManager<SocialNetwork, Long> implements SocialNetworkManager {
 
     private final Group finder;
+    private final AccessRightsService accessRightsService;
 
     @Inject
-    public SocialNetworkManagerDefault(final Provider<EntityManager> provider, final Group finder) {
+    public SocialNetworkManagerDefault(final Provider<EntityManager> provider, final Group finder,
+	    final AccessRightsService accessRightsService) {
 	super(provider, SocialNetwork.class);
 	this.finder = finder;
+	this.accessRightsService = accessRightsService;
     }
 
     public void acceptJoinGroup(final User userLogged, final Group group, final Group inGroup) throws DefaultException,
@@ -252,7 +256,7 @@
     }
 
     private void checkUserLoggedIsAdmin(final User userLogged, final SocialNetwork sn) throws AccessViolationException {
-	if (!sn.isAdmin(userLogged.getUserGroup())) {
+	if (!accessRightsService.get(userLogged, sn.getAccessLists()).isAdministrable()) {
 	    throw new AccessViolationException();
 	}
     }

Modified: trunk/src/main/java/org/ourproject/kune/platf/server/rpc/GroupRPC.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/rpc/GroupRPC.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/rpc/GroupRPC.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -29,7 +29,7 @@
 import org.ourproject.kune.platf.server.UserSession;
 import org.ourproject.kune.platf.server.access.AccessType;
 import org.ourproject.kune.platf.server.auth.Authenticated;
-import org.ourproject.kune.platf.server.auth.Authorizated;
+import org.ourproject.kune.platf.server.auth.GroupAuthorizated;
 import org.ourproject.kune.platf.server.content.ContentManager;
 import org.ourproject.kune.platf.server.domain.Group;
 import org.ourproject.kune.platf.server.domain.User;
@@ -60,7 +60,7 @@
     }
 
     @Authenticated
-    @Authorizated(accessTypeRequired = AccessType.ADMIN)
+    @GroupAuthorizated(accessTypeRequired = AccessType.ADMIN)
     @Transactional(type = TransactionType.READ_WRITE, rollbackOn = DefaultException.class)
     public void changeGroupWsTheme(final String userHash, final String groupShortName, final String theme)
 	    throws DefaultException {

Modified: trunk/src/main/java/org/ourproject/kune/platf/server/rpc/SocialNetworkRPC.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/rpc/SocialNetworkRPC.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/rpc/SocialNetworkRPC.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -27,7 +27,7 @@
 import org.ourproject.kune.platf.server.UserSession;
 import org.ourproject.kune.platf.server.access.AccessType;
 import org.ourproject.kune.platf.server.auth.Authenticated;
-import org.ourproject.kune.platf.server.auth.Authorizated;
+import org.ourproject.kune.platf.server.auth.GroupAuthorizated;
 import org.ourproject.kune.platf.server.domain.Group;
 import org.ourproject.kune.platf.server.domain.User;
 import org.ourproject.kune.platf.server.manager.GroupManager;
@@ -58,7 +58,7 @@
     }
 
     @Authenticated
-    @Authorizated(accessTypeRequired = AccessType.ADMIN)
+    @GroupAuthorizated(accessTypeRequired = AccessType.ADMIN)
     @Transactional(type = TransactionType.READ_WRITE)
     public SocialNetworkResultDTO AcceptJoinGroup(final String hash, final String groupShortName,
 	    final String groupToAcceptShortName) throws DefaultException {
@@ -71,7 +71,7 @@
     }
 
     @Authenticated
-    @Authorizated(accessTypeRequired = AccessType.ADMIN)
+    @GroupAuthorizated(accessTypeRequired = AccessType.ADMIN)
     @Transactional(type = TransactionType.READ_WRITE)
     public SocialNetworkResultDTO addAdminMember(final String hash, final String groupShortName,
 	    final String groupToAddShortName) throws DefaultException {
@@ -84,7 +84,7 @@
     }
 
     @Authenticated
-    @Authorizated(accessTypeRequired = AccessType.ADMIN)
+    @GroupAuthorizated(accessTypeRequired = AccessType.ADMIN)
     @Transactional(type = TransactionType.READ_WRITE)
     public SocialNetworkResultDTO addCollabMember(final String hash, final String groupShortName,
 	    final String groupToAddShortName) throws DefaultException {
@@ -97,7 +97,7 @@
     }
 
     @Authenticated
-    @Authorizated(accessTypeRequired = AccessType.ADMIN)
+    @GroupAuthorizated(accessTypeRequired = AccessType.ADMIN)
     @Transactional(type = TransactionType.READ_WRITE)
     public SocialNetworkResultDTO addViewerMember(final String hash, final String groupShortName,
 	    final String groupToAddShortName) throws DefaultException {
@@ -110,7 +110,7 @@
     }
 
     @Authenticated
-    @Authorizated(accessTypeRequired = AccessType.ADMIN)
+    @GroupAuthorizated(accessTypeRequired = AccessType.ADMIN)
     @Transactional(type = TransactionType.READ_WRITE)
     public SocialNetworkResultDTO deleteMember(final String hash, final String groupShortName,
 	    final String groupToDeleleShortName) throws DefaultException {
@@ -123,7 +123,7 @@
     }
 
     @Authenticated
-    @Authorizated(accessTypeRequired = AccessType.ADMIN)
+    @GroupAuthorizated(accessTypeRequired = AccessType.ADMIN)
     @Transactional(type = TransactionType.READ_WRITE)
     public SocialNetworkResultDTO denyJoinGroup(final String hash, final String groupShortName,
 	    final String groupToDenyShortName) throws DefaultException {
@@ -137,7 +137,7 @@
 
     @Authenticated(mandatory = false)
     // At least you can access as Viewer to the Group
-    @Authorizated(accessTypeRequired = AccessType.READ)
+    @GroupAuthorizated(accessTypeRequired = AccessType.READ)
     @Transactional(type = TransactionType.READ_ONLY)
     public SocialNetworkDTO getGroupMembers(final String hash, final String groupShortName) throws DefaultException {
 	final UserSession userSession = getUserSession();
@@ -148,7 +148,7 @@
 
     @Authenticated(mandatory = false)
     // At least you can access as Viewer to the Group
-    @Authorizated(accessTypeRequired = AccessType.READ)
+    @GroupAuthorizated(accessTypeRequired = AccessType.READ)
     @Transactional(type = TransactionType.READ_ONLY)
     public ParticipationDataDTO getParticipation(final String hash, final String groupShortName)
 	    throws DefaultException {
@@ -168,7 +168,7 @@
     }
 
     @Authenticated
-    @Authorizated(accessTypeRequired = AccessType.ADMIN)
+    @GroupAuthorizated(accessTypeRequired = AccessType.ADMIN)
     @Transactional(type = TransactionType.READ_WRITE)
     public SocialNetworkResultDTO setAdminAsCollab(final String hash, final String groupShortName,
 	    final String groupToSetCollabShortName) throws DefaultException {
@@ -181,7 +181,7 @@
     }
 
     @Authenticated
-    @Authorizated(accessTypeRequired = AccessType.ADMIN)
+    @GroupAuthorizated(accessTypeRequired = AccessType.ADMIN)
     @Transactional(type = TransactionType.READ_WRITE)
     public SocialNetworkResultDTO setCollabAsAdmin(final String hash, final String groupShortName,
 	    final String groupToSetAdminShortName) throws DefaultException {

Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/socialnet/GroupMembersSummaryPresenter.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/socialnet/GroupMembersSummaryPresenter.java	2008-08-06 04:21:36 UTC (rev 832)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/socialnet/GroupMembersSummaryPresenter.java	2008-08-07 12:07:05 UTC (rev 833)
@@ -18,7 +18,7 @@
 import org.ourproject.kune.platf.client.ui.gridmenu.GridButton;
 import org.ourproject.kune.platf.client.ui.gridmenu.GridGroup;
 import org.ourproject.kune.workspace.client.i18n.I18nUITranslationService;
-import org.ourproject.kune.workspace.client.search.UserLiveSearcher;
+import org.ourproject.kune.workspace.client.search.GroupLiveSearcher;
 import org.ourproject.kune.workspace.client.sitebar.Site;
 import org.ourproject.kune.workspace.client.ui.newtmp.themes.WsTheme;
 import org.ourproject.kune.workspace.client.ui.newtmp.themes.WsThemePresenter;
@@ -42,7 +42,7 @@
     public GroupMembersSummaryPresenter(final I18nUITranslationService i18n, final StateManager stateManager,
 	    final ImageUtils imageUtils, final Session session,
 	    final Provider<SocialNetworkServiceAsync> snServiceProvider,
-	    final Provider<UserLiveSearcher> userLiveSearcherProvider, final WsThemePresenter wsThemePresenter) {
+	    final Provider<GroupLiveSearcher> liveSearcherProvider, final WsThemePresenter wsThemePresenter) {
 	super(i18n, stateManager, imageUtils, session, snServiceProvider);
 	this.i18n = i18n;
 	this.stateManager = stateManager;
@@ -73,12 +73,12 @@
 	addMember = new GridButton("images/add-green.gif", "", i18n
 		.t("Add a group or a person as member of this group"), new Slot<String>() {
 	    public void onEvent(final String parameter) {
-		userLiveSearcherProvider.get().onSelection(new Slot<LinkDTO>() {
+		liveSearcherProvider.get().onSelection(new Slot<LinkDTO>() {
 		    public void onEvent(final LinkDTO link) {
 			view.confirmAddCollab(link.getShortName(), link.getLongName());
 		    }
 		});
-		userLiveSearcherProvider.get().show();
+		liveSearcherProvider.get().show();
 	    }
 	});
 	super.addGroupOperation(gotoGroupMenuItem, false);




More information about the kune-commits mailing list