summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2019-04-08 17:17:57 +0200
committerGitHub <noreply@github.com>2019-04-08 17:17:57 +0200
commite0decd5ff982fd5beb242637c669cf8324c86390 (patch)
tree37fef45a0d338d9299f7e2e0a5ab447334a009f8 /src
parent7f2bdba462e9b02327607283db0adaf0e49f6581 (diff)
parentc37000eb7a1067ee5c6dfd0cb0f734d3b12780da (diff)
Merge pull request #1042 from nextcloud/enhancement/repair/duplicate-types
Automatic repair of duplicate types
Diffstat (limited to 'src')
-rw-r--r--src/services/checks/duplicateTypes.js62
-rw-r--r--src/services/checks/index.js2
2 files changed, 64 insertions, 0 deletions
diff --git a/src/services/checks/duplicateTypes.js b/src/services/checks/duplicateTypes.js
new file mode 100644
index 00000000..2642aa82
--- /dev/null
+++ b/src/services/checks/duplicateTypes.js
@@ -0,0 +1,62 @@
+/**
+ * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.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/>.
+ *
+ */
+
+export default {
+ name: 'duplicate types',
+ run: contact => {
+ try {
+ const props = contact.vCard.getAllProperties()
+ .map(prop => prop.getParameter('type'))
+ .filter(prop => prop)
+ const fixed = props.map(prop => [...new Set(prop)])
+ if (props
+ && Array.isArray(props)
+ && props.length > 0
+ && props.join('') !== fixed.join('')) {
+ return true
+ }
+ } catch (error) {
+ return false
+ }
+ return false
+ },
+ fix: contact => {
+ let results = false
+ try {
+ const props = contact.vCard.getAllProperties()
+ props.forEach(prop => {
+ // ['WORK', 'pref', 'pref'] => ['WORK', 'pref']
+ const param = prop.getParameter('type')
+ const fixed = [...new Set(param)]
+ if (param
+ && Array.isArray(param)
+ && param.join('') !== fixed.join('')) {
+ prop.setParameter('type', fixed)
+ results = true
+ }
+ })
+ } catch (error) {
+ console.error(error)
+ }
+ return results
+ }
+}
diff --git a/src/services/checks/index.js b/src/services/checks/index.js
index 2ac0871d..170bd846 100644
--- a/src/services/checks/index.js
+++ b/src/services/checks/index.js
@@ -21,11 +21,13 @@
*/
import badGenderType from './badGenderType'
+import duplicateTypes from './duplicateTypes'
import invalidREV from './invalidREV'
import missingFN from './missingFN'
export default [
badGenderType,
+ duplicateTypes,
invalidREV,
missingFN
]