Author: tmortagne
Date: 2007-10-26 12:57:44 +0200 (Fri, 26 Oct 2007)
New Revision: 5506
Added:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageRightsApi.java
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
Log:
XWIKI-1826: Add a sub-api to RightsManagerPluginApi containing
getParentPreferences() that get inherited rights.
Added:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageRightsApi.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageRightsApi.java
(rev 0)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManageRightsApi.java
2007-10-26 10:57:44 UTC (rev 5506)
@@ -0,0 +1,109 @@
+/*
+ * 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.rightsmanager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+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;
+
+/**
+ * API for managing rights and inheritance.
+ *
+ * @version $Id: $
+ */
+public class RightsManageRightsApi extends Api
+{
+ /**
+ * Field name of the last error code inserted in context.
+ */
+ public static final String CONTEXT_LASTERRORCODE =
RightsManagerPluginApi.CONTEXT_LASTERRORCODE;
+
+ /**
+ * Field name of the last api exception inserted in context.
+ */
+ public static final String CONTEXT_LASTEXCEPTION =
RightsManagerPluginApi.CONTEXT_LASTEXCEPTION;
+
+ /**
+ * Quote symbol.
+ */
+ public static final String QUOTE = RightsManagerPluginApi.QUOTE;
+
+ /**
+ * The logging toolkit.
+ */
+ protected static final Log LOG =
LogFactory.getLog(RightsManageRightsApi.class);
+
+ /**
+ * Create an instance of RightsManageRightsApi.
+ *
+ * @param context the XWiki context.
+ */
+ public RightsManageRightsApi(XWikiContext context)
+ {
+ super(context);
+ }
+
+ /**
+ * Log error and register [EMAIL PROTECTED] #CONTEXT_LASTERRORCODE} and
[EMAIL PROTECTED] #CONTEXT_LASTEXCEPTION}.
+ *
+ * @param comment the comment to use with [EMAIL PROTECTED] #LOG}.
+ * @param e the exception.
+ */
+ private void logError(String comment, XWikiException e)
+ {
+ LOG.error(comment, e);
+
+ this.context.put(CONTEXT_LASTERRORCODE, new Integer(e.getCode()));
+ this.context.put(CONTEXT_LASTEXCEPTION, e);
+ }
+
+ // Inheritance
+
+ /**
+ * Get the document containing inherited rights of provided document.
+ *
+ * @param spaceOrPage the space of page where to get XWikiRights. If null
get wiki rights.
+ * @return the document containing inherited rights of provided document.
+ * @throws XWikiException error when browsing rights preferences.
+ */
+ public Document getParentPreference(String spaceOrPage) throws
XWikiException
+ {
+ Document parent = null;
+
+ try {
+ XWikiDocument xdoc =
+ RightsManager.getInstance().getParentPreference(spaceOrPage,
context);
+
+ if (xdoc != null) {
+ parent = xdoc.newDocument(context);
+ }
+ } catch (RightsManagerException e) {
+ logError("Try to get parent rights preference for " + QUOTE +
spaceOrPage + QUOTE, e);
+ }
+
+ return parent;
+ }
+}
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
2007-10-26 10:30:56 UTC (rev 5505)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManager.java
2007-10-26 10:57:44 UTC (rev 5506)
@@ -617,7 +617,7 @@
*
* @param spaceOrPage the space of page where to get XWikiRights. If null
get wiki rights.
* @param levelsToMatch the levels names to check ("view", "edit", etc.).
- * @param context the Xwiki context.
+ * @param context the XWiki context.
* @return the [EMAIL PROTECTED] Map} containing [levelname : [EMAIL
PROTECTED] LevelTree}].
* @throws XWikiException error when browsing rights preferences.
*/
@@ -821,6 +821,24 @@
}
/**
+ * Get the document containing inherited rights of provided document.
+ *
+ * @param spaceOrPage the space of page where to get XWikiRights. If null
get wiki rights.
+ * @param context the XWiki context.
+ * @return the document containing inherited rights of provided document.
+ * @throws XWikiException error when browsing rights preferences.
+ */
+ public XWikiDocument getParentPreference(String spaceOrPage, XWikiContext
context)
+ throws XWikiException
+ {
+ XWikiDocument preferences = getXWikiPreferencesDoc(spaceOrPage,
context);
+
+ boolean global = isGlobal(preferences, spaceOrPage);
+
+ return getParentPreference(preferences, global, context);
+ }
+
+ /**
* Get level right tree.
*
* @param doc the document containing rights preferences.
@@ -1113,12 +1131,12 @@
/**
* Browse a group and groups it contains to find provided member (user or
group).
*
- * @param groupName the group name where to search for memeber.
- * @param memberName the name of the memeber to find.
- * @param groupCacheIn a map containg a set a group and its corresponding
memebers already
+ * @param groupName the group name where to search for member.
+ * @param memberName the name of the member to find.
+ * @param groupCacheIn a map containing a set a group and its
corresponding members already
* retrieved.
- * @param context the Xwiki context.
- * @return true if the memeber has been found, false otherwise.
+ * @param context the XWiki context.
+ * @return true if the member has been found, false otherwise.
* @throws XWikiException error when browsing groups.
*/
public boolean groupContainsMember(String groupName, String memberName,
Map groupCacheIn,
@@ -1159,15 +1177,15 @@
}
/**
- * Browse a right objet to find provided user or group.
+ * Browse a right object to find provided user or group.
*
- * @param rightEntry the objet containing rights preferences.
- * @param userOrGroupName the name of teh user or groups to find.
+ * @param rightEntry the object containing rights preferences.
+ * @param userOrGroupName the name of the user or groups to find.
* @param user indicate if it is a user or a group.
- * @param groupCacheIn a map containg a set a group and its corresponding
memebers already
+ * @param groupCacheIn a map containing a set a group and its
corresponding members already
* retrieved.
- * @param context the Xwiki conxtext.
- * @return true if the memeber has been found, false otherwise.
+ * @param context the XWiki context.
+ * @return true if the member has been found, false otherwise.
* @throws XWikiException error when browsing right object.
*/
public boolean rightEntryContainsUserOrGroup(BaseObject rightEntry, String
userOrGroupName,
@@ -1210,7 +1228,7 @@
* Indicate if provided user is super administrator.
*
* @param userName the name of the user.
- * @param context the XWiki conxtext.
+ * @param context the XWiki context.
* @return true is provided user is super administrator, false otherwise.
*/
public boolean isSuperAdmin(String userName, XWikiContext context)
@@ -1240,13 +1258,13 @@
* Indicate which rights provided user or group has on provided right
level on provided right
* object.
*
- * @param rightEntry the object containg rights prferences.
+ * @param rightEntry the object containing rights preferences.
* @param levelName the name of the level right to check.
* @param userOrGroupName the name of the user or group.
* @param user indicate if it is a user or a group.
- * @param groupCache a map containg a set a group and its corresponding
memebers already
+ * @param groupCache a map containing a set a group and its corresponding
members already
* retrieved.
- * @param context the Xwiki context.
+ * @param context the XWiki context.
* @return [EMAIL PROTECTED] Boolean#TRUE} if user has provided right
level, [EMAIL PROTECTED] Boolean#FALSE} if it is
* denied on provided right level. Can be null if no "allow" or
"deny" rights.
* @throws XWikiException error when browsing rights.
@@ -1283,7 +1301,7 @@
* @param levelName the name of the level right to check ("view", "edit",
etc.).
* @param userOrGroupName the name of the user or group.
* @param user indicate if it is a user or a group.
- * @param context the Xwiki context.
+ * @param context the XWiki context.
* @return true if user has provided rights, false otherwise.
* @throws XWikiException error when browsing rights.
*/
@@ -1335,7 +1353,7 @@
* @param levelName the name of the level right to check ("view", "edit",
etc.).
* @param userOrGroupName the name of the user or group.
* @param user indicate if it is a user or a group.
- * @param context the Xwiki context.
+ * @param context the XWiki context.
* @return true if user has provided rights, false otherwise.
* @throws XWikiException error when browsing rights.
*/
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
2007-10-26 10:30:56 UTC (rev 5505)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/rightsmanager/RightsManagerPluginApi.java
2007-10-26 10:57:44 UTC (rev 5506)
@@ -64,6 +64,11 @@
protected static final Log LOG =
LogFactory.getLog(RightsManagerPluginApi.class);
/**
+ * API for managing rights and inheritance.
+ */
+ private RightsManageRightsApi rightsApi;
+
+ /**
* Create an instance of the Rights Manager plugin user api.
*
* @param plugin the entry point of the Rights Manager plugin.
@@ -72,7 +77,17 @@
public RightsManagerPluginApi(RightsManagerPlugin plugin, XWikiContext
context)
{
super(plugin, context);
+
+ rightsApi = new RightsManageRightsApi(context);
}
+
+ /**
+ * @return the API for managing rights and inheritance.
+ */
+ public RightsManageRightsApi getRightsApi()
+ {
+ return rightsApi;
+ }
/**
* Convert Map/List pattern matching parameter from Velocity to [][] used
in
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications