Skip to content

Commit

Permalink
[WHIP] Workable Hack In Progress
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Sep 9, 2021
1 parent 2693573 commit 73a8074
Show file tree
Hide file tree
Showing 31 changed files with 1,361 additions and 45 deletions.
2 changes: 1 addition & 1 deletion apps/files_sharing/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
header('Location: ' . $urlGenerator->linkToRoute($route, ['token' => $token]));
} else {
http_response_code(404);
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl = new OCP\Template('', '404-file', 'guest');
print_unescaped($tmpl->fetchPage());
}
2 changes: 1 addition & 1 deletion apps/oauth2/lib/Controller/LoginRedirectorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function authorize($client_id,
$params = [
'content' => $this->l->t('Your client is not authorized to connect. Please inform the administrator of your client.'),
];
return new TemplateResponse('core', '404', $params, 'guest');
return new TemplateResponse('core', '404-file', $params, 'guest');
}

if ($response_type !== 'code') {
Expand Down
1 change: 1 addition & 0 deletions apps/provisioning_api/lib/Controller/AUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ protected function getUserData(string $userId, bool $includeScopes = false): arr
IAccountManager::PROPERTY_ADDRESS,
IAccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_TWITTER,
IAccountManager::PROPERTY_PROFILE_ENABLED,
] as $propertyName) {
$property = $userAccount->getProperty($propertyName);
$data[$propertyName] = $property->getValue();
Expand Down
40 changes: 38 additions & 2 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ public function getEditableFieldsForUser(string $userId): DataResponse {
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
$permittedFields[] = IAccountManager::PROPERTY_COMPANY;
$permittedFields[] = IAccountManager::PROPERTY_JOB_TITLE;
$permittedFields[] = IAccountManager::PROPERTY_HEADLINE;
$permittedFields[] = IAccountManager::PROPERTY_BIOGRAPHY;
$permittedFields[] = IAccountManager::PROPERTY_PROFILE_ENABLED;

return new DataResponse($permittedFields);
}
Expand Down Expand Up @@ -693,11 +698,11 @@ public function editUserMultiValue(
*
* @param string $userId
* @param string $key
* @param string $value
* @param string|bool $value
* @return DataResponse
* @throws OCSException
*/
public function editUser(string $userId, string $key, string $value): DataResponse {
public function editUser(string $userId, string $key, string|bool $value): DataResponse {
$currentLoggedInUser = $this->userSession->getUser();

$targetUser = $this->userManager->get($userId);
Expand Down Expand Up @@ -737,6 +742,11 @@ public function editUser(string $userId, string $key, string $value): DataRespon
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
$permittedFields[] = IAccountManager::PROPERTY_COMPANY;
$permittedFields[] = IAccountManager::PROPERTY_JOB_TITLE;
$permittedFields[] = IAccountManager::PROPERTY_HEADLINE;
$permittedFields[] = IAccountManager::PROPERTY_BIOGRAPHY;
$permittedFields[] = IAccountManager::PROPERTY_PROFILE_ENABLED;
$permittedFields[] = IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX;
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS . self::SCOPE_SUFFIX;
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE . self::SCOPE_SUFFIX;
Expand Down Expand Up @@ -768,6 +778,11 @@ public function editUser(string $userId, string $key, string $value): DataRespon
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
$permittedFields[] = IAccountManager::PROPERTY_COMPANY;
$permittedFields[] = IAccountManager::PROPERTY_JOB_TITLE;
$permittedFields[] = IAccountManager::PROPERTY_HEADLINE;
$permittedFields[] = IAccountManager::PROPERTY_BIOGRAPHY;
$permittedFields[] = IAccountManager::PROPERTY_PROFILE_ENABLED;
$permittedFields[] = 'quota';
} else {
// No rights
Expand Down Expand Up @@ -863,6 +878,10 @@ public function editUser(string $userId, string $key, string $value): DataRespon
case IAccountManager::PROPERTY_ADDRESS:
case IAccountManager::PROPERTY_WEBSITE:
case IAccountManager::PROPERTY_TWITTER:
case IAccountManager::PROPERTY_COMPANY:
case IAccountManager::PROPERTY_JOB_TITLE:
case IAccountManager::PROPERTY_HEADLINE:
case IAccountManager::PROPERTY_BIOGRAPHY:
$userAccount = $this->accountManager->getAccount($targetUser);
try {
$userProperty = $userAccount->getProperty($key);
Expand All @@ -881,6 +900,23 @@ public function editUser(string $userId, string $key, string $value): DataRespon
}
$this->accountManager->updateAccount($userAccount);
break;
case IAccountManager::PROPERTY_PROFILE_ENABLED:
if (!is_bool($value)) {
throw new OCSException('Invalid value, value must be a boolean', 102);
}
$value = $value === true ? '1' : '0';

$userAccount = $this->accountManager->getAccount($targetUser);
try {
$userProperty = $userAccount->getProperty($key);
if ($userProperty->getValue() !== $value) {
$userProperty->setValue($value);
}
} catch (PropertyDoesNotExistException $e) {
$userAccount->setProperty($key, $value, IAccountManager::SCOPE_LOCAL, IAccountManager::NOT_VERIFIED);
}
$this->accountManager->updateAccount($userAccount);
break;
case IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX:
Expand Down
42 changes: 42 additions & 0 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,10 @@ public function testGetUserDataAsAdmin() {
IAccountManager::PROPERTY_PHONE => ['value' => 'phone'],
IAccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
IAccountManager::PROPERTY_COMPANY => ['value' => 'company'],
IAccountManager::PROPERTY_JOB_TITLE => ['value' => 'job_title'],
IAccountManager::PROPERTY_HEADLINE => ['value' => 'headline'],
IAccountManager::PROPERTY_BIOGRAPHY => ['value' => 'biography'],
]);
$this->config
->expects($this->at(0))
Expand Down Expand Up @@ -1067,6 +1071,11 @@ public function testGetUserDataAsAdmin() {
'setPassword' => true,
],
'additional_mail' => [],
'company' => 'company',
'job_title' => 'job_title',
'headline' => 'headline',
'biography' => 'biography',
'profile_enabled' => '1',
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
Expand Down Expand Up @@ -1165,6 +1174,10 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
IAccountManager::PROPERTY_PHONE => ['value' => 'phone'],
IAccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
IAccountManager::PROPERTY_COMPANY => ['value' => 'company'],
IAccountManager::PROPERTY_JOB_TITLE => ['value' => 'job_title'],
IAccountManager::PROPERTY_HEADLINE => ['value' => 'headline'],
IAccountManager::PROPERTY_BIOGRAPHY => ['value' => 'biography'],
]);

$this->l10nFactory
Expand Down Expand Up @@ -1195,6 +1208,11 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
'setPassword' => true,
],
'additional_mail' => [],
'company' => 'company',
'job_title' => 'job_title',
'headline' => 'headline',
'biography' => 'biography',
'profile_enabled' => '1',
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
Expand Down Expand Up @@ -1332,6 +1350,10 @@ public function testGetUserDataAsSubAdminSelfLookup() {
IAccountManager::PROPERTY_PHONE => ['value' => 'phone'],
IAccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
IAccountManager::PROPERTY_COMPANY => ['value' => 'company'],
IAccountManager::PROPERTY_JOB_TITLE => ['value' => 'job_title'],
IAccountManager::PROPERTY_HEADLINE => ['value' => 'headline'],
IAccountManager::PROPERTY_BIOGRAPHY => ['value' => 'biography'],
]);

$this->l10nFactory
Expand Down Expand Up @@ -1361,6 +1383,11 @@ public function testGetUserDataAsSubAdminSelfLookup() {
'setPassword' => false,
],
'additional_mail' => [],
'company' => 'company',
'job_title' => 'job_title',
'headline' => 'headline',
'biography' => 'biography',
'profile_enabled' => '1',
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
Expand Down Expand Up @@ -3875,6 +3902,11 @@ public function dataGetEditableFields() {
IAccountManager::PROPERTY_ADDRESS,
IAccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_TWITTER,
IAccountManager::PROPERTY_COMPANY,
IAccountManager::PROPERTY_JOB_TITLE,
IAccountManager::PROPERTY_HEADLINE,
IAccountManager::PROPERTY_BIOGRAPHY,
IAccountManager::PROPERTY_PROFILE_ENABLED,
]],
[true, ISetDisplayNameBackend::class, [
IAccountManager::PROPERTY_DISPLAYNAME,
Expand All @@ -3884,6 +3916,11 @@ public function dataGetEditableFields() {
IAccountManager::PROPERTY_ADDRESS,
IAccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_TWITTER,
IAccountManager::PROPERTY_COMPANY,
IAccountManager::PROPERTY_JOB_TITLE,
IAccountManager::PROPERTY_HEADLINE,
IAccountManager::PROPERTY_BIOGRAPHY,
IAccountManager::PROPERTY_PROFILE_ENABLED,
]],
[true, UserInterface::class, [
IAccountManager::PROPERTY_EMAIL,
Expand All @@ -3892,6 +3929,11 @@ public function dataGetEditableFields() {
IAccountManager::PROPERTY_ADDRESS,
IAccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_TWITTER,
IAccountManager::PROPERTY_COMPANY,
IAccountManager::PROPERTY_JOB_TITLE,
IAccountManager::PROPERTY_HEADLINE,
IAccountManager::PROPERTY_BIOGRAPHY,
IAccountManager::PROPERTY_PROFILE_ENABLED,
]],
];
}
Expand Down
8 changes: 7 additions & 1 deletion apps/settings/css/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ input {
.profile-settings-container {
display: inline-grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr 2fr 1fr;
grid-template-rows: 1fr 1fr 2fr;

#locale {
h3 {
height: 32px;
}
}
}

.personal-show-container {
Expand Down
18 changes: 17 additions & 1 deletion apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ public function getForm(): TemplateResponse {
] + $messageParameters + $languageParameters + $localeParameters;

$personalInfoParameters = [
'userId' => $uid,
'displayNames' => $this->getDisplayNames($account),
'emails' => $this->getEmails($account),
'languages' => $this->getLanguages($user),
'profileEnabled' => $this->getProfileEnabled($account),
];

$accountParameters = [
Expand Down Expand Up @@ -245,7 +247,7 @@ function (IAccountProperty $property) {
'verified' => $property->getVerified(),
];
},
$account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)->getProperties()
$account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)->getProperties(),
);

$emails = [
Expand Down Expand Up @@ -359,4 +361,18 @@ private function getMessageParameters(IAccount $account): array {
}
return $messageParameters;
}

/**
* returns the profile enabled state
*
* @param IAccount $account
* @return bool
*/
private function getProfileEnabled(IAccount $account): bool {
return filter_var(
$account->getProperty(IAccountManager::PROPERTY_PROFILE_ENABLED)->getValue(),
FILTER_VALIDATE_BOOLEAN,
FILTER_NULL_ON_FAILURE,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

<script>
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import debounce from 'debounce'
import { savePrimaryDisplayName } from '../../../service/PersonalInfo/DisplayNameService'
Expand Down Expand Up @@ -106,6 +107,7 @@ export default {
if (status === 'ok') {
// Ensure that local state reflects server state
this.initialDisplayName = displayName
emit('settings:displayName:updated', displayName)
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!--
- @copyright 2021, Christopher Ng <chrng8@gmail.com>
-
- @author Christopher Ng <chrng8@gmail.com>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<template>
<div class="profile">
<input
id="enable-profile"
class="checkbox"
type="checkbox"
:checked="profileEnabled"
@change="onEnableProfileChange">
<label for="enable-profile">
{{ t('settings', 'Enable Profile') }}
</label>
<em>This will enable your user profile.</em>
</div>
</template>

<script>
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { saveEnableProfile } from '../../../service/PersonalInfo/ProfileService'
import { validateEnableProfile } from '../../../utils/validate'
export default {
name: 'ProfileCheckbox',
props: {
profileEnabled: {
type: Boolean,
required: true,
},
},
data() {
return {
initialProfileEnabled: this.profileEnabled,
showCheckmarkIcon: false,
showErrorIcon: false,
}
},
methods: {
async onEnableProfileChange(e) {
const isEnabled = e.target.checked
this.$emit('update:profile-enabled', isEnabled)
if (validateEnableProfile(isEnabled)) {
await this.updateEnableProfile(isEnabled)
}
},
async updateEnableProfile(isEnabled) {
try {
const responseData = await saveEnableProfile(isEnabled)
this.handleResponse({
isEnabled,
status: responseData.ocs?.meta?.status,
})
} catch (e) {
this.handleResponse({
errorMessage: 'Unable to update profile enabled state',
error: e,
})
}
},
handleResponse({ isEnabled, status, errorMessage, error }) {
if (status === 'ok') {
// Ensure that local state reflects server state
this.initialProfileEnabled = isEnabled
emit('settings:profileEnabled:updated', isEnabled)
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
showError(t('settings', errorMessage))
this.logger.error(errorMessage, error)
this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000)
}
},
},
}
</script>
<style lang="scss" scoped>
.profile {
display: grid;
em {
margin-left: 29px !important;
}
}
</style>
Loading

0 comments on commit 73a8074

Please sign in to comment.