Example #1
0
 function testSingleBackend()
 {
     OC_Group::useBackend(new OCA\user_ldap\GROUP_LDAP());
     $group_ldap = new OCA\user_ldap\GROUP_LDAP();
     $this->assertIsA(OC_Group::getGroups(), gettype(array()));
     $this->assertIsA($group_ldap->getGroups(), gettype(array()));
     $this->assertFalse(OC_Group::inGroup('john', 'dosers'), gettype(false));
     $this->assertFalse($group_ldap->inGroup('john', 'dosers'), gettype(false));
     //TODO: check also for expected true result. This backend won't be able to do any modifications, maybe use a dummy for this.
     $this->assertIsA(OC_Group::getUserGroups('john doe'), gettype(array()));
     $this->assertIsA($group_ldap->getUserGroups('john doe'), gettype(array()));
     $this->assertIsA(OC_Group::usersInGroup('campers'), gettype(array()));
     $this->assertIsA($group_ldap->usersInGroup('campers'), gettype(array()));
 }
                $groups[] = $group;
            }
        }
        if (count($groups) === 0) {
            $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
        }
    } else {
        $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    }
}
$username = $_POST["username"];
$password = $_POST["password"];
// Return Success story
try {
    // check whether the user's files home exists
    $userDirectory = OC_User::getHome($username) . '/files/';
    $homeExists = file_exists($userDirectory);
    if (!OC_User::createUser($username, $password)) {
        OC_JSON::error(array('data' => array('message' => 'User creation failed for ' . $username)));
        exit;
    }
    foreach ($groups as $i) {
        if (!OC_Group::groupExists($i)) {
            OC_Group::createGroup($i);
        }
        OC_Group::addToGroup($username, $i);
    }
    OC_JSON::success(array("data" => array("homeExists" => $homeExists, "username" => $username, "groups" => OC_Group::getUserGroups($username))));
} catch (Exception $exception) {
    OC_JSON::error(array("data" => array("message" => $exception->getMessage())));
}
Example #3
0
            if (OC_SubAdmin::isGroupAccessible(OC_User::getUser(), $group)) {
                $groups[] = $group;
            }
        }
        if (count($groups) == 0) {
            $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
        }
    } else {
        $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    }
}
$username = $_POST["username"];
$password = $_POST["password"];
// Does the group exist?
if (in_array($username, OC_User::getUsers())) {
    OC_JSON::error(array("data" => array("message" => "User already exists")));
    exit;
}
// Return Success story
try {
    OC_User::createUser($username, $password);
    foreach ($groups as $i) {
        if (!OC_Group::groupExists($i)) {
            OC_Group::createGroup($i);
        }
        OC_Group::addToGroup($username, $i);
    }
    OC_JSON::success(array("data" => array("username" => $username, "groups" => implode(", ", OC_Group::getUserGroups($username)))));
} catch (Exception $exception) {
    OC_JSON::error(array("data" => array("message" => $exception->getMessage())));
}
Example #4
0
 /**
  * check if sharing is disabled for the current user
  *
  * @return boolean
  */
 public static function isSharingDisabledForUser()
 {
     if (\OC_Appconfig::getValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
         $user = \OCP\User::getUser();
         $groupsList = \OC_Appconfig::getValue('core', 'shareapi_exclude_groups_list', '');
         $excludedGroups = explode(',', $groupsList);
         $usersGroups = \OC_Group::getUserGroups($user);
         if (!empty($usersGroups)) {
             $remainingGroups = array_diff($usersGroups, $excludedGroups);
             // if the user is only in groups which are disabled for sharing then
             // sharing is also disabled for the user
             if (empty($remainingGroups)) {
                 return true;
             }
         }
     }
     return false;
 }
Example #5
0
 /**
  * Delete the user
  *
  * @return bool
  */
 public function delete()
 {
     if ($this->emitter) {
         $this->emitter->emit('\\OC\\User', 'preDelete', array($this));
     }
     $result = $this->backend->deleteUser($this->uid);
     if ($result) {
         // FIXME: Feels like an hack - suggestions?
         // We have to delete the user from all groups
         foreach (\OC_Group::getUserGroups($this->uid) as $i) {
             \OC_Group::removeFromGroup($this->uid, $i);
         }
         // Delete the user's keys in preferences
         \OC::$server->getConfig()->deleteAllUserValues($this->uid);
         // Delete user files in /data/
         \OC_Helper::rmdirr(\OC_User::getHome($this->uid));
         // Delete the users entry in the storage table
         \OC\Files\Cache\Storage::remove('home::' . $this->uid);
         \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
         \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
     }
     if ($this->emitter) {
         $this->emitter->emit('\\OC\\User', 'postDelete', array($this));
     }
     return !($result === false);
 }
 /**
  * Generate a string to be used for searching for uid_shared_with that handles both users and groups
  * @param $uid (Optional) The uid to get the user groups for, a gid to get the users in a group, or if not set the current user
  * @return An IN operator as a string
  */
 private static function getUsersAndGroups($uid = null, $includePrivateLinks = true)
 {
     $in = " IN(";
     if (isset($uid) && OC_Group::groupExists($uid)) {
         $users = OC_Group::usersInGroup($uid);
         foreach ($users as $user) {
             // Add a comma only if the the current element isn't the last
             if ($user !== end($users)) {
                 $in .= "'" . $user . "@" . $uid . "', ";
             } else {
                 $in .= "'" . $user . "@" . $uid . "'";
             }
         }
     } else {
         if (isset($uid)) {
             // TODO Check if this is necessary, only constructor needs it as IN. It would be better for other queries to just return =$uid
             $in .= "'" . $uid . "'";
             $groups = OC_Group::getUserGroups($uid);
             foreach ($groups as $group) {
                 $in .= ", '" . $uid . "@" . $group . "'";
             }
         } else {
             $uid = OCP\USER::getUser();
             $in .= "'" . $uid . "'";
             $groups = OC_Group::getUserGroups($uid);
             foreach ($groups as $group) {
                 $in .= ", '" . $uid . "@" . $group . "'";
             }
         }
     }
     if ($includePrivateLinks) {
         $in .= ", '" . self::PUBLICLINK . "'";
     }
     $in .= ")";
     return $in;
 }
Example #7
0
 /**
  * @brief delete a user
  * @param $uid The username of the user to delete
  * @returns true/false
  *
  * Deletes a user
  */
 public static function deleteUser($uid)
 {
     $run = true;
     OC_Hook::emit("OC_User", "pre_deleteUser", array("run" => &$run, "uid" => $uid));
     if ($run) {
         //delete the user from all backends
         foreach (self::$_usedBackends as $backend) {
             $backend->deleteUser($uid);
         }
         if (self::userExists($uid)) {
             return false;
         }
         // We have to delete the user from all groups
         foreach (OC_Group::getUserGroups($uid) as $i) {
             OC_Group::removeFromGroup($uid, $i);
         }
         // Delete the user's keys in preferences
         OC_Preferences::deleteUser($uid);
         // Delete user files in /data/
         OC_Helper::rmdirr(OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data") . '/' . $uid . '/');
         // Emit and exit
         OC_Hook::emit("OC_User", "post_deleteUser", array("uid" => $uid));
         return true;
     } else {
         return false;
     }
 }
Example #8
0
    $pattern = '';
}
$users = array();
$userManager = \OC_User::getManager();
if (OC_User::isAdminUser(OC_User::getUser())) {
    if ($gid !== false) {
        $batch = OC_Group::displayNamesInGroup($gid, $pattern, $limit, $offset);
    } else {
        $batch = OC_User::getDisplayNames($pattern, $limit, $offset);
    }
    foreach ($batch as $uid => $displayname) {
        $user = $userManager->get($uid);
        $users[] = array('name' => $uid, 'displayname' => $displayname, 'groups' => join(', ', OC_Group::getUserGroups($uid)), 'subadmin' => join(', ', OC_SubAdmin::getSubAdminsGroups($uid)), 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin());
    }
} else {
    $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    if ($gid !== false && in_array($gid, $groups)) {
        $groups = array($gid);
    } elseif ($gid !== false) {
        //don't you try to investigate loops you must not know about
        $groups = array();
    }
    $batch = OC_Group::usersInGroups($groups, $pattern, $limit, $offset);
    foreach ($batch as $uid) {
        $user = $userManager->get($uid);
        // Only add the groups, this user is a subadmin of
        $userGroups = array_intersect(OC_Group::getUserGroups($uid), OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()));
        $users[] = array('name' => $uid, 'displayname' => $user->getDisplayName(), 'groups' => join(', ', $userGroups), 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin());
    }
}
OC_JSON::success(array('data' => $users));
Example #9
0
    $UserTokenSeed = "";
    $UserLocked = "";
    $UserAlgorithm = "";
    $UserPin = "";
    $UserPrefixPin = "";
    //get otp information :
    $OtpExist = $mOtp->CheckUserExists($uid);
    if ($OtpExist) {
        $mOtp->SetUser($uid);
        $UserTokenSeed = base32_encode(hex2bin($mOtp->GetUserTokenSeed()));
        $UserLocked = $mOtp->GetUserLocked();
        $UserAlgorithm = $mOtp->GetUserAlgorithm();
        $UserPin = $mOtp->GetUserPin();
        $UserPrefixPin = $mOtp->GetUserPrefixPin();
    }
    $users[] = array("name" => $uid, "displayName" => $displayName, "groups" => OC_Group::getUserGroups($uid), 'subadmin' => OC_SubAdmin::getSubAdminsGroups($uid), 'OtpExist' => $OtpExist, 'UserTokenSeed' => $UserTokenSeed, 'UserLocked' => $UserLocked, 'UserAlgorithm' => $UserAlgorithm, 'UserPin' => $UserPin, 'UserPrefixPin' => $UserPrefixPin);
}
foreach ($accessiblegroups as $i) {
    // Do some more work here soon
    $groups[] = array("name" => $i);
}
$tmpl = new OC_Template("user_otp", "list_users", "user");
$tmpl->assign('PrefixPin', OCP\Config::getAppValue('user_otp', 'UserPrefixPin', '0') ? 1 : 0);
$tmpl->assign('users', $users);
$tmpl->assign('groups', $groups);
$tmpl->assign('isadmin', (int) $isadmin);
$tmpl->assign('subadmins', $subadmins);
$tmpl->assign('numofgroups', count($accessiblegroups));
//~ $tmpl->assign( 'quota_preset', $quotaPreset);
//~ $tmpl->assign( 'default_quota', $defaultQuota);
//~ $tmpl->assign( 'defaultQuotaIsUserDefined', $defaultQuotaIsUserDefined);
Example #10
0
 /**
  * Generate a unique target for the item
  * @param string $itemType
  * @param string $itemSource
  * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  * @param string $shareWith User or group the item is being shared with
  * @param string $uidOwner User that is the owner of shared item
  * @param string $suggestedTarget The suggested target originating from a reshare (optional)
  * @param int $groupParent The id of the parent group share (optional)
  * @throws \Exception
  * @return string Item target
  */
 public static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null, $groupParent = null)
 {
     $backend = \OC\Share\Share::getBackend($itemType);
     if ($shareType == self::SHARE_TYPE_LINK) {
         if (isset($suggestedTarget)) {
             return $suggestedTarget;
         }
         return $backend->generateTarget($itemSource, false);
     } else {
         if ($itemType == 'file' || $itemType == 'folder') {
             $column = 'file_target';
             $columnSource = 'file_source';
         } else {
             $column = 'item_target';
             $columnSource = 'item_source';
         }
         if ($shareType == self::SHARE_TYPE_USER) {
             // Share with is a user, so set share type to user and groups
             $shareType = self::$shareTypeUserAndGroups;
             $userAndGroups = array_merge(array($shareWith), \OC_Group::getUserGroups($shareWith));
         } else {
             $userAndGroups = false;
         }
         $exclude = null;
         // Backend has 3 opportunities to generate a unique target
         for ($i = 0; $i < 2; $i++) {
             // Check if suggested target exists first
             if ($i == 0 && isset($suggestedTarget)) {
                 $target = $suggestedTarget;
             } else {
                 if ($shareType == self::SHARE_TYPE_GROUP) {
                     $target = $backend->generateTarget($itemSource, false, $exclude);
                 } else {
                     $target = $backend->generateTarget($itemSource, $shareWith, $exclude);
                 }
                 if (is_array($exclude) && in_array($target, $exclude)) {
                     break;
                 }
             }
             // Check if target already exists
             $checkTarget = \OC\Share\Share::getItems($itemType, $target, $shareType, $shareWith);
             if (!empty($checkTarget)) {
                 foreach ($checkTarget as $item) {
                     // Skip item if it is the group parent row
                     if (isset($groupParent) && $item['id'] == $groupParent) {
                         if (count($checkTarget) == 1) {
                             return $target;
                         } else {
                             continue;
                         }
                     }
                     if ($item['uid_owner'] == $uidOwner) {
                         if ($itemType == 'file' || $itemType == 'folder') {
                             $meta = \OC\Files\Filesystem::getFileInfo($itemSource);
                             if ($item['file_source'] == $meta['fileid']) {
                                 return $target;
                             }
                         } else {
                             if ($item['item_source'] == $itemSource) {
                                 return $target;
                             }
                         }
                     }
                 }
                 if (!isset($exclude)) {
                     $exclude = array();
                 }
                 // Find similar targets to improve backend's chances to generate a unqiue target
                 if ($userAndGroups) {
                     if ($column == 'file_target') {
                         $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share`' . ' WHERE `item_type` IN (\'file\', \'folder\')' . ' AND `share_type` IN (?,?,?)' . ' AND `share_with` IN (\'' . implode('\',\'', $userAndGroups) . '\')');
                         $result = $checkTargets->execute(array(self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
                     } else {
                         $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share`' . ' WHERE `item_type` = ? AND `share_type` IN (?,?,?)' . ' AND `share_with` IN (\'' . implode('\',\'', $userAndGroups) . '\')');
                         $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
                     }
                 } else {
                     if ($column == 'file_target') {
                         $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share`' . ' WHERE `item_type` IN (\'file\', \'folder\')' . ' AND `share_type` = ? AND `share_with` = ?');
                         $result = $checkTargets->execute(array(self::SHARE_TYPE_GROUP, $shareWith));
                     } else {
                         $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share`' . ' WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ?');
                         $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith));
                     }
                 }
                 while ($row = $result->fetchRow()) {
                     $exclude[] = $row[$column];
                 }
             } else {
                 return $target;
             }
         }
     }
     $message = 'Sharing backend registered for ' . $itemType . ' did not generate a unique target for ' . $itemSource;
     \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
     throw new \Exception($message);
 }
Example #11
0
}
?>
	
	<table id="table_access">
		<tr>
			<td>
				<div class="scroll_div_dialog">
					<table id="table_groups">
							<tr>
								<th><?php 
p($l->t('Groups'));
?>
</th>
							</tr>
						<?php 
$groups = OC_Group::getUserGroups(OCP\User::getUser());
?>
						<?php 
foreach ($groups as $gid) {
    ?>
							<tr>
								<td class="cl_group_item"><?php 
    echo $gid;
    ?>
</td>
							</tr>
						<?php 
}
?>
					</table>
				</div>
Example #12
0
 private function getGroups()
 {
     $this->requireLogin();
     // TODO(leon): This looks like a private API.
     return \OC_Group::getUserGroups($this->getUserId());
 }
Example #13
0
 public static function check_access($share, $id, $type)
 {
     $group_where = self::group_sql(OC_Group::getUserGroups($share));
     $stmt = OCP\DB::prepare("SELECT * FROM *PREFIX*calendar_share_" . $type . " WHERE (" . $type . "id = ? AND (share = ? AND sharetype = 'user') " . $group_where . ")");
     $result = $stmt->execute(array($id, $share));
     $rows = $result->numRows();
     if ($rows > 0) {
         return true;
     } elseif ($type == self::EVENT) {
         $event = OC_Calendar_App::getEventObject($id, false, false);
         return self::check_access($share, $event['calendarid'], self::CALENDAR);
     } else {
         return false;
     }
 }
	public static function getRooms() {
		$grooms = array();
		$urooms = array();
		$userId = OC_User::getUser();
		$ordering = array();
		// add groups the user contains if more than the user himself is in the room
		foreach (OC_Group::getUserGroups($userId) as $group) {
			if ( count(OC_Group::usersInGroup($group)) > 1 ) {
				$grooms["group:".$group] = array( "type" => "group", "name" => $group );
				/*if ( UC_ROOM_ONLY_MSGS ) { // TODO: option: maybe private msgs only to users in same rooms ?					
				} */
			}
		}
		// if no group exist create default; NEW in 0.2: no default room!
		//if ( empty($grooms) )
		//	$grooms["group:default"] = array( "type" => "group", "name" => "default" );

		// add all other users
		if ( UC_SINGLE_USER_MSG == true ) {
			foreach (OC_User::getUsers() as $user) {
				if ( $userId != $user ) {
					$urooms["user:"******"type" => "user", "name" => $user );
				}
			}
		}
		$rooms = $grooms + $urooms; 
		return $rooms;
	}	
Example #15
0
$quotaPreset = explode(',', $quotaPreset);
foreach ($quotaPreset as &$preset) {
    $preset = trim($preset);
}
$quotaPreset = array_diff($quotaPreset, array('default', 'none'));
$defaultQuota = OC_Appconfig::getValue('files', 'default_quota', 'none');
$defaultQuotaIsUserDefined = array_search($defaultQuota, $quotaPreset) === false && array_search($defaultQuota, array('none', 'default')) === false;
// load users and quota
foreach ($accessibleUsers as $uid => $displayName) {
    $quota = OC_Preferences::getValue($uid, 'files', 'quota', 'default');
    $isQuotaUserDefined = array_search($quota, $quotaPreset) === false && array_search($quota, array('none', 'default')) === false;
    $name = $displayName;
    if ($displayName !== $uid) {
        $name = $name . ' (' . $uid . ')';
    }
    $user = $userManager->get($uid);
    $users[] = array("name" => $uid, "displayName" => $displayName, "groups" => OC_Group::getUserGroups($uid), 'quota' => $quota, 'isQuotaUserDefined' => $isQuotaUserDefined, 'subadmin' => OC_SubAdmin::getSubAdminsGroups($uid), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin());
}
$tmpl = new OC_Template("settings", "users/main", "user");
$tmpl->assign('users', $users);
$tmpl->assign('groups', $groups);
$tmpl->assign('adminGroup', $adminGroup);
$tmpl->assign('isAdmin', (int) $isAdmin);
$tmpl->assign('subadmins', $subadmins);
$tmpl->assign('numofgroups', count($groups) + count($adminGroup));
$tmpl->assign('quota_preset', $quotaPreset);
$tmpl->assign('default_quota', $defaultQuota);
$tmpl->assign('defaultQuotaIsUserDefined', $defaultQuotaIsUserDefined);
$tmpl->assign('recoveryAdminEnabled', $recoveryAdminEnabled);
$tmpl->assign('enableAvatars', \OC::$server->getConfig()->getSystemValue('enable_avatars', true));
$tmpl->printPage();
Example #16
0
OC_Util::addStyle('settings', 'settings');
OC_App::setActiveNavigationEntry('core_users');
$users = array();
$groups = array();
$isadmin = OC_Group::inGroup(OC_User::getUser(), 'admin') ? true : false;
if ($isadmin) {
    $accessiblegroups = OC_Group::getGroups();
    $accessibleusers = OC_User::getUsers('', 30);
    $subadmins = OC_SubAdmin::getAllSubAdmins();
} else {
    $accessiblegroups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    $accessibleusers = OC_Group::usersInGroups($accessiblegroups, '', 30);
    $subadmins = false;
}
foreach ($accessibleusers as $i) {
    $users[] = array("name" => $i, "groups" => join(", ", OC_Group::getUserGroups($i)), 'quota' => OC_Preferences::getValue($i, 'files', 'quota', 'default'), 'subadmin' => implode(', ', OC_SubAdmin::getSubAdminsGroups($i)));
}
foreach ($accessiblegroups as $i) {
    // Do some more work here soon
    $groups[] = array("name" => $i);
}
$quotaPreset = OC_Appconfig::getValue('files', 'quota_preset', 'default,none,1 GB, 5 GB, 10 GB');
$quotaPreset = explode(',', $quotaPreset);
foreach ($quotaPreset as &$preset) {
    $preset = trim($preset);
}
$defaultQuota = OC_Appconfig::getValue('files', 'default_quota', 'none');
$tmpl = new OC_Template("settings", "users", "user");
$tmpl->assign("users", $users);
$tmpl->assign("groups", $groups);
$tmpl->assign('isadmin', (int) $isadmin);
Example #17
0
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
OC_JSON::callCheck();
OC_JSON::checkSubAdminUser();
if (isset($_GET['offset'])) {
    $offset = $_GET['offset'];
} else {
    $offset = 0;
}
if (isset($_GET['limit'])) {
    $limit = $_GET['limit'];
} else {
    $limit = 10;
}
$users = array();
if (OC_User::isAdminUser(OC_User::getUser())) {
    $batch = OC_User::getDisplayNames('', $limit, $offset);
    foreach ($batch as $user => $displayname) {
        $users[] = array('name' => $user, 'displayname' => $displayname, 'groups' => join(', ', OC_Group::getUserGroups($user)), 'subadmin' => join(', ', OC_SubAdmin::getSubAdminsGroups($user)), 'quota' => OC_Preferences::getValue($user, 'files', 'quota', 'default'));
    }
} else {
    $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    $batch = OC_Group::usersInGroups($groups, '', $limit, $offset);
    foreach ($batch as $user) {
        $users[] = array('name' => $user, 'displayname' => OC_User::getDisplayName($user), 'groups' => join(', ', OC_Group::getUserGroups($user)), 'quota' => OC_Preferences::getValue($user, 'files', 'quota', 'default'));
    }
}
OC_JSON::success(array('data' => $users));
Example #18
0
$quotaPreset = explode(',', $quotaPreset);
foreach ($quotaPreset as &$preset) {
    $preset = trim($preset);
}
$quotaPreset = array_diff($quotaPreset, array('default', 'none'));
$defaultQuota = OC_Appconfig::getValue('files', 'default_quota', 'none');
$defaultQuotaIsUserDefined = array_search($defaultQuota, $quotaPreset) === false && array_search($defaultQuota, array('none', 'default')) === false;
// load users and quota
foreach ($accessibleusers as $uid => $displayName) {
    $quota = OC_Preferences::getValue($uid, 'files', 'quota', 'default');
    $isQuotaUserDefined = array_search($quota, $quotaPreset) === false && array_search($quota, array('none', 'default')) === false;
    $name = $displayName;
    if ($displayName !== $uid) {
        $name = $name . ' (' . $uid . ')';
    }
    $users[] = array("name" => $uid, "displayName" => $displayName, "groups" => OC_Group::getUserGroups($uid), 'quota' => $quota, 'isQuotaUserDefined' => $isQuotaUserDefined, 'subadmin' => OC_SubAdmin::getSubAdminsGroups($uid));
}
foreach ($accessiblegroups as $i) {
    // Do some more work here soon
    $groups[] = array("name" => $i);
}
$tmpl = new OC_Template("settings", "users", "user");
$tmpl->assign('users', $users);
$tmpl->assign('groups', $groups);
$tmpl->assign('isadmin', (int) $isadmin);
$tmpl->assign('subadmins', $subadmins);
$tmpl->assign('numofgroups', count($accessiblegroups));
$tmpl->assign('quota_preset', $quotaPreset);
$tmpl->assign('default_quota', $defaultQuota);
$tmpl->assign('defaultQuotaIsUserDefined', $defaultQuotaIsUserDefined);
$tmpl->assign('recoveryAdminEnabled', $recoveryAdminEnabled);
Example #19
0
 /**
  * @brief delete a user
  * @param $uid The username of the user to delete
  * @returns true/false
  *
  * Deletes a user
  */
 public static function deleteUser($uid)
 {
     $run = true;
     OC_Hook::emit("OC_User", "pre_deleteUser", array("run" => &$run, "uid" => $uid));
     if ($run) {
         //delete the user from all backends
         foreach (self::$_usedBackends as $backend) {
             if ($backend->implementsActions(OC_USER_BACKEND_DELETE_USER)) {
                 $backend->deleteUser($uid);
             }
         }
         // We have to delete the user from all groups
         foreach (OC_Group::getUserGroups($uid) as $i) {
             OC_Group::removeFromGroup($uid, $i);
         }
         // Delete the user's keys in preferences
         OC_Preferences::deleteUser($uid);
         // Emit and exit
         OC_Hook::emit("OC_User", "post_deleteUser", array("uid" => $uid));
         return true;
     } else {
         return false;
     }
 }
Example #20
0
 public function testMultiBackend()
 {
     $userBackend = new \Test\Util\User\Dummy();
     \OC_User::getManager()->registerBackend($userBackend);
     $backend1 = new OC_Group_Dummy();
     $backend2 = new OC_Group_Dummy();
     OC_Group::useBackend($backend1);
     OC_Group::useBackend($backend2);
     $group1 = $this->getUniqueID();
     $group2 = $this->getUniqueID();
     OC_Group::createGroup($group1);
     //groups should be added to the first registered backend
     $this->assertEquals(array($group1), $backend1->getGroups());
     $this->assertEquals(array(), $backend2->getGroups());
     $this->assertEquals(array($group1), OC_Group::getGroups());
     $this->assertTrue(OC_Group::groupExists($group1));
     $this->assertFalse(OC_Group::groupExists($group2));
     $backend1->createGroup($group2);
     $this->assertEquals(array($group1, $group2), OC_Group::getGroups());
     $this->assertTrue(OC_Group::groupExists($group1));
     $this->assertTrue(OC_Group::groupExists($group2));
     $user1 = $this->getUniqueID();
     $user2 = $this->getUniqueID();
     $userBackend->createUser($user1, '');
     $userBackend->createUser($user2, '');
     $this->assertFalse(OC_Group::inGroup($user1, $group1));
     $this->assertFalse(OC_Group::inGroup($user2, $group1));
     $this->assertTrue(OC_Group::addToGroup($user1, $group1));
     $this->assertTrue(OC_Group::inGroup($user1, $group1));
     $this->assertFalse(OC_Group::inGroup($user2, $group1));
     $this->assertFalse($backend2->inGroup($user1, $group1));
     OC_Group::addToGroup($user1, $group1);
     $this->assertEquals(array($user1), OC_Group::usersInGroup($group1));
     $this->assertEquals(array($group1), OC_Group::getUserGroups($user1));
     $this->assertEquals(array(), OC_Group::getUserGroups($user2));
     OC_Group::deleteGroup($group1);
     $this->assertEquals(array(), OC_Group::getUserGroups($user1));
     $this->assertEquals(array(), OC_Group::usersInGroup($group1));
     $this->assertFalse(OC_Group::inGroup($user1, $group1));
 }
Example #21
0
 private function isAdmin()
 {
     $this->requireLogin();
     $groups = \OC_Group::getUserGroups($this->userId);
     return in_array('admin', $groups, true);
 }
Example #22
0
 /**
  * @brief delete a user
  * @param string $uid The username of the user to delete
  * @return bool
  *
  * Deletes a user
  */
 public static function deleteUser($uid)
 {
     $user = self::getManager()->get($uid);
     if ($user) {
         $result = $user->delete();
         // if delete was successful we clean-up the rest
         if ($result) {
             // We have to delete the user from all groups
             foreach (OC_Group::getUserGroups($uid) as $i) {
                 OC_Group::removeFromGroup($uid, $i);
             }
             // Delete the user's keys in preferences
             OC_Preferences::deleteUser($uid);
             // Delete user files in /data/
             $home = \OC_User::getHome($uid);
             OC_Helper::rmdirr($home);
             // Delete the users entry in the storage table
             \OC\Files\Cache\Storage::remove('home::' . $uid);
             \OC\Files\Cache\Storage::remove('local::' . $home . '/');
             // Remove it from the Cache
             self::getManager()->delete($uid);
         }
         return true;
     } else {
         return false;
     }
 }
Example #23
0
/**
* Gets an array of groups and will try to add the group to OC and then add the user to the groups.
* 
*/
function update_groups($uid, $groups, $protected_groups = array(), $just_created = false)
{
    if (!$just_created) {
        $old_groups = OC_Group::getUserGroups($uid);
        foreach ($old_groups as $group) {
            if (!in_array($group, $protected_groups) && !in_array($group, $groups)) {
                \OC_Group::removeFromGroup($uid, $group);
                \OCP\Util::writeLog('cas', 'Removed "' . $uid . '" from the group "' . $group . '"', \OCP\Util::DEBUG);
            }
        }
    }
    foreach ($groups as $group) {
        if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $group)) {
            \OCP\Util::writeLog('cas', 'Invalid group "' . $group . '", allowed chars "a-zA-Z0-9" and "_.@-" ', \OCP\Util::DEBUG);
        } else {
            if (!\OC_Group::inGroup($uid, $group)) {
                if (!OC_Group::groupExists($group)) {
                    \OC_Group::createGroup($group);
                    \OCP\Util::writeLog('cas', 'New group created: ' . $group, \OCP\Util::DEBUG);
                }
                \OC_Group::addToGroup($uid, $group);
                \OCP\Util::writeLog('cas', 'Added "' . $uid . '" to the group "' . $group . '"', \OCP\Util::DEBUG);
            }
        }
    }
}
Example #24
0
 public static function getUsersGroups($parameters)
 {
     $userid = $parameters['userid'];
     return array('groups' => OC_Group::getUserGroups($userid));
 }
Example #25
0
 private static function update_groups($uid, $groups, $protectedGroups = array(), $just_created = false)
 {
     if (!$just_created) {
         $old_groups = OC_Group::getUserGroups($uid);
         foreach ($old_groups as $group) {
             if (!in_array($group, $protectedGroups) && !in_array($group, $groups)) {
                 // This does not affect groups from user_group_admin
                 OC_Group::removeFromGroup($uid, $group);
                 OC_Log::write('saml', 'Removed "' . $uid . '" from the group "' . $group . '"', OC_Log::DEBUG);
             }
         }
     }
     foreach ($groups as $group) {
         if (preg_match('/[^a-zA-Z0-9 _\\.@\\-\\/]/', $group)) {
             OC_Log::write('saml', 'Invalid group "' . $group . '", allowed chars "a-zA-Z0-9" and "_.@-/" ', OC_Log::DEBUG);
         } else {
             if (!OC_Group::inGroup($uid, $group)) {
                 if (!OC_Group::groupExists($group)) {
                     if (OCP\App::isEnabled('user_group_admin')) {
                         OC_User_Group_Admin_Util::createHiddenGroup($group);
                     } else {
                         OC_Group::createGroup($group);
                     }
                     OC_Log::write('saml', 'New group created: ' . $group, OC_Log::DEBUG);
                 }
                 if (OCP\App::isEnabled('user_group_admin')) {
                     OC_User_Group_Admin_Util::addToGroup($uid, $group);
                 } else {
                     OC_Group::addToGroup($uid, $group);
                 }
                 OC_Log::write('saml', 'Added "' . $uid . '" to the group "' . $group . '"', OC_Log::DEBUG);
             }
         }
     }
 }
Example #26
0
 /**
  * Delete all reshares of an item
  * @param int Id of item to delete
  * @param bool If true, exclude the parent from the delete (optional)
  * @param string The user that the parent was shared with (optinal)
  */
 private static function delete($parent, $excludeParent = false, $uidOwner = null)
 {
     $ids = array($parent);
     $parents = array($parent);
     while (!empty($parents)) {
         $parents = "'" . implode("','", $parents) . "'";
         // Check the owner on the first search of reshares, useful for
         // finding and deleting the reshares by a single user of a group share
         if (count($ids) == 1 && isset($uidOwner)) {
             $query = \OC_DB::prepare('SELECT `id`, `uid_owner`, `item_type`, `item_target`, `parent`' . ' FROM `*PREFIX*share` WHERE `parent` IN (' . $parents . ') AND `uid_owner` = ?');
             $result = $query->execute(array($uidOwner));
         } else {
             $query = \OC_DB::prepare('SELECT `id`, `item_type`, `item_target`, `parent`, `uid_owner`' . ' FROM `*PREFIX*share` WHERE `parent` IN (' . $parents . ')');
             $result = $query->execute();
         }
         // Reset parents array, only go through loop again if items are found
         $parents = array();
         while ($item = $result->fetchRow()) {
             // Search for a duplicate parent share, this occurs when an
             // item is shared to the same user through a group and user or the
             // same item is shared by different users
             $userAndGroups = array_merge(array($item['uid_owner']), \OC_Group::getUserGroups($item['uid_owner']));
             $query = \OC_DB::prepare('SELECT `id`, `permissions` FROM `*PREFIX*share`' . ' WHERE `item_type` = ?' . ' AND `item_target` = ?' . ' AND `share_type` IN (?,?,?)' . ' AND `share_with` IN (\'' . implode('\',\'', $userAndGroups) . '\')' . ' AND `uid_owner` != ? AND `id` != ?');
             $duplicateParent = $query->execute(array($item['item_type'], $item['item_target'], self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique, $item['uid_owner'], $item['parent']))->fetchRow();
             if ($duplicateParent) {
                 // Change the parent to the other item id if share permission is granted
                 if ($duplicateParent['permissions'] & PERMISSION_SHARE) {
                     $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `parent` = ? WHERE `id` = ?');
                     $query->execute(array($duplicateParent['id'], $item['id']));
                     continue;
                 }
             }
             $ids[] = $item['id'];
             $parents[] = $item['id'];
         }
     }
     if ($excludeParent) {
         unset($ids[0]);
     }
     if (!empty($ids)) {
         $ids = "'" . implode("','", $ids) . "'";
         $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` IN (' . $ids . ')');
         $query->execute();
     }
 }
Example #27
0
 /**
  * Get shared items from the database
  * @param string $itemType
  * @param string $item Item source or target (optional)
  * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, SHARE_TYPE_LINK, $shareTypeUserAndGroups, or $shareTypeGroupUserUnique
  * @param string $shareWith User or group the item is being shared with
  * @param string $uidOwner User that is the owner of shared items (optional)
  * @param int $format Format to convert items to with formatItems() (optional)
  * @param mixed $parameters to pass to formatItems() (optional)
  * @param int $limit Number of items to return, -1 to return all matches (optional)
  * @param boolean $includeCollections Include collection item types (optional)
  * @param boolean $itemShareWithBySource (optional)
  * @param boolean $checkExpireDate
  * @return array
  *
  * See public functions getItem(s)... for parameter usage
  *
  */
 public static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false, $itemShareWithBySource = false, $checkExpireDate = true)
 {
     if (!self::isEnabled()) {
         return array();
     }
     $backend = self::getBackend($itemType);
     $collectionTypes = false;
     // Get filesystem root to add it to the file target and remove from the
     // file source, match file_source with the file cache
     if ($itemType == 'file' || $itemType == 'folder') {
         if (!is_null($uidOwner)) {
             $root = \OC\Files\Filesystem::getRoot();
         } else {
             $root = '';
         }
         $where = 'INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` ';
         if (!isset($item)) {
             $where .= ' AND `file_target` IS NOT NULL ';
         }
         $where .= 'INNER JOIN `*PREFIX*storages` ON `numeric_id` = `*PREFIX*filecache`.`storage` ';
         $fileDependent = true;
         $queryArgs = array();
     } else {
         $fileDependent = false;
         $root = '';
         $collectionTypes = self::getCollectionItemTypes($itemType);
         if ($includeCollections && !isset($item) && $collectionTypes) {
             // If includeCollections is true, find collections of this item type, e.g. a music album contains songs
             if (!in_array($itemType, $collectionTypes)) {
                 $itemTypes = array_merge(array($itemType), $collectionTypes);
             } else {
                 $itemTypes = $collectionTypes;
             }
             $placeholders = join(',', array_fill(0, count($itemTypes), '?'));
             $where = ' WHERE `item_type` IN (' . $placeholders . '))';
             $queryArgs = $itemTypes;
         } else {
             $where = ' WHERE `item_type` = ?';
             $queryArgs = array($itemType);
         }
     }
     if (\OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
         $where .= ' AND `share_type` != ?';
         $queryArgs[] = self::SHARE_TYPE_LINK;
     }
     if (isset($shareType)) {
         // Include all user and group items
         if ($shareType == self::$shareTypeUserAndGroups && isset($shareWith)) {
             $where .= ' AND ((`share_type` in (?, ?) AND `share_with` = ?) ';
             $queryArgs[] = self::SHARE_TYPE_USER;
             $queryArgs[] = self::$shareTypeGroupUserUnique;
             $queryArgs[] = $shareWith;
             $groups = \OC_Group::getUserGroups($shareWith);
             if (!empty($groups)) {
                 $placeholders = join(',', array_fill(0, count($groups), '?'));
                 $where .= ' OR (`share_type` = ? AND `share_with` IN (' . $placeholders . ')) ';
                 $queryArgs[] = self::SHARE_TYPE_GROUP;
                 $queryArgs = array_merge($queryArgs, $groups);
             }
             $where .= ')';
             // Don't include own group shares
             $where .= ' AND `uid_owner` != ?';
             $queryArgs[] = $shareWith;
         } else {
             $where .= ' AND `share_type` = ?';
             $queryArgs[] = $shareType;
             if (isset($shareWith)) {
                 $where .= ' AND `share_with` = ?';
                 $queryArgs[] = $shareWith;
             }
         }
     }
     if (isset($uidOwner)) {
         $where .= ' AND `uid_owner` = ?';
         $queryArgs[] = $uidOwner;
         if (!isset($shareType)) {
             // Prevent unique user targets for group shares from being selected
             $where .= ' AND `share_type` != ?';
             $queryArgs[] = self::$shareTypeGroupUserUnique;
         }
         if ($fileDependent) {
             $column = 'file_source';
         } else {
             $column = 'item_source';
         }
     } else {
         if ($fileDependent) {
             $column = 'file_target';
         } else {
             $column = 'item_target';
         }
     }
     if (isset($item)) {
         $collectionTypes = self::getCollectionItemTypes($itemType);
         if ($includeCollections && $collectionTypes && !in_array('folder', $collectionTypes)) {
             $where .= ' AND (';
         } else {
             $where .= ' AND';
         }
         // If looking for own shared items, check item_source else check item_target
         if (isset($uidOwner) || $itemShareWithBySource) {
             // If item type is a file, file source needs to be checked in case the item was converted
             if ($fileDependent) {
                 $where .= ' `file_source` = ?';
                 $column = 'file_source';
             } else {
                 $where .= ' `item_source` = ?';
                 $column = 'item_source';
             }
         } else {
             if ($fileDependent) {
                 $where .= ' `file_target` = ?';
                 $item = \OC\Files\Filesystem::normalizePath($item);
             } else {
                 $where .= ' `item_target` = ?';
             }
         }
         $queryArgs[] = $item;
         if ($includeCollections && $collectionTypes && !in_array('folder', $collectionTypes)) {
             $placeholders = join(',', array_fill(0, count($collectionTypes), '?'));
             $where .= ' OR `item_type` IN (' . $placeholders . '))';
             $queryArgs = array_merge($queryArgs, $collectionTypes);
         }
     }
     if ($shareType == self::$shareTypeUserAndGroups && $limit === 1) {
         // Make sure the unique user target is returned if it exists,
         // unique targets should follow the group share in the database
         // If the limit is not 1, the filtering can be done later
         $where .= ' ORDER BY `*PREFIX*share`.`id` DESC';
     } else {
         $where .= ' ORDER BY `*PREFIX*share`.`id` ASC';
     }
     if ($limit != -1 && !$includeCollections) {
         // The limit must be at least 3, because filtering needs to be done
         if ($limit < 3) {
             $queryLimit = 3;
         } else {
             $queryLimit = $limit;
         }
     } else {
         $queryLimit = null;
     }
     $select = self::createSelectStatement($format, $fileDependent, $uidOwner);
     $root = strlen($root);
     $query = \OC_DB::prepare('SELECT ' . $select . ' FROM `*PREFIX*share` ' . $where, $queryLimit);
     $result = $query->execute($queryArgs);
     if (\OC_DB::isError($result)) {
         \OCP\Util::writeLog('OCP\\Share', \OC_DB::getErrorMessage() . ', select=' . $select . ' where=', \OCP\Util::ERROR);
     }
     $items = array();
     $targets = array();
     $switchedItems = array();
     $mounts = array();
     while ($row = $result->fetchRow()) {
         self::transformDBResults($row);
         // Filter out duplicate group shares for users with unique targets
         if ($fileDependent && !self::isFileReachable($row['path'], $row['storage_id'])) {
             continue;
         }
         if ($row['share_type'] == self::$shareTypeGroupUserUnique && isset($items[$row['parent']])) {
             $row['share_type'] = self::SHARE_TYPE_GROUP;
             $row['unique_name'] = true;
             // remember that we use a unique name for this user
             $row['share_with'] = $items[$row['parent']]['share_with'];
             // if the group share was unshared from the user we keep the permission, otherwise
             // we take the permission from the parent because this is always the up-to-date
             // permission for the group share
             if ($row['permissions'] > 0) {
                 $row['permissions'] = $items[$row['parent']]['permissions'];
             }
             // Remove the parent group share
             unset($items[$row['parent']]);
             if ($row['permissions'] == 0) {
                 continue;
             }
         } else {
             if (!isset($uidOwner)) {
                 // Check if the same target already exists
                 if (isset($targets[$row['id']])) {
                     // Check if the same owner shared with the user twice
                     // through a group and user share - this is allowed
                     $id = $targets[$row['id']];
                     if (isset($items[$id]) && $items[$id]['uid_owner'] == $row['uid_owner']) {
                         // Switch to group share type to ensure resharing conditions aren't bypassed
                         if ($items[$id]['share_type'] != self::SHARE_TYPE_GROUP) {
                             $items[$id]['share_type'] = self::SHARE_TYPE_GROUP;
                             $items[$id]['share_with'] = $row['share_with'];
                         }
                         // Switch ids if sharing permission is granted on only
                         // one share to ensure correct parent is used if resharing
                         if (~(int) $items[$id]['permissions'] & \OCP\Constants::PERMISSION_SHARE && (int) $row['permissions'] & \OCP\Constants::PERMISSION_SHARE) {
                             $items[$row['id']] = $items[$id];
                             $switchedItems[$id] = $row['id'];
                             unset($items[$id]);
                             $id = $row['id'];
                         }
                         $items[$id]['permissions'] |= (int) $row['permissions'];
                     }
                     continue;
                 } elseif (!empty($row['parent'])) {
                     $targets[$row['parent']] = $row['id'];
                 }
             }
         }
         // Remove root from file source paths if retrieving own shared items
         if (isset($uidOwner) && isset($row['path'])) {
             if (isset($row['parent'])) {
                 $query = \OC_DB::prepare('SELECT `file_target` FROM `*PREFIX*share` WHERE `id` = ?');
                 $parentResult = $query->execute(array($row['parent']));
                 if (\OC_DB::isError($result)) {
                     \OCP\Util::writeLog('OCP\\Share', 'Can\'t select parent: ' . \OC_DB::getErrorMessage() . ', select=' . $select . ' where=' . $where, \OCP\Util::ERROR);
                 } else {
                     $parentRow = $parentResult->fetchRow();
                     $tmpPath = $parentRow['file_target'];
                     // find the right position where the row path continues from the target path
                     $pos = strrpos($row['path'], $parentRow['file_target']);
                     $subPath = substr($row['path'], $pos);
                     $splitPath = explode('/', $subPath);
                     foreach (array_slice($splitPath, 2) as $pathPart) {
                         $tmpPath = $tmpPath . '/' . $pathPart;
                     }
                     $row['path'] = $tmpPath;
                 }
             } else {
                 if (!isset($mounts[$row['storage']])) {
                     $mountPoints = \OC\Files\Filesystem::getMountByNumericId($row['storage']);
                     if (is_array($mountPoints) && !empty($mountPoints)) {
                         $mounts[$row['storage']] = current($mountPoints);
                     }
                 }
                 if (!empty($mounts[$row['storage']])) {
                     $path = $mounts[$row['storage']]->getMountPoint() . $row['path'];
                     $relPath = substr($path, $root);
                     // path relative to data/user
                     $row['path'] = rtrim($relPath, '/');
                 }
             }
         }
         if ($checkExpireDate) {
             if (self::expireItem($row)) {
                 continue;
             }
         }
         // Check if resharing is allowed, if not remove share permission
         if (isset($row['permissions']) && !self::isResharingAllowed() | \OCP\Util::isSharingDisabledForUser()) {
             $row['permissions'] &= ~\OCP\Constants::PERMISSION_SHARE;
         }
         // Add display names to result
         $row['share_with_displayname'] = $row['share_with'];
         if (isset($row['share_with']) && $row['share_with'] != '' && $row['share_type'] === self::SHARE_TYPE_USER) {
             $row['share_with_displayname'] = \OCP\User::getDisplayName($row['share_with']);
         } else {
             if (isset($row['share_with']) && $row['share_with'] != '' && $row['share_type'] === self::SHARE_TYPE_REMOTE) {
                 $addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD']);
                 foreach ($addressBookEntries as $entry) {
                     foreach ($entry['CLOUD'] as $cloudID) {
                         if ($cloudID === $row['share_with']) {
                             $row['share_with_displayname'] = $entry['FN'];
                         }
                     }
                 }
             }
         }
         if (isset($row['uid_owner']) && $row['uid_owner'] != '') {
             $row['displayname_owner'] = \OCP\User::getDisplayName($row['uid_owner']);
         }
         if ($row['permissions'] > 0) {
             $items[$row['id']] = $row;
         }
     }
     // group items if we are looking for items shared with the current user
     if (isset($shareWith) && $shareWith === \OCP\User::getUser()) {
         $items = self::groupItems($items, $itemType);
     }
     if (!empty($items)) {
         $collectionItems = array();
         foreach ($items as &$row) {
             // Return only the item instead of a 2-dimensional array
             if ($limit == 1 && $row[$column] == $item && ($row['item_type'] == $itemType || $itemType == 'file')) {
                 if ($format == self::FORMAT_NONE) {
                     return $row;
                 } else {
                     break;
                 }
             }
             // Check if this is a collection of the requested item type
             if ($includeCollections && $collectionTypes && $row['item_type'] !== 'folder' && in_array($row['item_type'], $collectionTypes)) {
                 if (($collectionBackend = self::getBackend($row['item_type'])) && $collectionBackend instanceof \OCP\Share_Backend_Collection) {
                     // Collections can be inside collections, check if the item is a collection
                     if (isset($item) && $row['item_type'] == $itemType && $row[$column] == $item) {
                         $collectionItems[] = $row;
                     } else {
                         $collection = array();
                         $collection['item_type'] = $row['item_type'];
                         if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') {
                             $collection['path'] = basename($row['path']);
                         }
                         $row['collection'] = $collection;
                         // Fetch all of the children sources
                         $children = $collectionBackend->getChildren($row[$column]);
                         foreach ($children as $child) {
                             $childItem = $row;
                             $childItem['item_type'] = $itemType;
                             if ($row['item_type'] != 'file' && $row['item_type'] != 'folder') {
                                 $childItem['item_source'] = $child['source'];
                                 $childItem['item_target'] = $child['target'];
                             }
                             if ($backend instanceof \OCP\Share_Backend_File_Dependent) {
                                 if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') {
                                     $childItem['file_source'] = $child['source'];
                                 } else {
                                     // TODO is this really needed if we already know that we use the file backend?
                                     $meta = \OC\Files\Filesystem::getFileInfo($child['file_path']);
                                     $childItem['file_source'] = $meta['fileid'];
                                 }
                                 $childItem['file_target'] = \OC\Files\Filesystem::normalizePath($child['file_path']);
                             }
                             if (isset($item)) {
                                 if ($childItem[$column] == $item) {
                                     // Return only the item instead of a 2-dimensional array
                                     if ($limit == 1) {
                                         if ($format == self::FORMAT_NONE) {
                                             return $childItem;
                                         } else {
                                             // Unset the items array and break out of both loops
                                             $items = array();
                                             $items[] = $childItem;
                                             break 2;
                                         }
                                     } else {
                                         $collectionItems[] = $childItem;
                                     }
                                 }
                             } else {
                                 $collectionItems[] = $childItem;
                             }
                         }
                     }
                 }
                 // Remove collection item
                 $toRemove = $row['id'];
                 if (array_key_exists($toRemove, $switchedItems)) {
                     $toRemove = $switchedItems[$toRemove];
                 }
                 unset($items[$toRemove]);
             } elseif ($includeCollections && $collectionTypes && in_array($row['item_type'], $collectionTypes)) {
                 // FIXME: Thats a dirty hack to improve file sharing performance,
                 // see github issue #10588 for more details
                 // Need to find a solution which works for all back-ends
                 $collectionBackend = self::getBackend($row['item_type']);
                 $sharedParents = $collectionBackend->getParents($row['item_source']);
                 foreach ($sharedParents as $parent) {
                     $collectionItems[] = $parent;
                 }
             }
         }
         if (!empty($collectionItems)) {
             $collectionItems = array_unique($collectionItems, SORT_REGULAR);
             $items = array_merge($items, $collectionItems);
         }
         // filter out invalid items, these can appear when subshare entries exist
         // for a group in which the requested user isn't a member any more
         $items = array_filter($items, function ($item) {
             return $item['share_type'] !== self::$shareTypeGroupUserUnique;
         });
         return self::formatResult($items, $column, $backend, $format, $parameters);
     } elseif ($includeCollections && $collectionTypes && in_array('folder', $collectionTypes)) {
         // FIXME: Thats a dirty hack to improve file sharing performance,
         // see github issue #10588 for more details
         // Need to find a solution which works for all back-ends
         $collectionItems = array();
         $collectionBackend = self::getBackend('folder');
         $sharedParents = $collectionBackend->getParents($item, $shareWith, $uidOwner);
         foreach ($sharedParents as $parent) {
             $collectionItems[] = $parent;
         }
         if ($limit === 1) {
             return reset($collectionItems);
         }
         return self::formatResult($collectionItems, $column, $backend, $format, $parameters);
     }
     return array();
 }
Example #28
0
    $pattern = $_GET['pattern'];
} else {
    $pattern = '';
}
$users = array();
$userManager = \OC_User::getManager();
if (OC_User::isAdminUser(OC_User::getUser())) {
    if ($gid !== false) {
        $batch = OC_Group::displayNamesInGroup($gid, $pattern, $limit, $offset);
    } else {
        $batch = OC_User::getDisplayNames($pattern, $limit, $offset);
    }
    foreach ($batch as $uid => $displayname) {
        $user = $userManager->get($uid);
        $users[] = array('name' => $uid, 'displayname' => $displayname, 'groups' => join(', ', OC_Group::getUserGroups($uid)), 'subadmin' => join(', ', OC_SubAdmin::getSubAdminsGroups($uid)), 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin());
    }
} else {
    $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    if ($gid !== false && in_array($gid, $groups)) {
        $groups = array($gid);
    } elseif ($gid !== false) {
        //don't you try to investigate loops you must not know about
        $groups = array();
    }
    $batch = OC_Group::usersInGroups($groups, $pattern, $limit, $offset);
    foreach ($batch as $uid) {
        $user = $userManager->get($uid);
        $users[] = array('name' => $user, 'displayname' => $user->getDisplayName(), 'groups' => join(', ', OC_Group::getUserGroups($uid)), 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin());
    }
}
OC_JSON::success(array('data' => $users));
Example #29
0
                 }
                 foreach ($emails as $email) {
                     $result[] = array('id' => $contact['id'], 'email' => $email, 'displayname' => $contact['FN']);
                 }
             }
         }
     }
     OC_JSON::success(array('data' => $result));
     break;
 case 'getShareWith':
     if (isset($_GET['search'])) {
         $shareWithinGroupOnly = OC\Share\Share::shareWithGroupMembersOnly();
         $shareWith = array();
         $groups = OC_Group::getGroups((string) $_GET['search']);
         if ($shareWithinGroupOnly) {
             $usergroups = OC_Group::getUserGroups(OC_User::getUser());
             $groups = array_intersect($groups, $usergroups);
         }
         $count = 0;
         $users = array();
         $limit = 0;
         $offset = 0;
         while ($count < 15 && count($users) == $limit) {
             $limit = 15 - $count;
             if ($shareWithinGroupOnly) {
                 $users = OC_Group::DisplayNamesInGroups($usergroups, (string) $_GET['search'], $limit, $offset);
             } else {
                 $users = OC_User::getDisplayNames((string) $_GET['search'], $limit, $offset);
             }
             $offset += $limit;
             foreach ($users as $uid => $displayName) {
Example #30
0
        }
        if (count($groups) === 0) {
            $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
        }
    } else {
        $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    }
}
$username = $_POST["username"];
$password = $_POST["password"];
// Return Success story
try {
    // check whether the user's files home exists
    $userDirectory = OC_User::getHome($username) . '/files/';
    $homeExists = file_exists($userDirectory);
    if (!OC_User::createUser($username, $password)) {
        OC_JSON::error(array('data' => array('message' => 'User creation failed for ' . $username)));
        exit;
    }
    foreach ($groups as $i) {
        if (!OC_Group::groupExists($i)) {
            OC_Group::createGroup($i);
        }
        OC_Group::addToGroup($username, $i);
    }
    $userManager = \OC_User::getManager();
    $user = $userManager->get($username);
    OCP\JSON::success(array("data" => array("homeExists" => $homeExists, "username" => $username, "groups" => OC_Group::getUserGroups($username), 'storageLocation' => $user->getHome())));
} catch (Exception $exception) {
    OCP\JSON::error(array("data" => array("message" => $exception->getMessage())));
}