diff --git a/xwiki-platform-core/xwiki-platform-oldcore/pom.xml b/xwiki-platform-core/xwiki-platform-oldcore/pom.xml index 9410544895cd2d2feafcb7cb3fbfaeb94fad8a3a..bbe60f3b214159d12bc4a99b20cf28250979d6ce 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/pom.xml +++ b/xwiki-platform-core/xwiki-platform-oldcore/pom.xml @@ -843,9 +843,6 @@ **/plugin/svg/SVGMacro.java, **/plugin/svg/SVGPluginApi.java, **/plugin/svg/SVGPlugin.java, - **/plugin/userdirectory/Group.java, - **/plugin/userdirectory/UserDirectoryPluginAPI.java, - **/plugin/userdirectory/UserDirectoryPlugin.java, **/plugin/usertools/XWikiUserManagementToolsAPI.java, **/plugin/usertools/XWikiUserManagementToolsImpl.java, **/plugin/usertools/XWikiUserManagementTools.java, diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/plugin/userdirectory/Group.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/plugin/userdirectory/Group.java deleted file mode 100644 index 0642953811b73701ff3d03061f66ad8af08e685b..0000000000000000000000000000000000000000 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/plugin/userdirectory/Group.java +++ /dev/null @@ -1,455 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package com.xpn.xwiki.plugin.userdirectory; - -import com.xpn.xwiki.XWiki; -import com.xpn.xwiki.XWikiContext; -import com.xpn.xwiki.XWikiException; -import com.xpn.xwiki.api.Document; -import com.xpn.xwiki.api.Object; -import com.xpn.xwiki.doc.XWikiDocument; -import com.xpn.xwiki.objects.classes.BaseClass; -import com.xpn.xwiki.plugin.PluginException; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.xwiki.rendering.syntax.Syntax; - -public class Group -{ - private Document doc; - - private Object objDirectoryGroup; - - private boolean isNew = false; - - public static final int ERROR_USERDIRECTORYPLUGIN_GROUP_UNKNOWN = 0; - - public static final int ERROR_USERDIRECTORYPLUGIN_GROUP_DOESNT_EXIST = 1; - - public Group(XWikiDocument doc, XWikiContext context) throws XWikiException - { - this(doc.newDocument(context), context); - } - - public Group(Document doc, XWikiContext context) throws XWikiException - { - reload(doc, context); - } - - public void reload(XWikiContext context) throws XWikiException - { - reload(null, context); - } - - public void reload(Document doc, XWikiContext context) throws XWikiException - { - if (doc == null) - doc = context.getWiki().getDocument(this.doc.getFullName(), context).newDocument(context); - this.doc = doc; - - BaseClass dirGrpClass = getXWikiDirectoryGroupClass(context); - Object obj; - - if ((obj = doc.getObject(dirGrpClass.getName())) == null) { - doc.createNewObject(dirGrpClass.getName()); - obj = doc.getObject(dirGrpClass.getName()); - this.isNew = true; - } - - this.objDirectoryGroup = obj; - } - - public boolean isNew() - { - return isNew; - } - - public void setName(String name) - { - objDirectoryGroup.set("name", name); - } - - public String getName() - { - return (String) objDirectoryGroup.get("name"); - } - - public String getPageName() - { - return doc.getFullName(); - } - - public void set(String key, java.lang.Object value, XWikiContext context) - { - objDirectoryGroup.set(key, value); - } - - public java.lang.Object get(String key, XWikiContext context) - { - return objDirectoryGroup.get(key); - } - - public List getUsersPageName(XWikiContext context) throws XWikiException - { - List usersPageName = new ArrayList(); - List objs = doc.getObjects(getXWikiGroupsClass(context).getName()); - Iterator it = objs.iterator(); - while (it.hasNext()) { - usersPageName.add(((Object) it.next()).get("member")); - } - - return usersPageName; - } - - /** - * Add a parent to this group - * - * @param name the name of the page of the parent group - * @param context - * @return false if the group is already parent of this one - * @throws XWikiException if the parent group doesn't exist - */ - public boolean addParentName(String name, UserDirectoryPlugin userDirPlugin, XWikiContext context) - throws XWikiException - { - if (isParentPage(name, context)) - return false; - Group parentGroup = getGroup(name, context); - if (parentGroup.isNew()) - throw new PluginException(UserDirectoryPlugin.class, ERROR_USERDIRECTORYPLUGIN_GROUP_DOESNT_EXIST, - "This group doesn't exist"); - addParentName(name, context); - return true; - } - - public boolean isParentPage(String name, XWikiContext context) throws XWikiException - { - List parentsPage = getParentPages(context); - Iterator it = parentsPage.iterator(); - while (it.hasNext()) { - String pageName = (String) it.next(); - if (pageName.equals(name)) - return true; - } - return false; - } - - public boolean removeParent(String name, UserDirectoryPlugin userDirPlugin, XWikiContext context) - throws XWikiException - { - if (!isParentPage(name, context)) - return false; - removeParent(name, context); - return true; - } - - private void removeParent(String name, XWikiContext context) throws XWikiException - { - String className = getXWikiGroupRelationClass(context).getName(); - Vector objs = doc.getObjects(className); - Iterator it = objs.iterator(); - - while (it.hasNext()) { - Object obj = (Object) it.next(); - if (obj.get("parentpage").equals(name)) { - doc.removeObject(obj); - return; - } - } - } - - private void addParentName(String name, XWikiContext context) throws XWikiException - { - String className = getXWikiGroupRelationClass(context).getName(); - int nb = doc.createNewObject(className); - - Object obj = doc.getObject(className, nb); - obj.set("parentpage", name); - } - - /** - * @param context - * @return the list of parent group's page - * @throws XWikiException - */ - public List getParentPages(XWikiContext context) throws XWikiException - { - ArrayList parents = new ArrayList(); - - Vector objs = doc.getObjects(getXWikiGroupRelationClass(context).getName()); - if (objs == null) - return parents; - - Iterator it = objs.iterator(); - while (it.hasNext()) { - Object obj = (Object) it.next(); - String parentsPage = (String) obj.get("parentpage"); - if (parentsPage != null && parentsPage.length() > 0) - parents.add(parentsPage); - } - return parents; - } - - public List getParents(XWikiContext context) throws XWikiException - { - List parentsPage = getParentPages(context); - List res = new ArrayList(); - Iterator it = parentsPage.iterator(); - while (it.hasNext()) { - String str = (String) it.next(); - res.add(getGroup(str, context)); - } - return res; - } - - /** - * @param name - * @param context - * @return - * @throws XWikiException - */ - public boolean addUser(String name, XWikiContext context) throws XWikiException - { - if (isMember(name, context)) - return false; - String className = getXWikiGroupsClass(context).getName(); - int nb = doc.createNewObject(className); - Object obj = doc.getObject(className, nb); - obj.set("member", name); - return true; - } - - public boolean isMember(String docName, XWikiContext context) throws XWikiException - { - List users = getMembers(context); - return users.contains(docName); - } - - public List getUnactivatedMembers(XWikiContext context) throws XWikiException - { - List unactivatedMembers = new ArrayList(); - List members = getMembers(context); - Iterator it = members.iterator(); - while (it.hasNext()) { - String userPage = (String) it.next(); - Document doc = context.getWiki().getDocument(userPage, context).newDocument(context); - doc.use("XWiki.XWikiUsers"); - Integer active = (Integer) doc.getValue("active"); - if (active == null || active.intValue() == 0) { - unactivatedMembers.add(userPage); - } - } - return unactivatedMembers; - } - - public List getActivatedMembers(XWikiContext context) throws XWikiException - { - List unactivatedMembers = new ArrayList(); - List members = getMembers(context); - Iterator it = members.iterator(); - while (it.hasNext()) { - String userPage = (String) it.next(); - Document doc = context.getWiki().getDocument(userPage, context).newDocument(context); - doc.use("XWiki.XWikiUsers"); - String active = (String) doc.getValue("active"); - if (active.equals("0")) { - unactivatedMembers.add(userPage); - } - } - return unactivatedMembers; - } - - public List getMembers(XWikiContext context) throws XWikiException - { - List objs = doc.getObjects(Group.getXWikiGroupsClass(context).getName()); - Iterator it = objs.iterator(); - List members = new ArrayList(); - while (it.hasNext()) { - members.add(((Object) it.next()).get("member")); - } - return members; - } - - public boolean removeUser(String docName, XWikiContext context) throws XWikiException - { - if (!isMember(docName, context)) - return false; - String className = getXWikiGroupsClass(context).getName(); - Vector objs = doc.getObjects(className); - - Object obj; - Iterator it = objs.iterator(); - - while (it.hasNext()) { - obj = (Object) it.next(); - if (obj.get("member").equals(docName)) { - doc.removeObject(obj); - return true; - } - } - return false; - } - - public void save(XWikiContext context) throws XWikiException - { - doc.saveWithProgrammingRights(); - } - - protected static BaseClass getXWikiGroupsClass(XWikiContext context) throws XWikiException - { - XWikiDocument doc; - XWiki xwiki = context.getWiki(); - boolean needsUpdate = false; - - try { - doc = xwiki.getDocument("XWiki.XWikiGroups", context); - } catch (Exception e) { - doc = new XWikiDocument(); - doc.setSpace("XWiki"); - doc.setName("XWikiGroups"); - needsUpdate = true; - } - - BaseClass bclass = doc.getXClass(); - bclass.setName("XWiki.XWikiGroups"); - needsUpdate |= bclass.addTextField("member", "Member", 30); - needsUpdate |= bclass.addTextField("role", "Role", 30); - needsUpdate |= bclass.addTextAreaField("description", "Description", 40, 5); - - String content = doc.getContent(); - if ((content == null) || (content.equals(""))) { - needsUpdate = true; - doc.setContent("1 XWikiGroups"); - doc.setSyntax(Syntax.XWIKI_1_0); - } - - if (needsUpdate) - xwiki.saveDocument(doc, context); - return bclass; - } - - protected static BaseClass getXWikiDirectoryGroupClass(XWikiContext context) throws XWikiException - { - XWikiDocument doc; - XWiki xwiki = context.getWiki(); - boolean needsUpdate = false; - - try { - doc = xwiki.getDocument("XWiki.DirectoryGroupClass", context); - } catch (Exception e) { - doc = new XWikiDocument(); - doc.setSpace("XWiki"); - doc.setName("DirectoryGroupClass"); - needsUpdate = true; - } - - BaseClass bclass = doc.getXClass(); - bclass.setName("XWiki.DirectoryGroupClass"); - needsUpdate |= bclass.addTextField("name", "Name", 30); - needsUpdate |= bclass.addTextAreaField("description", "Description", 40, 5); - - String content = doc.getContent(); - if ((content == null) || (content.equals(""))) { - needsUpdate = true; - doc.setContent("1 DirectoryGroupClass"); - doc.setSyntax(Syntax.XWIKI_1_0); - } - - if (needsUpdate) - xwiki.saveDocument(doc, context); - return bclass; - } - - protected static BaseClass getXWikiGroupRelationClass(XWikiContext context) throws XWikiException - { - XWikiDocument doc; - XWiki xwiki = context.getWiki(); - boolean needsUpdate = false; - - try { - doc = xwiki.getDocument("XWiki.GroupRelationClass", context); - } catch (Exception e) { - doc = new XWikiDocument(); - doc.setSpace("XWiki"); - doc.setName("GroupRelationClass"); - needsUpdate = true; - } - - BaseClass bclass = doc.getXClass(); - bclass.setName("XWiki.GroupRelationClass"); - needsUpdate |= bclass.addTextField("name", "Name", 30); - needsUpdate |= bclass.addTextField("parentpage", "Parent", 30); - needsUpdate |= bclass.addTextAreaField("description", "Description", 40, 5); - - String content = doc.getContent(); - if ((content == null) || (content.equals(""))) { - needsUpdate = true; - doc.setContent("1 XWikiGroup"); - doc.setSyntax(Syntax.XWIKI_1_0); - } - - if (needsUpdate) - xwiki.saveDocument(doc, context); - return bclass; - } - - public static List getAllGroupsPageName(XWikiContext context) throws XWikiException - { - String className = getXWikiDirectoryGroupClass(context).getName(); - String hql = ", BaseObject as obj where obj.name=doc.fullName" + " and obj.className='" + className + "'"; - return context.getWiki().getStore().searchDocumentsNames(hql, context); - } - - public static boolean isValidGroup(String grpName, XWikiContext context) throws XWikiException - { - Document doc = context.getWiki().getDocument(grpName, context).newDocument(context); - if (doc.isNew()) - return false; - return (doc.getObjects(getXWikiDirectoryGroupClass(context).getName()).size() > 0); - } - - public static Group getGroup(String space, String name, XWikiContext context) throws XWikiException - { - XWikiDocument doc = context.getWiki().getDocument(space, name, context); - return (new Group(doc, context)); - } - - public Group getGroup(String name, XWikiContext context) throws XWikiException - { - if (name.indexOf('.') >= 0) { - String[] grp = name.split("\\."); - return getGroup(grp[0], grp[1], context); - } else - return getGroup(UserDirectoryPlugin.DEFAULT_PLUGIN_SPACE, name, context); - } - - public static List getAllGroupsPageName(String orderBy, XWikiContext context) throws XWikiException - { - String className = getXWikiDirectoryGroupClass(context).getName(); - String hql = - ", BaseObject as obj, StringProperty as prop where obj.name=doc.fullName" + " and obj.className='" - + className + "' and obj.id=prop.id.id and prop.name='" + orderBy + "' order by prop.value"; - return context.getWiki().getStore().searchDocumentsNames(hql, context); - } -} diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPlugin.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPlugin.java deleted file mode 100644 index 06c8080125d7d01d9af6d52483e454e61f5549e6..0000000000000000000000000000000000000000 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPlugin.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package com.xpn.xwiki.plugin.userdirectory; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.apache.velocity.VelocityContext; - -import com.xpn.xwiki.XWikiContext; -import com.xpn.xwiki.XWikiException; -import com.xpn.xwiki.api.Api; -import com.xpn.xwiki.api.Document; -import com.xpn.xwiki.doc.XWikiDocument; -import com.xpn.xwiki.plugin.PluginException; -import com.xpn.xwiki.plugin.XWikiDefaultPlugin; -import com.xpn.xwiki.plugin.XWikiPluginInterface; -import com.xpn.xwiki.plugin.usertools.XWikiUserManagementTools; -import com.xpn.xwiki.user.api.XWikiGroupService; -import com.xpn.xwiki.web.XWikiRequest; - -public class UserDirectoryPlugin extends XWikiDefaultPlugin implements XWikiPluginInterface -{ - public static final String DEFAULT_PLUGIN_SPACE = "Directory"; - - public static final String DEFAULT_GROUP_TEMPLATE = "XWiki.DirectoryGroupTemplate"; - - public static final String DEFAULT_DEACTIVATION_MESSAGE_PAGE = "XWiki.DeactivationMessage"; - - public static final int ERROR_USERDIRECTORYPLUGIN_UNKNOWN = 0; - - public static final int ERROR_USERDIRECTORYPLUGIN_ALREADYEXIST = 1; - - public static final int ERROR_USERDIRECTORYPLUGIN_GRPDOESNTEXIST = 2; - - private static final int ERROR_XWIKI_EMAIL_CANNOT_PREPARE_VALIDATION_EMAIL = 3; - - private static final int ERROR_XWIKI_EMAIL_CANNOT_GET_VALIDATION_CONFIG = 4; - - public UserDirectoryPlugin(String name, String className, XWikiContext context) - { - super(name, className, context); - } - - @Override - public String getName() - { - return "userdirectory"; - } - - @Override - public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) - { - return new UserDirectoryPluginAPI((UserDirectoryPlugin) plugin, context); - } - - /** - * Add a group from the request - * - * @param context - */ - public Group addGroup(XWikiContext context) throws XWikiException - { - XWikiRequest req = context.getRequest(); - String name = req.get("XWiki.DirectoryGroupClass_0_name"); - name = context.getWiki().clearName(name, context); - XWikiDocument tmpDoc = context.getWiki().getDocument(DEFAULT_PLUGIN_SPACE, name, context); - if (!tmpDoc.isNew()) - throw new PluginException(UserDirectoryPlugin.class, ERROR_USERDIRECTORYPLUGIN_ALREADYEXIST, - "This document already exist, try another name"); - Document doc = tmpDoc.newDocument(context); - doc.addObjectFromRequest("XWiki.DirectoryGroupClass"); - doc.setContent(getTemplate(context)); - doc.saveWithProgrammingRights(); - return new Group(doc, context); - } - - public String getTemplate(XWikiContext context) throws XWikiException - { - return context.getWiki().getDocument(DEFAULT_GROUP_TEMPLATE, context).getContent(); - } - - public void updateGroup(XWikiContext context) throws XWikiException - { - XWikiRequest req = context.getRequest(); - String pageName = req.get("pageName"); - XWikiDocument tmpDoc = context.getWiki().getDocument(pageName, context); - Document doc = tmpDoc.newDocument(context); - doc.updateObjectFromRequest("XWiki.DirectoryGroupClass"); - doc.save(); - } - - public boolean groupExist(String name, XWikiContext context) throws XWikiException - { - return getGroup(name, context).isNew(); - } - - public Group getGroup(String space, String name, XWikiContext context) throws XWikiException - { - return Group.getGroup(space, name, context); - } - - public Group getGroup(String name, XWikiContext context) throws XWikiException - { - return getGroup(DEFAULT_PLUGIN_SPACE, name, context); - } - - public List getAllGroupsPageName(XWikiContext context) throws XWikiException - { - return Group.getAllGroupsPageName(context); - } - - public List getAllGroupsPageName(String orderBy, XWikiContext context) throws XWikiException - { - return Group.getAllGroupsPageName(orderBy, context); - } - - public List getAllGroups(XWikiContext context) throws XWikiException - { - return getAllGroups(null, context); - } - - public List getAllGroups(String orderBy, XWikiContext context) throws XWikiException - { - List allGroupsPageName; - if (orderBy == null) - allGroupsPageName = getAllGroupsPageName(context); - else - allGroupsPageName = getAllGroupsPageName(orderBy, context); - List groups = new ArrayList(); - if (allGroupsPageName == null) - return groups; - Iterator it = allGroupsPageName.iterator(); - while (it.hasNext()) - groups.add(getGroup((String) it.next(), context)); - return groups; - } - - public List getMembers(String grpPage, XWikiContext context) throws XWikiException - { - Group grp = getGroup(grpPage, context); - return grp.getMembers(context); - } - - public List getUnactivatedMembers(String grpPage, XWikiContext context) throws XWikiException - { - Group grp = getGroup(grpPage, context); - return grp.getUnactivatedMembers(context); - } - - public boolean removeGroup(String name, XWikiContext context) - { - return false; - } - - public boolean addParentGroup(String childGroupName, String parentGroupName, XWikiContext context) - throws XWikiException - { - Group grp = getGroup(childGroupName, context); - boolean res = grp.addParentName(parentGroupName, this, context); - if (res) { - grp.save(context); - return true; - } - return false; - } - - public boolean removeParentGroup(String childGroupName, String parentGroupName, XWikiContext context) - throws XWikiException - { - Group grp = getGroup(childGroupName, context); - boolean res = grp.removeParent(parentGroupName, this, context); - if (res) { - grp.save(context); - return true; - } - return false; - } - - public List getParentGroups(String grpName, XWikiContext context) throws XWikiException - { - Group grp = getGroup(grpName, context); - return grp.getParents(context); - } - - public String inviteToGroup(String name, String firstName, String email, String group, XWikiContext context) - throws XWikiException - { - String pageName = context.getWiki().convertUsername(email, context); - XWikiUserManagementTools userTools = - (XWikiUserManagementTools) context.getWiki().getPlugin("usermanagementtools", context); - XWikiDocument doc = context.getWiki().getDocument(userTools.getUserSpace(context) + "." + pageName, context); - if (doc.isNew()) { - String userDocName = userTools.inviteUser(name, email, context); - Document userDoc = context.getWiki().getDocument(userDocName, context).newDocument(context); - userDoc.use("XWiki.XWikiUsers"); - userDoc.set("first_name", firstName); - userDoc.saveWithProgrammingRights(); - } - addUserToGroup(doc.getFullName(), group, context); - return doc.getFullName(); - } - - public void addUserToGroup(String userPage, String group, XWikiContext context) throws XWikiException - { - Group grp = getGroup(group, context); - if (grp == null) - throw new PluginException(UserDirectoryPlugin.class, ERROR_USERDIRECTORYPLUGIN_GRPDOESNTEXIST, - "This group doesn't exist"); - if (grp.addUser(userPage, context)) - grp.save(context); - } - - public String getUserName(String userPage, XWikiContext context) throws XWikiException - { - XWikiUserManagementTools userTools = - (XWikiUserManagementTools) context.getWiki().getPlugin("usermanagementtools", context); - return userTools.getUserName(userPage, context); - } - - public String getUserEmail(String userPage, XWikiContext context) throws XWikiException - { - XWikiUserManagementTools userTools = - (XWikiUserManagementTools) context.getWiki().getPlugin("usermanagementtools", context); - return userTools.getEmail(userPage, context); - } - - public List getUsersDocumentName(String grpPage, XWikiContext context) throws XWikiException - { - Group grp = getGroup(grpPage, context); - return grp.getUsersPageName(context); - } - - public List getUsersDocument(String grpPage, XWikiContext context) throws XWikiException - { - List users = getUsersDocumentName(grpPage, context); - List usersDoc = new ArrayList(); - Iterator it = users.iterator(); - while (it.hasNext()) { - usersDoc.add(context.getWiki().getDocument((String) it.next(), context).newDocument(context)); - } - return usersDoc; - } - - public boolean removeMemberships(String userPage, String grpPage, XWikiContext context) throws XWikiException - { - Group grp = getGroup(grpPage, context); - grp.removeUser(userPage, context); - grp.save(context); - return true; - } - - public void sendDeactivationEMail(String userPage, String grpPage, XWikiContext context) throws XWikiException - { - Group grp = getGroup(grpPage, context); - String userName = getUserName(userPage, context); - String email = getUserEmail(userPage, context); - String message = prepareDeactivationMessage(userName, email, grp.getName(), context); - String sender; - try { - sender = context.getWiki().getXWikiPreference("admin_email", context); - } catch (Exception e) { - throw new PluginException(getName(), ERROR_XWIKI_EMAIL_CANNOT_GET_VALIDATION_CONFIG, - "Exception while reading the validation email config", e, null); - - } - context.getWiki().sendMessage(sender, email, message, context); - } - - private String prepareDeactivationMessage(String name, String email, String grp, XWikiContext context) - throws XWikiException - { - XWikiDocument doc = context.getWiki().getDocument(getDeactivationMessageDocument(context), context); - - String content = doc.getContent(); - - try { - VelocityContext vcontext = (VelocityContext) context.get("vcontext"); - vcontext.put("name", name); - vcontext.put("group", grp); - vcontext.put("email", email); - content = context.getWiki().parseContent(content, context); - } catch (Exception e) { - throw new PluginException(getName(), ERROR_XWIKI_EMAIL_CANNOT_PREPARE_VALIDATION_EMAIL, - "Exception while preparing the validation email", e, null); - - } - return content; - } - - protected String getDeactivationMessageDocument(XWikiContext context) - { - return DEFAULT_DEACTIVATION_MESSAGE_PAGE; - } - - public List getUserMemberships(String userPage, XWikiContext context) throws XWikiException - { - XWikiGroupService groupService = context.getWiki().getGroupService(context); - Collection groups = groupService.listGroupsForUser(userPage, context); - List userGrps = new ArrayList(); - Iterator it = groups.iterator(); - while (it.hasNext()) { - String grpName = (String) it.next(); - if (Group.isValidGroup(grpName, context)) - userGrps.add(grpName); - } - return userGrps; - } - - public boolean deactivateAccount(String userPage, XWikiContext context) throws XWikiException - { - Document doc = context.getWiki().getDocument(userPage, context).newDocument(context); - doc.use("XWiki.XWikiUsers"); - doc.set("active", "0"); - String validkey = context.getWiki().generateValidationKey(16); - doc.set("validkey", validkey); - doc.saveWithProgrammingRights(); - return true; - } - - public void resendInvitation(String userPage, XWikiContext context) throws XWikiException - { - XWikiUserManagementTools userTools = - (XWikiUserManagementTools) context.getWiki().getPlugin("usermanagementtools", context); - - userTools.resendInvitation(userTools.getEmail(userPage, context), context); - } - -} diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPluginAPI.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPluginAPI.java deleted file mode 100644 index 36aa87663c83f0de5e144e510bb4d4aaf6b32fe4..0000000000000000000000000000000000000000 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/plugin/userdirectory/UserDirectoryPluginAPI.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package com.xpn.xwiki.plugin.userdirectory; - -import com.xpn.xwiki.XWikiContext; -import com.xpn.xwiki.XWikiException; -import com.xpn.xwiki.api.Api; - -import java.util.List; - -public class UserDirectoryPluginAPI extends Api { - UserDirectoryPlugin userDir; - - public UserDirectoryPluginAPI(UserDirectoryPlugin userDirectory, XWikiContext context) { - super(context); - this.userDir = userDirectory; - } - - public Group addGroup(XWikiContext context) throws XWikiException { - return userDir.addGroup(context); - } - - public void updateGroup(XWikiContext context) throws XWikiException { - userDir.updateGroup(context); - } - - public boolean groupExist(String name, XWikiContext context) throws XWikiException { - return userDir.groupExist(name, context); - } - - public Group getGroup(String space, String name, XWikiContext context) throws XWikiException { - return userDir.getGroup(space, name, context); - } - - public Group getGroup(String name, XWikiContext context) throws XWikiException { - return userDir.getGroup(name, context); - } - - public List getAllGroupsPageName(XWikiContext context) throws XWikiException { - return userDir.getAllGroupsPageName(context); - } - - public List getAllGroups(XWikiContext context) throws XWikiException { - return userDir.getAllGroups(context); - } - - public List getAllGroups(String orderBy, XWikiContext context) throws XWikiException { - return userDir.getAllGroups(orderBy, context); - } - - public List getMembers(String grpPage, XWikiContext context) throws XWikiException { - return userDir.getMembers(grpPage, context); - } - - public List getUnactivatedMembers(String grpPage, XWikiContext context) throws XWikiException { - return userDir.getUnactivatedMembers(grpPage, context); - } - - public boolean addParentGroup(String childGroupName, String parentGroupName, XWikiContext context) throws XWikiException { - return userDir.addParentGroup(childGroupName, parentGroupName, context); - } - - public boolean removeParentGroup(String childGroupName, String parentGroupName, XWikiContext context) throws XWikiException { - return userDir.removeParentGroup(childGroupName, parentGroupName, context); - } - - public List getParentGroups(String grpName, XWikiContext context) throws XWikiException { - return userDir.getParentGroups(grpName, context); - } - - public String inviteToGroup(String name, String firstName, String email, String group, XWikiContext context) throws XWikiException { - return userDir.inviteToGroup(name, firstName, email, group, context); - } - - public void addUserToGroup(String userPage, String group, XWikiContext context) throws XWikiException { - userDir.addUserToGroup(userPage, group, context); - } - - public String getUserName(String userPage, XWikiContext context) throws XWikiException { - return userDir.getUserName(userPage, context); - } - - public String getUserEmail(String userPage, XWikiContext context) throws XWikiException { - return userDir.getUserEmail(userPage, context); - } - - public List getUsersDocumentName(String grpPage, XWikiContext context) throws XWikiException { - return userDir.getUsersDocumentName(grpPage, context); - } - - public List getUsersDocument(String grpPage, XWikiContext context) throws XWikiException { - return userDir.getUsersDocument(grpPage, context); - } - - - public boolean removeMemberships(String userPage, String grpPage, XWikiContext context) throws XWikiException { - return userDir.removeMemberships(userPage, grpPage, context); - } - - public void sendDeactivationEMail(String userPage, String grpPage, XWikiContext context) throws XWikiException { - userDir.sendDeactivationEMail(userPage, grpPage, context); - } - - public List getUserMemberships(String userPage, XWikiContext context) throws XWikiException { - return userDir.getUserMemberships(userPage, context); - } - - public boolean deactivateAccount(String userPage, XWikiContext context) throws XWikiException { - return userDir.deactivateAccount(userPage, context); - } - - public void resendInvitation(String userPage, XWikiContext context) throws XWikiException { - userDir.resendInvitation(userPage, context); - } - -}