summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/app.php13
-rw-r--r--lib/subadmin.php36
-rwxr-xr-xlib/util.php9
3 files changed, 39 insertions, 19 deletions
diff --git a/lib/app.php b/lib/app.php
index 4c2c43ec26b..9c3411a76bc 100755
--- a/lib/app.php
+++ b/lib/app.php
@@ -293,16 +293,21 @@ class OC_App{
if (OC_User::isLoggedIn()) {
// personal menu
$settings[] = array( "id" => "personal", "order" => 1, "href" => OC_Helper::linkTo( "settings", "personal.php" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.svg" ));
-
+
// if there're some settings forms
if(!empty(self::$settingsForms))
// settings menu
$settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "settings.php" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" ));
-
- // if the user is an admin
- if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) {
+
+ //SubAdmins are also allowed to access user management
+ if(OC_SubAdmin::isSubAdmin($_SESSION["user_id"]) || OC_Group::inGroup( $_SESSION["user_id"], "admin" )){
// admin users menu
$settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "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" )) {
// admin apps menu
$settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
diff --git a/lib/subadmin.php b/lib/subadmin.php
index aad657b024f..b6f0b3007fd 100644
--- a/lib/subadmin.php
+++ b/lib/subadmin.php
@@ -38,9 +38,6 @@ class OC_SubAdmin{
public static function createSubAdmin($uid, $gid){
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*group_admin (gid,uid) VALUES(?,?)');
$result = $stmt->execute(array($gid, $uid));
- if(OC_DB::isError($result)){
- return false;
- }
OC_Hook::emit( "OC_SubAdmin", "post_createSubAdmin", array( "gid" => $gid ));
return true;
}
@@ -54,9 +51,6 @@ class OC_SubAdmin{
public static function deleteSubAdmin($uid, $gid){
$stmt = OC_DB::prepare('DELETE FROM *PREFIX*group_admin WHERE gid = ? AND uid = ?');
$result = $stmt->execute(array($gid, $uid));
- if(OC_DB::isError($result)){
- return false;
- }
OC_Hook::emit( "OC_SubAdmin", "post_deleteSubAdmin", array( "gid" => $gid ));
return true;
}
@@ -68,7 +62,7 @@ class OC_SubAdmin{
*/
public static function getSubAdminsGroups($uid){
$stmt = OC_DB::prepare('SELECT gid FROM *PREFIX*group_admin WHERE uid = ?');
- $result = $stmt->execute(array($gid, $uid));
+ $result = $stmt->execute(array($uid));
$gids = array();
while($row = $result->fetchRow()){
$gids[] = $row['gid'];
@@ -83,7 +77,7 @@ class OC_SubAdmin{
*/
public static function getGroupsSubAdmins($gid){
$stmt = OC_DB::prepare('SELECT uid FROM *PREFIX*group_admin WHERE gid = ?');
- $result = $stmt->execute(array($gid, $uid));
+ $result = $stmt->execute(array($gid));
$uids = array();
while($row = $result->fetchRow()){
$uids[] = $row['uid'];
@@ -97,11 +91,35 @@ class OC_SubAdmin{
*/
public static function getAllSubAdmins(){
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*group_admin');
- $result = $stmt->execute(array($gid, $uid));
+ $result = $stmt->execute();
$subadmins = array();
while($row = $result->fetchRow()){
$subadmins[] = $row;
}
return $subadmins;
}
+
+ /**
+ * @brief checks if a user is a SubAdmin of a group
+ * @return array
+ */
+ public static function isSubAdminofGroup($uid, $gid){
+ $stmt = OC_DB::prepare('SELECT COUNT(*) as count FROM *PREFIX*group_admin where uid = ? AND gid = ?');
+ $result = $stmt->execute(array($uid, $gid));
+ $result = $result->fetchRow();
+ if($result['count'] >= 1){
+ return true;
+ }
+ return false;
+ }
+
+ public static function isSubAdmin($uid){
+ $stmt = OC_DB::prepare('SELECT COUNT(*) as count FROM *PREFIX*group_admin WHERE uid = ?');
+ $result = $stmt->execute(array($uid));
+ $result = $result->fetchRow();
+ if($result['count'] > 0){
+ return true;
+ }
+ return false;
+ }
}
diff --git a/lib/util.php b/lib/util.php
index de9171edc8e..2eb102dfa69 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -328,16 +328,13 @@ class OC_Util {
// Check if we are a user
self::checkLoggedIn();
if(OC_Group::inGroup(OC_User::getUser(),'admin')){
- return OC_Group::getGroups();
+ return true;
}
- $stmt = OC_DB::prepare('SELECT COUNT(*) as count FROM *PREFIX*group_admin WHERE uid = ?');
- $result = $stmt->execute(array(OC_User::getUser()));
- $result = $result->fetchRow();
- if($result['count'] == 0){
+ if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())){
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' ));
exit();
}
- return $groups;
+ return true;
}
/**