Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions lib/private/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ class OC_Group {

/**
* @return \OC\Group\Manager
* @deprecated Use \OC::$server->getGroupManager();
*/
public static function getManager() {
return \OC::$server->getGroupManager();
}

/**
* @return \OC\User\Manager
* @deprecated Use \OC::$server->getUserManager()
*/
private static function getUserManager() {
return \OC::$server->getUserManager();
Expand Down Expand Up @@ -73,12 +75,10 @@ public static function clearBackends() {
*
* Tries to create a new group. If the group name already exists, false will
* be returned. Basic checking of Group name
* @deprecated Use \OC::$server->getGroupManager()->createGroup() instead
*/
public static function createGroup($gid) {
OC_Hook::emit("OC_Group", "pre_createGroup", array("run" => true, "gid" => $gid));

if (self::getManager()->createGroup($gid)) {
OC_Hook::emit("OC_User", "post_createGroup", array("gid" => $gid));
return true;
} else {
return false;
Expand All @@ -91,19 +91,12 @@ public static function createGroup($gid) {
* @return bool
*
* Deletes a group and removes it from the group_user-table
* @deprecated Use \OC::$server->getGroupManager()->delete() instead
*/
public static function deleteGroup($gid) {
// Prevent users from deleting group admin
if ($gid == "admin") {
return false;
}

OC_Hook::emit("OC_Group", "pre_deleteGroup", array("run" => true, "gid" => $gid));

$group = self::getManager()->get($gid);
if ($group) {
if ($group->delete()) {
OC_Hook::emit("OC_User", "post_deleteGroup", array("gid" => $gid));
return true;
}
}
Expand All @@ -117,6 +110,7 @@ public static function deleteGroup($gid) {
* @return bool
*
* Checks whether the user is member of a group or not.
* @deprecated Use \OC::$server->getGroupManager->inGroup($user);
*/
public static function inGroup($uid, $gid) {
$group = self::getManager()->get($gid);
Expand All @@ -134,14 +128,13 @@ public static function inGroup($uid, $gid) {
* @return bool
*
* Adds a user to a group.
* @deprecated Use \OC::$server->getGroupManager->addUser();
*/
public static function addToGroup($uid, $gid) {
$group = self::getManager()->get($gid);
$user = self::getUserManager()->get($uid);
if ($group and $user) {
OC_Hook::emit("OC_Group", "pre_addToGroup", array("run" => true, "uid" => $uid, "gid" => $gid));
$group->addUser($user);
OC_Hook::emit("OC_User", "post_addToGroup", array("uid" => $uid, "gid" => $gid));
return true;
} else {
return false;
Expand Down Expand Up @@ -176,6 +169,7 @@ public static function removeFromGroup($uid, $gid) {
*
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
* @deprecated Use \OC::$server->getGroupManager->getuserGroupIds($user)
*/
public static function getUserGroups($uid) {
$user = self::getUserManager()->get($uid);
Expand Down Expand Up @@ -209,6 +203,7 @@ public static function getGroups($search = '', $limit = null, $offset = null) {
*
* @param string $gid
* @return bool
* @deprecated Use \OC::$server->getGroupManager->groupExists($gid)
*/
public static function groupExists($gid) {
return self::getManager()->groupExists($gid);
Expand Down Expand Up @@ -260,6 +255,7 @@ public static function usersInGroups($gids, $search = '', $limit = -1, $offset =
* @param int $limit
* @param int $offset
* @return array an array of display names (value) and user ids(key)
* @deprecated Use \OC::$server->getGroupManager->displayNamesInGroup($gid, $search, $limit, $offset)
*/
public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
return self::getManager()->displayNamesInGroup($gid, $search, $limit, $offset);
Expand Down
5 changes: 5 additions & 0 deletions lib/private/group/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ public function searchDisplayName($search, $limit = null, $offset = null) {
* @return bool
*/
public function delete() {
// Prevent users from deleting group admin
if ($this->getGID() === 'admin') {
return false;
}

$result = false;
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'preDelete', array($this));
Expand Down
7 changes: 4 additions & 3 deletions lib/private/group/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MetaData {
protected $metaData = array();

/**
* @var \OC\Group\Manager $groupManager
* @var \OCP\IGroupManager $groupManager
*/
protected $groupManager;

Expand All @@ -41,12 +41,12 @@ class MetaData {
/**
* @param string $user the uid of the current user
* @param bool $isAdmin whether the current users is an admin
* @param \OC\Group\Manager $groupManager
* @param \OCP\IGroupManager $groupManager
*/
public function __construct(
$user,
$isAdmin,
\OC\Group\Manager $groupManager
\OCP\IGroupManager $groupManager
) {
$this->user = $user;
$this->isAdmin = (bool)$isAdmin;
Expand Down Expand Up @@ -168,6 +168,7 @@ private function getGroups($search = '') {
if($this->isAdmin) {
return $this->groupManager->search($search);
} else {
// FIXME: Remove static method call
$groupIds = \OC_SubAdmin::getSubAdminsGroups($this->user);

/* \OC_SubAdmin::getSubAdminsGroups() returns an array of GIDs, but this
Expand Down
22 changes: 20 additions & 2 deletions lib/private/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,26 @@ function __construct($webRoot) {
return new \OC\User\Manager($config);
});
$this->registerService('GroupManager', function (Server $c) {
$userManager = $c->getUserManager();
return new \OC\Group\Manager($userManager);
$groupManager = new \OC\Group\Manager($this->getUserManager());
$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
});
$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
});
$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
});
$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
});
$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
});
$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
});
return $groupManager;
});
$this->registerService('UserSession', function (Server $c) {
$manager = $c->getUserManager();
Expand Down
25 changes: 5 additions & 20 deletions lib/private/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static function getUserSession() {

/**
* @return \OC\User\Manager
* @deprecated Use \OC::$server->getUserManager()
*/
public static function getManager() {
return OC::$server->getUserManager();
Expand Down Expand Up @@ -179,6 +180,7 @@ public static function setupBackends() {
* itself, not in its subclasses.
*
* Allowed characters in the username are: "a-z", "A-Z", "0-9" and "_.@-"
* @deprecated Use \OC::$server->getUserManager->createUser($uid, $password)
*/
public static function createUser($uid, $password) {
return self::getManager()->createUser($uid, $password);
Expand All @@ -190,30 +192,12 @@ public static function createUser($uid, $password) {
* @return bool
*
* Deletes a user
* @deprecated Use \OC::$server->getUserManager->delete()
*/
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/
OC_Helper::rmdirr(\OC_User::getHome($uid));

// Delete the users entry in the storage table
\OC\Files\Cache\Storage::remove('home::' . $uid);
}

return true;
return $user->delete();
} else {
return false;
}
Expand Down Expand Up @@ -525,6 +509,7 @@ public static function checkPassword($uid, $password) {
* @return string
*
* returns the path to the users home directory
* @deprecated Use \OC::$server->getUserManager->getHome()
*/
public static function getHome($uid) {
$user = self::getManager()->get($uid);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/user/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function searchDisplayName($pattern, $limit = null, $offset = null) {
* @param string $uid
* @param string $password
* @throws \Exception
* @return bool|\OC\User\User the created user of false
* @return bool|\OC\User\User the created user or false
*/
public function createUser($uid, $password) {
$l = \OC::$server->getL10N('lib');
Expand Down
18 changes: 18 additions & 0 deletions lib/private/user/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ public function delete() {
$this->emitter->emit('\OC\User', 'preDelete', array($this));
}
$result = $this->backend->deleteUser($this->uid);
if ($result) {

// FIXME: Feels like an hack - suggestions?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way ?
Should the storage removal happen somewhere else maybe, through registering to a deleteUser hook ? Maybe something for another time ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd vote to have it done triggered by a hook, but this is not urgent. This goes beyond just deleting and sometimes it might (pure speculation) be useful to have the possibility to "reset" a user. But as long as we don't have the need for it, it is ok to leave it for now/OC 8 like this.


// 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_Preferences::deleteUser($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);
}

if ($this->emitter) {
$this->emitter->emit('\OC\User', 'postDelete', array($this));
}
Expand Down
21 changes: 0 additions & 21 deletions settings/ajax/creategroup.php

This file was deleted.

59 changes: 0 additions & 59 deletions settings/ajax/createuser.php

This file was deleted.

46 changes: 0 additions & 46 deletions settings/ajax/grouplist.php

This file was deleted.

Loading