summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2014-12-17 21:40:26 +0100
committerMorris Jobke <hey@morrisjobke.de>2014-12-17 21:40:26 +0100
commit3d006207d1940227c34e735fb439d9af105fcbcc (patch)
tree5d8210aaf748fdf1b3b5c81415a4656dfd9e9b71 /lib/private
parenta3700513d6aca33c691bd6d17f1fad63288f0b48 (diff)
parent6779bf113d27eca305661c5da67f685ddf2147df (diff)
downloadnextcloud-server-3d006207d1940227c34e735fb439d9af105fcbcc.tar.gz
nextcloud-server-3d006207d1940227c34e735fb439d9af105fcbcc.zip
Merge pull request #12892 from owncloud/is-addmin
Add isAdmin and isInGroup methods for the group manager
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/appframework/dependencyinjection/dicontainer.php4
-rw-r--r--lib/private/group/manager.php30
-rw-r--r--lib/private/user/session.php9
3 files changed, 39 insertions, 4 deletions
diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php
index 517ada2d205..dc57ef4c167 100644
--- a/lib/private/appframework/dependencyinjection/dicontainer.php
+++ b/lib/private/appframework/dependencyinjection/dicontainer.php
@@ -188,6 +188,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{
}
/**
+ * @deprecated use IUserSession->isLoggedIn()
* @return boolean
*/
function isLoggedIn() {
@@ -195,8 +196,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{
}
/**
- * @deprecated use the groupmanager instead to find out if the user is in
- * the admin group
+ * @deprecated use IGroupManager->isAdmin($userId)
* @return boolean
*/
function isAdminUser() {
diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php
index be7bf972693..8dcf14fc1d2 100644
--- a/lib/private/group/manager.php
+++ b/lib/private/group/manager.php
@@ -170,7 +170,14 @@ class Manager extends PublicEmitter implements IGroupManager {
* @return \OC\Group\Group[]
*/
public function getUserGroups($user) {
- $uid = $user->getUID();
+ return $this->getUserIdGroups($user->getUID());
+ }
+
+ /**
+ * @param string $uid the user id
+ * @return \OC\Group\Group[]
+ */
+ public function getUserIdGroups($uid) {
if (isset($this->cachedUserGroups[$uid])) {
return $this->cachedUserGroups[$uid];
}
@@ -184,7 +191,26 @@ class Manager extends PublicEmitter implements IGroupManager {
$this->cachedUserGroups[$uid] = $groups;
return $this->cachedUserGroups[$uid];
}
-
+
+ /**
+ * Checks if a userId is in the admin group
+ * @param string $userId
+ * @return bool if admin
+ */
+ public function isAdmin($userId) {
+ return $this->isInGroup($userId, 'admin');
+ }
+
+ /**
+ * Checks if a userId is in a group
+ * @param string $userId
+ * @param group $group
+ * @return bool if in group
+ */
+ public function isInGroup($userId, $group) {
+ return array_key_exists($group, $this->getUserIdGroups($userId));
+ }
+
/**
* get a list of group ids for a user
* @param \OC\User\User $user
diff --git a/lib/private/user/session.php b/lib/private/user/session.php
index 277aa1a047e..53662d00952 100644
--- a/lib/private/user/session.php
+++ b/lib/private/user/session.php
@@ -138,6 +138,15 @@ class Session implements IUserSession, Emitter {
}
/**
+ * Checks wether the user is logged in
+ *
+ * @return bool if logged in
+ */
+ public function isLoggedIn() {
+ return $this->getUser() !== null;
+ }
+
+ /**
* set the login name
*
* @param string|null $loginName for the logged in user