Skip to content
Snippets Groups Projects
Commit aa6144f1 authored by Eduard Moraru's avatar Eduard Moraru
Browse files

XWIKI-6909: Add hasWikiAdminRights method to XWikiRightsService

- Fixed javadoc for hasAdminRights()
- Added a hasWikiAdminRights() method
parent 4c5b465d
No related branches found
No related tags found
No related merge requests found
...@@ -361,6 +361,7 @@ ...@@ -361,6 +361,7 @@
<exclude>com/xpn/xwiki/plugin/activitystream/api/ActivityEvent</exclude> <exclude>com/xpn/xwiki/plugin/activitystream/api/ActivityEvent</exclude>
<exclude>com/xpn/xwiki/plugin/activitystream/plugin/ActivityEvent</exclude> <exclude>com/xpn/xwiki/plugin/activitystream/plugin/ActivityEvent</exclude>
<exclude>org/xwiki/bridge/DocumentAccessBridge</exclude> <exclude>org/xwiki/bridge/DocumentAccessBridge</exclude>
<exclude>com/xpn/xwiki/user/api/XWikiRightService</exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
......
...@@ -43,7 +43,7 @@ public interface XWikiRightService ...@@ -43,7 +43,7 @@ public interface XWikiRightService
* The Guest username. * The Guest username.
*/ */
public static final String GUEST_USER = "XWikiGuest"; public static final String GUEST_USER = "XWikiGuest";
/** /**
* The Guest full name. * The Guest full name.
*/ */
...@@ -58,7 +58,7 @@ public interface XWikiRightService ...@@ -58,7 +58,7 @@ public interface XWikiRightService
* The AllGroup full name. * The AllGroup full name.
*/ */
public static final String ALLGROUP_GROUP_FULLNAME = "XWiki." + ALLGROUP_GROUP; public static final String ALLGROUP_GROUP_FULLNAME = "XWiki." + ALLGROUP_GROUP;
/** /**
* Checks if the wiki current user has the right to execute (@code action} on the document {@code doc}, along with * Checks if the wiki current user has the right to execute (@code action} on the document {@code doc}, along with
* redirecting to the login if it's not the case and there is no logged in user (the user is the guest user). * redirecting to the login if it's not the case and there is no logged in user (the user is the guest user).
...@@ -107,14 +107,23 @@ public boolean hasAccessLevel(String right, String username, String docname, XWi ...@@ -107,14 +107,23 @@ public boolean hasAccessLevel(String right, String username, String docname, XWi
public boolean hasProgrammingRights(XWikiDocument doc, XWikiContext context); public boolean hasProgrammingRights(XWikiDocument doc, XWikiContext context);
/** /**
* Checks that the current user in the context (the currently authenticated user) has administration rights on the * Checks that the current user in the context (the currently authenticated user) has administration rights either
* current wiki. * on the current wiki or on the current space.
* *
* @param context the xwiki context of this request * @param context the xwiki context of this request
* @return {@code true} if the current user in the context has the {@code admin} right, {@code false} otherwise * @return {@code true} if the current user in the context has the {@code admin} right, {@code false} otherwise
*/ */
public boolean hasAdminRights(XWikiContext context); public boolean hasAdminRights(XWikiContext context);
/**
* Checks that the current user in the context (the currently authenticated user) has administration rights on the
* current wiki, regardless of any space admin rights that might also be available.
*
* @param context the xwiki context of this request
* @return {@code true} if the current user in the context has the {@code admin} right, {@code false} otherwise
*/
public boolean hasWikiAdminRights(XWikiContext context);
/** /**
* @param context the xwiki context of this request * @param context the xwiki context of this request
* @return the list of all the known access levels * @return the list of all the known access levels
......
...@@ -991,23 +991,34 @@ public boolean hasProgrammingRights(XWikiDocument doc, XWikiContext context) ...@@ -991,23 +991,34 @@ public boolean hasProgrammingRights(XWikiDocument doc, XWikiContext context)
*/ */
public boolean hasAdminRights(XWikiContext context) public boolean hasAdminRights(XWikiContext context)
{ {
boolean hasAdmin = false; boolean hasAdmin = hasWikiAdminRights(context);
try {
hasAdmin = hasAccessLevel("admin", context.getUser(), "XWiki.XWikiPreferences", context);
} catch (Exception e) {
LOG.error("Failed to check admin right for user [" + context.getUser() + "]", e);
}
if (!hasAdmin) { if (!hasAdmin) {
try { try {
hasAdmin = hasAdmin =
hasAccessLevel("admin", context.getUser(), context.getDoc().getSpace() + ".WebPreferences", context); hasAccessLevel("admin", context.getUser(), context.getDoc().getSpace() + ".WebPreferences", context);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); LOG.error("Failed to check space admin right for user [" + context.getUser() + "]", e);
} }
} }
return hasAdmin; return hasAdmin;
} }
/**
* {@inheritDoc}
*
* @see com.xpn.xwiki.user.api.XWikiRightService#hasWikiAdminRights(com.xpn.xwiki.XWikiContext)
*/
@Override
public boolean hasWikiAdminRights(XWikiContext context)
{
try {
return hasAccessLevel("admin", context.getUser(), "XWiki.XWikiPreferences", context);
} catch (Exception e) {
LOG.error("Failed to check wiki admin right for user [" + context.getUser() + "]", e);
return false;
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment