Skip to content
Closed
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
6 changes: 6 additions & 0 deletions changelog/unreleased/40657
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add per-user storage view

Adding an option for displaying used storage on per-user basis.

https://github.com/owncloud/enterprise/issues/5468
https://github.com/owncloud/core/pull/40657
12 changes: 12 additions & 0 deletions settings/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ private function formatUserForIndex(IUser $user, array $userGroups = null) {
];
}

// we are going to setup a different FS and not reverting it back. There shouldn't anyway be any code needed to access the FS after this
try {
\OC_Util::tearDownFS();
\OC_Util::setupFS($user->getUID());
$storage = \OC_Helper::getStorageInfo('/');
$storageUsed = \OC_Helper::humanFileSize($storage['used']);
} catch (\Exception $e) {
$this->log->debug("Can't compute used storage for user " . $user->getUID() . ": " . $e->getMessage(), ['app' => 'settings']);
$storageUsed = "0 B";
}

return [
'name' => $user->getUID(),
'displayname' => $user->getDisplayName(),
Expand All @@ -234,6 +245,7 @@ private function formatUserForIndex(IUser $user, array $userGroups = null) {
'isEnabled' => $user->isEnabled(),
'quota' => $user->getQuota(),
'storageLocation' => $user->getHome(),
'storageUsed' => $storageUsed,
'lastLogin' => $user->getLastLogin() * 1000,
'creationTime' => $user->getCreationTime() * 1000,
'backend' => $user->getBackendClassName(),
Expand Down
1 change: 1 addition & 0 deletions settings/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ span.usersLastLoginTooltip { white-space: nowrap; }
#userlist .mailAddress,
#userlist .enabled,
#userlist .storageLocation,
#userlist .storageUsed,
#userlist .userBackend,
#userlist .creationTime {
display : none;
Expand Down
21 changes: 20 additions & 1 deletion settings/js/users/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ var UserList = {
*/
$tr.find('td.storageLocation').text(user.storageLocation);

/**
* storage used
*/
$tr.find('td.storageUsed').text(user.storageUsed);

/**
* user backend
*/
Expand Down Expand Up @@ -1091,7 +1096,21 @@ $(document).ready(function () {
OC.AppConfig.setValue('core', 'umgmt_show_storage_location', 'false');
}
});


if ($('#CheckboxStorageUsed').is(':checked')) {
$("#userlist .storageUsed").show();
}
// Option to display/hide the "Storage used" column
$('#CheckboxStorageUsed').click(function() {
if ($('#CheckboxStorageUsed').is(':checked')) {
$("#userlist .storageUsed").show();
OC.AppConfig.setValue('core', 'umgmt_show_storage_used', 'true');
} else {
$("#userlist .storageUsed").hide();
OC.AppConfig.setValue('core', 'umgmt_show_storage_used', 'false');
}
});

if ($('#CheckboxCreationTime').is(':checked')) {
$("#userlist .creationTime").show();
}
Expand Down
9 changes: 9 additions & 0 deletions settings/templates/users/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ class="checkbox" <?php if ($_['show_storage_location'] === 'true') {
<?php p($l->t('Show storage location')) ?>
</label>
</p>
<p>
<input type="checkbox" name="StorageUsed" value="StorageUsed" id="CheckboxStorageUsed"
class="checkbox" <?php if ($_['show_storage_used'] === 'true') {
print_unescaped('checked="checked"');
} ?> />
<label for="CheckboxStorageUsed">
<?php p($l->t('Show storage used')) ?>
</label>
</p>
<p>
<input type="checkbox" name="CreationTime" value="CreationTime" id="CheckboxCreationTime"
class="checkbox" <?php if ($_['show_creation_time'] === 'true') {
Expand Down
2 changes: 2 additions & 0 deletions settings/templates/users/part.userlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<th class="enabled" scope="col"><?php p($l->t('Enabled')); ?></th>
<th class="quota" id="headerQuota" scope="col"><?php p($l->t('Quota')); ?></th>
<th class="storageLocation" scope="col"><?php p($l->t('Storage Location')); ?></th>
<th class="storageUsed" scope="col"><?php p($l->t('Storage Used')); ?></th>
<th class="userBackend" scope="col"><?php p($l->t('User Backend')); ?></th>
<th class="lastLogin" scope="col"><?php p($l->t('Last Login')); ?></th>
<th class="creationTime" scope="col"><?php p($l->t('Creation Time')); ?></th>
Expand Down Expand Up @@ -71,6 +72,7 @@
</select>
</td>
<td class="storageLocation"></td>
<td class="storageUsed"></td>
<td class="userBackend"></td>
<td class="lastLogin"></td>
<td class="creationTime"></td>
Expand Down
1 change: 1 addition & 0 deletions settings/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@

$tmpl->assign('show_is_enabled', $config->getAppValue('core', 'umgmt_show_is_enabled', 'false'));
$tmpl->assign('show_storage_location', $config->getAppValue('core', 'umgmt_show_storage_location', 'false'));
$tmpl->assign('show_storage_used', $config->getAppValue('core', 'umgmt_show_storage_used', 'false'));
$tmpl->assign('show_creation_time', $config->getAppValue('core', 'umgmt_show_creation_time', 'false'));
$tmpl->assign('show_last_login', $config->getAppValue('core', 'umgmt_show_last_login', 'false'));
$tmpl->assign('show_email', $config->getAppValue('core', 'umgmt_show_email', 'false'));
Expand Down
15 changes: 15 additions & 0 deletions tests/Settings/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public function testIndexAdmin(): void {
'isEnabled' => true,
'quota' => 1024,
'storageLocation' => '/home/foo',
'storageUsed' => 0,
'lastLogin' => 500000,
'backend' => 'OC_User_Database',
'email' => 'foo@bar.com',
Expand All @@ -317,6 +318,7 @@ public function testIndexAdmin(): void {
'isEnabled' => true,
'quota' => 404,
'storageLocation' => '/home/admin',
'storageUsed' => 0,
'lastLogin' => 12000,
'backend' => '\Test\Util\User\Dummy',
'email' => 'admin@bar.com',
Expand All @@ -338,6 +340,7 @@ public function testIndexAdmin(): void {
'isEnabled' => false,
'quota' => 2323,
'storageLocation' => '/home/bar',
'storageUsed' => 0,
'lastLogin' => 3999000,
'backend' => '\Test\Util\User\Dummy',
'email' => 'bar@dummy.com',
Expand Down Expand Up @@ -537,6 +540,7 @@ public function testIndexSubAdmin(): void {
'isEnabled' => false,
'quota' => 2323,
'storageLocation' => '/home/bar',
'storageUsed' => 0,
'lastLogin' => 3999000,
'backend' => '\Test\Util\User\Dummy',
'email' => 'bar@dummy.com',
Expand All @@ -562,6 +566,7 @@ public function testIndexSubAdmin(): void {
'isEnabled' => true,
'quota' => 1024,
'storageLocation' => '/home/foo',
'storageUsed' => 0,
'lastLogin' => 500000,
'backend' => 'OC_User_Database',
'email' => 'foo@bar.com',
Expand All @@ -583,6 +588,7 @@ public function testIndexSubAdmin(): void {
'isEnabled' => true,
'quota' => 404,
'storageLocation' => '/home/admin',
'storageUsed' => 0,
'lastLogin' => 12000,
'backend' => '\Test\Util\User\Dummy',
'email' => 'admin@bar.com',
Expand Down Expand Up @@ -755,6 +761,7 @@ public function testIndexWithSearch(): void {
'isEnabled' => true,
'quota' => 1024,
'storageLocation' => '/home/foo',
'storageUsed' => 0,
'lastLogin' => 500000,
'backend' => 'OC_User_Database',
'email' => 'foo@bar.com',
Expand All @@ -780,6 +787,7 @@ public function testIndexWithSearch(): void {
'isEnabled' => true,
'quota' => 404,
'storageLocation' => '/home/admin',
'storageUsed' => 0,
'lastLogin' => 12000,
'backend' => '\Test\Util\User\Dummy',
'email' => 'admin@bar.com',
Expand All @@ -801,6 +809,7 @@ public function testIndexWithSearch(): void {
'isEnabled' => false,
'quota' => 2323,
'storageLocation' => '/home/bar',
'storageUsed' => 0,
'lastLogin' => 3999000,
'backend' => '\Test\Util\User\Dummy',
'email' => 'bar@dummy.com',
Expand Down Expand Up @@ -886,6 +895,7 @@ public function testIndexWithBackend(): void {
'isEnabled' => true,
'quota' => 'none',
'storageLocation' => '/home/foo',
'storageUsed' => 0,
'lastLogin' => 500000,
'backend' => 'OC_User_Database',
'email' => null,
Expand Down Expand Up @@ -959,6 +969,7 @@ public function testCreateSuccessfulWithoutGroupAdmin(): void {
'name' => 'foo',
'groups' => [],
'storageLocation' => '/home/user',
'storageUsed' => 0,
'backend' => 'bar',
'lastLogin' => null,
'displayname' => null,
Expand Down Expand Up @@ -1060,6 +1071,7 @@ public function testCreateSuccessfulWithoutGroupSubAdmin(): void {
],
],
'storageLocation' => '/home/user',
'storageUsed' => 0,
'backend' => 'bar',
'lastLogin' => 0,
'displayname' => null,
Expand Down Expand Up @@ -1156,6 +1168,7 @@ public function testCreateSuccessfulWithGroupAdmin(): void {
],
],
'storageLocation' => '/home/user',
'storageUsed' => 0,
'backend' => 'bar',
'lastLogin' => null,
'displayname' => null,
Expand Down Expand Up @@ -1260,6 +1273,7 @@ public function testCreateSuccessfulWithGroupSubAdmin(): void {
],
],
'storageLocation' => '/home/user',
'storageUsed' => 0,
'backend' => 'bar',
'lastLogin' => 0,
'displayname' => null,
Expand Down Expand Up @@ -1768,6 +1782,7 @@ private function mockUser(
'isEnabled' => $isEnabled,
'quota' => null,
'storageLocation' => $home,
'storageUsed' => 0,
'lastLogin' => $lastLogin * 1000,
'backend' => $backend,
'email' => null,
Expand Down
30 changes: 30 additions & 0 deletions tests/acceptance/features/bootstrap/WebUIUsersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,36 @@ public function theAdministratorShouldBeAbleToSeeCreationTimeOfTheseUsers(
}
}

/**
* @Then /^the administrator should be able to see the used storage of these users in the User Management page:$/
*
* @param TableNode $table table of usernames and last logins with a heading | username | and | used storage |
*
* @return void
* @throws ElementNotVisible
* @throws Exception
*/
public function theAdministratorShouldBeAbleToSeeUsedStorageOfTheseUsers(
TableNode $table
):void {
$this->featureContext->verifyTableNodeColumns($table, ['username', 'used storage']);
foreach ($table as $row) {
$user = $this->featureContext->getActualUsername($row['username']);
$userUsedStorage = $this->usersPage->getUsedStorageOfUser($user);

Assert::assertStringContainsString(
$row['used storage'],
$userUsedStorage,
__METHOD__
. "'"
. $row['used storage']
. "' is not contained in the used storage of '"
. $user
. "'."
);
}
}

/**
* This will run before EVERY scenario.
*
Expand Down
32 changes: 32 additions & 0 deletions tests/acceptance/features/lib/UsersPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class UsersPage extends OwncloudPage {
protected $storageLocationColumnXpath = "//td[@class='storageLocation']";
protected $lastLoginXpath = "//td[@class='lastLogin']";
protected $creationTimeXpath = "//td[@class='creationTime']";
protected $usedStorageXpath = "//td[@class='usedStorage']";

protected $manualQuotaInputXpath
= "//input[contains(@data-original-title,'Please enter storage quota')]";
Expand Down Expand Up @@ -361,6 +362,37 @@ public function getCreationTimeOfUser(string $username): string {
return $this->getTrimmedText($userCreationTime);
}

/**
* @param string $username
*
* @return string used storage of a user
* @throws ElementNotFoundException|ElementNotVisible|Exception
*/
public function getUsedStorageOfUser(string $username): string {
$userTr = $this->findUserInTable($username);
$userUsedStorage = $userTr->find(
'xpath',
$this->usedStorageXpath
);

if ($userUsedStorage === null) {
throw new ElementNotFoundException(
__METHOD__ .
" xpath $this->usedStorageXpath " .
"used storage of user " . $username . " not found"
);
}

if (!$userUsedStorage->isVisible()) {
throw new ElementNotVisible(
__METHOD__ .
" used storage of user " . $username . " is not visible"
);
};

return $this->getTrimmedText($userUsedStorage);
}

/**
* Open the settings menu
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ Feature: add users
| Alice | seconds ago |
| Brian | seconds ago |

Scenario: administrator should be able to see used storage of a user
When the administrator enables the setting "Show storage used" in the User Management page using the webUI
Then the administrator should be able to see the used storage of these users in the User Management page:
| username | used storage |
| Alice | 1 GB |
| Brian | 5 GB |


Scenario: administrator should be able to see password column of user
When the administrator enables the setting "Show password field" in the User Management page using the webUI
Expand Down