mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-20 02:45:25 +00:00
test: migration from Python to JavaScript
This commit is contained in:
@@ -91,7 +91,7 @@ class Preferences {
|
||||
return obj
|
||||
}
|
||||
for (let k of Object.keys(obj)) {
|
||||
if (typeof obj[k] == 'object') {
|
||||
if (obj[k] && typeof obj[k] == 'object') {
|
||||
let o = this.findKey(obj[k], key)
|
||||
if (o !== null)
|
||||
return o
|
||||
|
||||
+51
-19
@@ -22,8 +22,22 @@ import config from './config'
|
||||
|
||||
const DAVInverse = 'urn:inverse:params:xml:ns:inverse-dav'
|
||||
const DAVInverseShort = 'i'
|
||||
const DAVMailHeader = 'urn:schemas:mailheader:'
|
||||
const DAVMailHeaderShort = 'mh'
|
||||
const DAVHttpMail = 'urn:schemas:httpmail:'
|
||||
const DAVHttpMailShort = 'hm'
|
||||
const DAVnsShortMap = {
|
||||
[DAVInverse]: DAVInverseShort,
|
||||
[DAVMailHeader]: DAVMailHeaderShort,
|
||||
[DAVHttpMail]: DAVHttpMailShort,
|
||||
...DAVNamespaceShorthandMap
|
||||
}
|
||||
|
||||
export { DAVInverse, DAVInverseShort }
|
||||
export {
|
||||
DAVInverse, DAVInverseShort,
|
||||
DAVMailHeader, DAVMailHeaderShort,
|
||||
DAVHttpMail, DAVHttpMailShort
|
||||
}
|
||||
|
||||
class WebDAV {
|
||||
constructor(un, pw) {
|
||||
@@ -97,15 +111,20 @@ class WebDAV {
|
||||
}
|
||||
|
||||
propfindWebdav(resource, properties, namespace = DAVNamespace.DAV, headers = {}) {
|
||||
const nsShort = DAVNamespaceShorthandMap[namespace] || DAVInverseShort
|
||||
const nsShort = DAVnsShortMap[namespace] || DAVInverseShort
|
||||
const formattedProperties = properties.map(p => {
|
||||
return { [`${nsShort}:${p}`]: '' }
|
||||
})
|
||||
let url
|
||||
if (resource.match(/^http/))
|
||||
url = resource
|
||||
else
|
||||
url = this.serverUrl + resource
|
||||
if (typeof headers.depth == 'undefined') {
|
||||
headers.depth = new String(0)
|
||||
}
|
||||
return davRequest({
|
||||
url: this.serverUrl + resource,
|
||||
url,
|
||||
init: {
|
||||
method: 'PROPFIND',
|
||||
headers: { ...this.headers, ...headers },
|
||||
@@ -427,27 +446,38 @@ class WebDAV {
|
||||
})
|
||||
}
|
||||
|
||||
mailQueryMaildav(resource, properties, filters = {}) {
|
||||
mailQueryMaildav(resource, properties, filters = {}, sort, ascending = true) {
|
||||
let formattedFilters = {}
|
||||
if (filters.constructor.toString().includes('Array')) {
|
||||
filters.map(f => {
|
||||
Object.keys(f).map(p => {
|
||||
if (filters) {
|
||||
if (filters.constructor.toString().includes('Array')) {
|
||||
filters.map(f => {
|
||||
Object.keys(f).map(p => {
|
||||
const pName = `${DAVInverseShort}:${p}`
|
||||
if (!formattedFilters[pName])
|
||||
formattedFilters[pName] = []
|
||||
formattedFilters[pName].push({ _attributes: f[p] })
|
||||
})
|
||||
})
|
||||
}
|
||||
else {
|
||||
Object.keys(filters).map(p => {
|
||||
const pName = `${DAVInverseShort}:${p}`
|
||||
if (!formattedFilters[pName])
|
||||
formattedFilters[pName] = []
|
||||
formattedFilters[pName].push({ _attributes: f[p] })
|
||||
formattedFilters[pName].push({ _attributes: filters[p] })
|
||||
})
|
||||
})
|
||||
}
|
||||
if (Object.keys(formattedFilters).length) {
|
||||
formattedFilters = {[`${DAVInverseShort}:mail-filters`]: formattedFilters}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Object.keys(filters).map(p => {
|
||||
const pName = `${DAVInverseShort}:${p}`
|
||||
if (!formattedFilters[pName])
|
||||
formattedFilters[pName] = []
|
||||
formattedFilters[pName].push({ _attributes: filters[p] })
|
||||
})
|
||||
let formattedSort = {}
|
||||
if (sort) {
|
||||
formattedSort = {[`${DAVInverseShort}:sort`]: {
|
||||
_attributes: { order: ascending ? 'ascending' : 'descending' },
|
||||
[sort]: {}
|
||||
}}
|
||||
}
|
||||
|
||||
return davRequest({
|
||||
url: this.serverUrl + resource,
|
||||
init: {
|
||||
@@ -458,10 +488,12 @@ class WebDAV {
|
||||
[`${DAVInverseShort}:mail-query`]: {
|
||||
_attributes: {
|
||||
...getDAVAttribute([DAVNamespace.DAV]),
|
||||
[`xmlns:${DAVInverseShort}`]: DAVInverse
|
||||
[`xmlns:${DAVInverseShort}`]: DAVInverse,
|
||||
[`xmlns:${DAVMailHeaderShort}`]: DAVMailHeader
|
||||
},
|
||||
prop: formatProps(properties.map(p => { return { name: p } })),
|
||||
[`${DAVInverseShort}:mail-filters`]: formattedFilters
|
||||
...formattedFilters,
|
||||
...formattedSort
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,13 @@ class TestUtility {
|
||||
return s;
|
||||
}
|
||||
|
||||
camelCase(snakeCase) {
|
||||
return snakeCase.replace(/(?:^\w|[A-Z]|\b\w)/g, (char, i) =>
|
||||
i === 0 ? char.toLowerCase() : char.toUpperCase(),
|
||||
)
|
||||
.replace(/[\s\-_]+/g, '')
|
||||
}
|
||||
|
||||
setupRights(resource, username, rights) {
|
||||
const action = (typeof rights == 'undefined') ? 'remove-user' : 'set-roles'
|
||||
return davRequest({
|
||||
|
||||
Reference in New Issue
Block a user