Skip to content

Commit

Permalink
WIP6
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Sep 19, 2024
1 parent 81f6bfd commit 1e5ce26
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 240 deletions.
8 changes: 0 additions & 8 deletions apps/user_ldap/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
->actionInclude('user_ldap/ajax/wizard.php');

$application = new \OCP\AppFramework\App('user_ldap');
$application->registerRoutes($this, [
'ocs' => [
['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'],
['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'],
['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'],
['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'],
]
]);

/** @var \OCA\User_LDAP\AppInfo\Application $application */
$application = \OC::$server->query(\OCA\User_LDAP\AppInfo\Application::class);
Expand Down
5 changes: 5 additions & 0 deletions apps/user_ldap/lib/Controller/ConfigAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\Settings\Admin;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
Expand Down Expand Up @@ -53,6 +54,7 @@ public function __construct(
* 200: Config created successfully
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'POST', url: '/api/v1/config')]
public function create() {
try {
$configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
Expand All @@ -77,6 +79,7 @@ public function create() {
* 200: Config deleted successfully
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'DELETE', url: '/api/v1/config/{configID}')]
public function delete($configID) {
try {
$this->ensureConfigIDExists($configID);
Expand Down Expand Up @@ -106,6 +109,7 @@ public function delete($configID) {
* 200: Config returned
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'PUT', url: '/api/v1/config/{configID}')]
public function modify($configID, $configData) {
try {
$this->ensureConfigIDExists($configID);
Expand Down Expand Up @@ -210,6 +214,7 @@ public function modify($configID, $configData) {
* 200: Config returned
*/
#[AuthorizedAdminSetting(settings: Admin::class)]
#[ApiRoute(verb: 'GET', url: '/api/v1/config/{configID}')]
public function show($configID, $showPassword = false) {
try {
$this->ensureConfigIDExists($configID);
Expand Down
1 change: 0 additions & 1 deletion apps/user_ldap/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function getForm() {
foreach ($prefixes as $prefix) {
$ldapConfig = new Configuration($prefix);
$rawLdapConfig = $ldapConfig->getConfiguration();
$rawLdapConfig['ldapAgentPassword'] = '***';
foreach ($rawLdapConfig as $key => $value) {
if (is_array($value)) {
$rawLdapConfig[$key] = implode(';', $value);
Expand Down
15 changes: 2 additions & 13 deletions apps/user_ldap/src/components/SettingsTabs/AdvancedTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,12 @@
</template>

<script lang="ts" setup>
import { defineProps, computed } from 'vue'

import { t } from '@nextcloud/l10n'
import { NcTextField, NcTextArea, NcCheckboxRadioSwitch } from '@nextcloud/vue'

import { useLDAPConfigStore } from '../../store/config'

const ldapConfigStore = useLDAPConfigStore()

const { ldapConfigId } = defineProps({
ldapConfigId: {
type: String,
required: true,
},
})
import { useLDAPConfigStore } from '../../store/configs'

const ldapConfig = computed(() => ldapConfigStore.ldapConfigs[ldapConfigId])
const { selectedConfig: ldapConfig } = useLDAPConfigStore()

const instanceName = 'TODO'
</script>
Expand Down
15 changes: 2 additions & 13 deletions apps/user_ldap/src/components/SettingsTabs/ExpertTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,12 @@
</template>

<script lang="ts" setup>
import { computed, defineProps } from 'vue'

import { t } from '@nextcloud/l10n'
import { NcTextField, NcButton } from '@nextcloud/vue'

import { useLDAPConfigStore } from '../../store/config'

const ldapConfigStore = useLDAPConfigStore()

const { ldapConfigId } = defineProps({
ldapConfigId: {
type: String,
required: true,
},
})
import { useLDAPConfigStore } from '../../store/configs'

const ldapConfig = computed(() => ldapConfigStore.ldapConfigs[ldapConfigId])
const { selectedConfig: ldapConfig } = useLDAPConfigStore()
</script>
<style lang="scss" scoped>
.ldap-wizard__expert {
Expand Down
24 changes: 8 additions & 16 deletions apps/user_ldap/src/components/SettingsTabs/GroupsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</div>

<div class="ldap-wizard__groups__line ldap-wizard__groups__groups-count-check">
<NcButton @click="getGroupsCount">
<NcButton @click="countGroups">
{{ t('user_ldap', 'Verify settings and count the groups') }}
</NcButton>

Expand All @@ -76,35 +76,27 @@
</template>

<script lang="ts" setup>
import { defineProps, computed, ref } from 'vue'
import { ref } from 'vue'

import { t } from '@nextcloud/l10n'
import { NcButton, NcTextArea, NcCheckboxRadioSwitch, NcSelect } from '@nextcloud/vue'

import { useLDAPConfigStore } from '../../store/config'
import { useLDAPConfigStore } from '../../store/configs'

const ldapConfigStore = useLDAPConfigStore()

const { ldapConfigId } = defineProps({
ldapConfigId: {
type: String,
required: true,
},
})

const ldapConfig = computed(() => ldapConfigStore.ldapConfigs[ldapConfigId])
const { selectedConfig: ldapConfig, callWizardAction } = useLDAPConfigStore()

const instanceName = 'TODO'

const groupsCount = ref<number>(-1)
const groupsCount = ref<number|undefined>(undefined)
const editGroupsFilter = ref(false)
const allowUserFilterGroupsSelection = ref(false)

/**
*
*/
async function getGroupsCount() {
groupsCount.value++ // TODO: Implement
async function countGroups() {
const { changes: { ldap_test_base: ldapTestBase } } = await callWizardAction('countGroups')
groupsCount.value = ldapTestBase
}
</script>
<style lang="scss" scoped>
Expand Down
17 changes: 4 additions & 13 deletions apps/user_ldap/src/components/SettingsTabs/LoginTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,14 @@
</template>

<script lang="ts" setup>
import { defineProps, computed, ref } from 'vue'
import { ref } from 'vue'

import { t } from '@nextcloud/l10n'
import { NcButton, NcTextField, NcTextArea, NcCheckboxRadioSwitch, NcSelect } from '@nextcloud/vue'

import { useLDAPConfigStore } from '../../store/config'
import { useLDAPConfigStore } from '../../store/configs'

const ldapConfigStore = useLDAPConfigStore()

const { ldapConfigId } = defineProps({
ldapConfigId: {
type: String,
required: true,
},
})

const ldapConfig = computed(() => ldapConfigStore.ldapConfigs[ldapConfigId])
const { selectedConfig: ldapConfig, callWizardAction } = useLDAPConfigStore()

const instanceName = 'TODO'
const testUsername = ref('TODO')
Expand All @@ -83,7 +74,7 @@ const editUserLoginFilter = ref(false)
*
*/
async function verifyLoginName() {
// TODO: Implement
const { changes: { ldap_test_base: ldapTestBase } } = await callWizardAction('testLoginName', { testUsername: testUsername.value })
}
</script>
<style lang="scss" scoped>
Expand Down
59 changes: 29 additions & 30 deletions apps/user_ldap/src/components/SettingsTabs/ServerTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<fieldset class="ldap-wizard__server">
<div class="ldap-wizard__server__line">
<NcButton :aria-label="t('user_ldap', 'Copy current configuration into new directory binding')"
@click="() => ldapConfigStore.copy(ldapConfigId)">
@click="() => copy(ldapConfigId)">
<template #icon>
<ContentCopy :size="20" />
</template>
</NcButton>
<NcButton :aria-label="t('user_ldap', 'Delete the current configuration')"
@click="() => ldapConfigStore.remove(ldapConfigId)">
@click="() => remove(ldapConfigId)">
<template #icon>
<Delete :size="20" />
</template>
Expand All @@ -36,7 +36,7 @@
</div>

<div class="ldap-wizard__server__line">
<NcTextField :value.sync="ldapConfig.ldapAgentName"
<NcTextField :value.sync="localLdapAgentName"
:helper-text="t('user_ldap', 'The DN of the client user with which the bind shall be done, e.g. uid=agent,dc=example,dc=com. For anonymous access, leave DN and Password empty.')"
:placeholder="t('user_ldap', 'User DN')"
autocomplete="off" />
Expand All @@ -45,11 +45,11 @@
<div class="ldap-wizard__server__line">
<NcTextField type="password"
:helper-text="t('user_ldap', 'For anonymous access, leave DN and Password empty.')"
:value.sync="ldapConfig.ldapAgentPassword"
:value.sync="localLdapAgentPassword"
:placeholder="t('user_ldap', 'Password')"
autocomplete="off" />

<NcButton @click="ldapConfigStore.create">
<NcButton :disabled="!needsToSaveCredentials" @click="updateCredentials">
{{ t('user_ldap', 'Save Credentials') }}
</NcButton>
</div>
Expand Down Expand Up @@ -79,58 +79,57 @@
</template>

<script lang="ts" setup>
import { defineProps, computed, ref } from 'vue'
import { computed, ref } from 'vue'

import ContentCopy from 'vue-material-design-icons/ContentCopy.vue'
import Delete from 'vue-material-design-icons/Delete.vue'

import { t } from '@nextcloud/l10n'
import { NcButton, NcTextField, NcTextArea, NcCheckboxRadioSwitch } from '@nextcloud/vue'

import { useLDAPConfigStore } from '../../store/config'
import { callWizard } from '../../services/ldapConfigService'
import { useLDAPConfigStore } from '../../store/configs'
import { showInfo } from '@nextcloud/dialogs'
import { useWizardStore } from '../../store/wizard'

const { ldapConfigId } = defineProps({
ldapConfigId: {
type: String,
required: true,
},
})
const { selectedConfigId: ldapConfigId, selectedConfig: ldapConfig, copy, remove } = useLDAPConfigStore()
const { currentWizardActions, callWizardAction } = useWizardStore()

const ldapConfigStore = useLDAPConfigStore()
const localLdapAgentName = ref(ldapConfig.ldapAgentName)
const localLdapAgentPassword = ref(ldapConfig.ldapAgentPassword)
const needsToSaveCredentials = computed(() => {
return ldapConfig.ldapAgentName !== localLdapAgentName.value || ldapConfig.ldapAgentPassword !== localLdapAgentPassword.value
})

const ldapConfig = computed(() => ldapConfigStore.ldapConfigs[ldapConfigId])
const usersCount = ref<number|undefined>(undefined)
const currentWizardActions = ref<string[]>([])
/**
*
*/
function updateCredentials() {
ldapConfig.ldapAgentName = localLdapAgentName.value
ldapConfig.ldapAgentPassword = localLdapAgentPassword.value
}

/**
*
*/
async function guessPortAndTLS() {
currentWizardActions.value.push('guessPortAndTLS')
const { changes: { ldap_port: ldapPort } } = await callWizard('guessPortAndTLS', ldapConfigId)
ldapConfig.value.ldapPort = ldapPort
currentWizardActions.value.splice(currentWizardActions.value.indexOf('guessPortAndTLS'), 1)
const { changes: { ldap_port: ldapPort } } = await callWizardAction('guessPortAndTLS')
ldapConfig.ldapPort = String(ldapPort)
}

/**
*
*/
async function guessBaseDN() {
currentWizardActions.value.push('guessBaseDN')
const { changes: { ldap_base: ldapBase } } = await callWizard('guessBaseDN', ldapConfigId)
ldapConfig.value.ldapBase = ldapBase
currentWizardActions.value.splice(currentWizardActions.value.indexOf('guessPortAndTLS'), 1)
const { changes: { ldap_base: ldapBase } } = await callWizardAction('guessBaseDN')
ldapConfig.ldapBase = ldapBase
}

/**
*
*/
async function countInBaseDN() {
currentWizardActions.value.push('countInBaseDN')
const { changes: { ldap_test_base: ldapTestBase } } = await callWizard('countInBaseDN', ldapConfigId)
usersCount.value = ldapTestBase
currentWizardActions.value.splice(currentWizardActions.value.indexOf('guessPortAndTLS'), 1)
const { changes: { ldap_test_base: ldapTestBase } } = await callWizardAction('countInBaseDN')
showInfo(t('user_ldap', 'Found {count} users in the given Base DN.', { count: ldapTestBase }))
}

</script>
Expand Down
26 changes: 9 additions & 17 deletions apps/user_ldap/src/components/SettingsTabs/UsersTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,26 @@
</div>

<div class="ldap-wizard__users__line ldap-wizard__users__user-count-check">
<NcButton @click="getUserCount">
<NcButton @click="countUsers">
{{ t('user_name', 'Verify settings and count users') }}
</NcButton>

<span v-if="userCount !== undefined">{{ t('user_ldap', "User count: {userCount}", { userCount }) }}</span>
<span v-if="usersCount !== undefined">{{ t('user_ldap', "User count: {userCount}", { usersCount }) }}</span>
</div>
</fieldset>
</template>

<script lang="ts" setup>
import { defineProps, computed, ref } from 'vue'
import { ref } from 'vue'

import { t } from '@nextcloud/l10n'
import { NcButton, NcTextArea, NcCheckboxRadioSwitch, NcSelect } from '@nextcloud/vue'

import { useLDAPConfigStore } from '../../store/config'
import { useLDAPConfigStore } from '../../store/configs'

const ldapConfigStore = useLDAPConfigStore()
const { selectedConfig: ldapConfig, callWizardAction } = useLDAPConfigStore()

const { ldapConfigId } = defineProps({
ldapConfigId: {
type: String,
required: true,
},
})

const ldapConfig = computed(() => ldapConfigStore.ldapConfigs[ldapConfigId])

const userCount = ref<number>(-1)
const usersCount = ref<number|undefined>(undefined)

const editUserFilter = ref(false)
const allowUserFilterGroupsSelection = ref(true) // TODO
Expand All @@ -116,8 +107,9 @@ const instanceName = 'TODO'
/**
*
*/
async function getUserCount() {
userCount.value++ // TODO: Implement
async function countUsers() {
const { changes: { ldap_test_base: ldapTestBase } } = await callWizardAction('countUsers')
usersCount.value = ldapTestBase
}
</script>
<style lang="scss" scoped>
Expand Down
Loading

0 comments on commit 1e5ce26

Please sign in to comment.