summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2013-01-14 19:45:17 +0100
committerLukas Reschke <lukas@statuscode.ch>2013-01-14 19:45:17 +0100
commit31b1a73e1f508a33843835b632ee05c7bfc2aaaf (patch)
treee590662315799744155151b2c6c9148d2e9e860e /lib
parentfa78fbe0c3e281c91468bee92c871be7b1e48c79 (diff)
downloadnextcloud-server-31b1a73e1f508a33843835b632ee05c7bfc2aaaf.tar.gz
nextcloud-server-31b1a73e1f508a33843835b632ee05c7bfc2aaaf.zip
Check if user is admin - bool
There was no "isAdminUser()" function which returned bool. This is irritiating as there were a loooooooot of places in the code which checked this itself with `OC_Group::inGroup($uid, 'admin)` - why not use a function for this? (Especially if you consider that we might change the group name in the future, which would lead to problems then) Additionally, @Raydiation needed such a method for his AppFramework :)
Diffstat (limited to 'lib')
-rw-r--r--lib/api.php5
-rw-r--r--lib/app.php4
-rw-r--r--lib/json.php8
-rw-r--r--lib/migrate.php2
-rw-r--r--lib/ocs/cloud.php4
-rw-r--r--lib/subadmin.php7
-rw-r--r--lib/user.php13
-rwxr-xr-xlib/util.php11
8 files changed, 29 insertions, 25 deletions
diff --git a/lib/api.php b/lib/api.php
index cb67e0c2a89..c464cd04913 100644
--- a/lib/api.php
+++ b/lib/api.php
@@ -127,8 +127,7 @@ class OC_API {
return false;
} else {
$subAdmin = OC_SubAdmin::isSubAdmin($user);
- $admin = OC_Group::inGroup($user, 'admin');
- if($subAdmin || $admin) {
+ if($subAdmin) {
return true;
} else {
return false;
@@ -141,7 +140,7 @@ class OC_API {
if(!$user) {
return false;
} else {
- return OC_Group::inGroup($user, 'admin');
+ return OC_User::isAdminUser($user);
}
break;
default:
diff --git a/lib/app.php b/lib/app.php
index e60bce2a201..3b039733fe5 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -313,14 +313,14 @@ class OC_App{
$settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkToRoute( "settings_settings" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" ));
//SubAdmins are also allowed to access user management
- if(OC_SubAdmin::isSubAdmin($_SESSION["user_id"]) || OC_Group::inGroup( $_SESSION["user_id"], "admin" )) {
+ if(OC_SubAdmin::isSubAdmin(OC_User::getUser())) {
// admin users menu
$settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkToRoute( "settings_users" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" ));
}
// if the user is an admin
- if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) {
+ if(OC_User::isAdminUser(OC_User::getUser())) {
// admin apps menu
$settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkToRoute( "settings_apps" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
diff --git a/lib/json.php b/lib/json.php
index 204430411c0..5ab877540d4 100644
--- a/lib/json.php
+++ b/lib/json.php
@@ -57,9 +57,7 @@ class OC_JSON{
* Check if the user is a admin, send json error msg if not
*/
public static function checkAdminUser() {
- self::checkLoggedIn();
- self::verifyUser();
- if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )) {
+ if( !OC_User::isAdminUser(OC_User::getUser())) {
$l = OC_L10N::get('lib');
self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
exit();
@@ -70,9 +68,7 @@ class OC_JSON{
* Check if the user is a subadmin, send json error msg if not
*/
public static function checkSubAdminUser() {
- self::checkLoggedIn();
- self::verifyUser();
- if(!OC_Group::inGroup(OC_User::getUser(), 'admin') && !OC_SubAdmin::isSubAdmin(OC_User::getUser())) {
+ if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) {
$l = OC_L10N::get('lib');
self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
exit();
diff --git a/lib/migrate.php b/lib/migrate.php
index 5ff8e338a44..62ab00bc332 100644
--- a/lib/migrate.php
+++ b/lib/migrate.php
@@ -219,7 +219,7 @@ class OC_Migrate{
// We need to be an admin if we are not importing our own data
if(($type == 'user' && self::$uid != $currentuser) || $type != 'user' ) {
- if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )) {
+ if( !OC_User::isAdminUser($currentuser)) {
// Naughty.
OC_Log::write( 'migration', 'Import not permitted.', OC_Log::ERROR );
return json_encode( array( 'success' => false ) );
diff --git a/lib/ocs/cloud.php b/lib/ocs/cloud.php
index 21095ec91e9..4564a1e9f1f 100644
--- a/lib/ocs/cloud.php
+++ b/lib/ocs/cloud.php
@@ -40,7 +40,7 @@ class OC_OCS_Cloud {
public static function getUserQuota($parameters) {
$user = OC_User::getUser();
- if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) {
+ if(OC_User::isAdminUser($user) or ($user==$parameters['user'])) {
if(OC_User::userExists($parameters['user'])) {
// calculate the disc space
@@ -82,7 +82,7 @@ class OC_OCS_Cloud {
public static function getUserPrivatekey($parameters) {
$user = OC_User::getUser();
- if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) {
+ if(OC_User::isAdminUser($user) or ($user==$parameters['user'])) {
if(OC_User::userExists($user)) {
// calculate the disc space
diff --git a/lib/subadmin.php b/lib/subadmin.php
index 9e83e6da430..8cda7240ac9 100644
--- a/lib/subadmin.php
+++ b/lib/subadmin.php
@@ -122,6 +122,11 @@ class OC_SubAdmin{
* @return bool
*/
public static function isSubAdmin($uid) {
+ // Check if the user is already an admin
+ if(OC_Group::inGroup($uid, 'admin' )) {
+ return true;
+ }
+
$stmt = OC_DB::prepare('SELECT COUNT(*) AS `count` FROM `*PREFIX*group_admin` WHERE `uid` = ?');
$result = $stmt->execute(array($uid));
$result = $result->fetchRow();
@@ -141,7 +146,7 @@ class OC_SubAdmin{
if(!self::isSubAdmin($subadmin)) {
return false;
}
- if(OC_Group::inGroup($user, 'admin')) {
+ if(OC_User::isAdminUser($user)) {
return false;
}
$accessiblegroups = self::getSubAdminsGroups($subadmin);
diff --git a/lib/user.php b/lib/user.php
index 80f88ca7052..8d4eb7aec4d 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -300,6 +300,19 @@ class OC_User {
}
/**
+ * @brief Check if the user is an admin user
+ * @param $uid uid of the admin
+ * @returns bool
+ */
+ public static function isAdminUser($uid) {
+ if(OC_Group::inGroup($uid, 'admin' )) {
+ return true;
+ }
+ return false;
+ }
+
+
+ /**
* @brief get the user id of the user currently logged in.
* @return string uid or false
*/
diff --git a/lib/util.php b/lib/util.php
index 7b1de094ead..06ae37176c1 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -342,10 +342,7 @@ class OC_Util {
* Check if the user is a admin, redirects to home if not
*/
public static function checkAdminUser() {
- // Check if we are a user
- self::checkLoggedIn();
- self::verifyUser();
- if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )) {
+ if( !OC_User::isAdminUser(OC_User::getUser())) {
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' ));
exit();
}
@@ -356,12 +353,6 @@ class OC_Util {
* @return array $groups where the current user is subadmin
*/
public static function checkSubAdminUser() {
- // Check if we are a user
- self::checkLoggedIn();
- self::verifyUser();
- if(OC_Group::inGroup(OC_User::getUser(), 'admin')) {
- return true;
- }
if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) {
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' ));
exit();