From 3bfdec25eb01a9d6b838de1660b9c0bcba56a189 Mon Sep 17 00:00:00 2001 From: Hesaam Farhang Date: Thu, 23 Jan 2020 10:49:51 -0800 Subject: [PATCH] Beautify and multiline js codes in views (#6265) Adding (and ran) a script to make JavaScript codes in CouchDB view files beautify and multi-line so make it more readable to developers. Also makes keep tracking changes easy during PR reviews. kz_datamgr:maybe_adapt_multiline/1 is updated to reverse multi-lined views back to simple string for all view's functions (such as lists, shows and of course views). --- .circleci/config.yml | 4 +- Makefile | 6 + applications/acdc/.circleci/config.yml | 4 +- .../acdc/priv/couchdb/views/acdc.json | 7 +- .../acdc/priv/couchdb/views/agent_stats.json | 21 +- .../acdc/priv/couchdb/views/agents.json | 11 +- .../acdc/priv/couchdb/views/call_stats.json | 34 ++-- .../acdc/priv/couchdb/views/queues.json | 20 +- applications/ananke/.circleci/config.yml | 4 +- applications/blackhole/.circleci/config.yml | 4 +- applications/braintree/.circleci/config.yml | 4 +- .../call_inspector/.circleci/config.yml | 4 +- applications/callflow/.circleci/config.yml | 4 +- applications/camper/.circleci/config.yml | 4 +- applications/cccp/.circleci/config.yml | 4 +- .../cccp/priv/couchdb/views/cccps.json | 40 +++- applications/cdr/.circleci/config.yml | 4 +- applications/cdr/priv/couchdb/views/cdr.json | 19 +- applications/conference/.circleci/config.yml | 4 +- applications/crossbar/.circleci/config.yml | 4 +- .../priv/couchdb/views/account-functions.json | 7 +- .../couchdb/views/functionsdb-functions.json | 65 ++++++- applications/doodle/.circleci/config.yml | 4 +- .../doodle/priv/couchdb/views/sms.json | 120 ++++++------ applications/ecallmgr/.circleci/config.yml | 4 +- applications/edr/.circleci/config.yml | 4 +- applications/fax/.circleci/config.yml | 4 +- .../fax/priv/couchdb/views/faxbox.json | 43 +++- .../fax/priv/couchdb/views/faxes.json | 53 ++--- applications/frontier/.circleci/config.yml | 4 +- applications/hangups/.circleci/config.yml | 4 +- applications/hotornot/.circleci/config.yml | 4 +- applications/jonny5/.circleci/config.yml | 4 +- applications/konami/.circleci/config.yml | 4 +- applications/media_mgr/.circleci/config.yml | 4 +- applications/milliwatt/.circleci/config.yml | 4 +- applications/notify/.circleci/config.yml | 4 +- .../omnipresence/.circleci/config.yml | 4 +- applications/pivot/.circleci/config.yml | 4 +- applications/pusher/.circleci/config.yml | 4 +- applications/registrar/.circleci/config.yml | 4 +- .../priv/couchdb/views/credentials.json | 22 +-- applications/reorder/.circleci/config.yml | 4 +- applications/skel/.circleci/config.yml | 4 +- applications/spyvsspy/.circleci/config.yml | 4 +- applications/stats/.circleci/config.yml | 4 +- applications/stepswitch/.circleci/config.yml | 4 +- .../couchdb/views/multi_db-resources.json | 66 ++++++- .../couchdb/views/resource_selectors.json | 112 ++++++++++- applications/sysconf/.circleci/config.yml | 4 +- applications/tasks/.circleci/config.yml | 4 +- .../tasks/priv/couchdb/views/compactor.json | 2 +- .../tasks/priv/couchdb/views/tasks.json | 16 +- applications/teletype/.circleci/config.yml | 4 +- .../priv/couchdb/views/notifications.json | 14 +- applications/trunkstore/.circleci/config.yml | 4 +- applications/webhooks/.circleci/config.yml | 4 +- .../priv/couchdb/views/account-webhooks.json | 7 +- .../couchdb/views/webhooksdb-webhooks.json | 42 +++- .../priv/couchdb/account/access_lists.json | 16 +- .../priv/couchdb/account/account.json | 30 ++- .../priv/couchdb/account/apps_store.json | 2 +- .../priv/couchdb/account/attributes.json | 79 +++++--- .../kazoo_apps/priv/couchdb/account/auth.json | 3 +- .../priv/couchdb/account/blacklists.json | 11 +- .../priv/couchdb/account/callflows.json | 77 ++++---- .../priv/couchdb/account/click2call.json | 12 +- .../priv/couchdb/account/conference.json | 15 +- .../priv/couchdb/account/conferences.json | 23 ++- .../priv/couchdb/account/contact_list.json | 66 ++++++- .../priv/couchdb/account/devices.json | 30 ++- .../priv/couchdb/account/directories.json | 20 +- .../priv/couchdb/account/faxbox.json | 51 ++++- .../priv/couchdb/account/faxes.json | 39 +++- .../priv/couchdb/account/groups.json | 31 ++- .../priv/couchdb/account/hotdesks.json | 12 +- .../priv/couchdb/account/lists.json | 18 +- .../priv/couchdb/account/menus.json | 11 +- .../priv/couchdb/account/message.json | 75 +++---- .../priv/couchdb/account/metaflows.json | 7 +- .../priv/couchdb/account/mobile.json | 12 +- .../priv/couchdb/account/notifications.json | 14 +- .../priv/couchdb/account/numbers.json | 14 +- .../priv/couchdb/account/parking.json | 14 +- .../priv/couchdb/account/phone_numbers.json | 6 +- .../priv/couchdb/account/pivot.json | 28 ++- .../priv/couchdb/account/rate_limits.json | 32 ++- .../priv/couchdb/account/resources.json | 45 ++++- .../priv/couchdb/account/search.json | 6 +- .../priv/couchdb/account/servers.json | 21 +- .../priv/couchdb/account/service_plans.json | 12 +- .../priv/couchdb/account/skels.json | 7 +- .../priv/couchdb/account/temporal_rules.json | 12 +- .../couchdb/account/temporal_rules_sets.json | 12 +- .../priv/couchdb/account/trunkstore.json | 65 ++++++- .../priv/couchdb/account/users.json | 14 +- .../priv/couchdb/account/vmboxes.json | 47 +++-- .../priv/couchdb/account/whitelabel.json | 7 +- .../priv/couchdb/views/accounts.json | 143 ++++++++++++-- .../kazoo_apps/priv/couchdb/views/alerts.json | 19 +- .../priv/couchdb/views/maintenance.json | 64 +++++- core/kazoo_apps/priv/couchdb/views/rates.json | 12 +- .../kazoo_apps/priv/couchdb/views/search.json | 18 +- .../priv/couchdb/views/system_configs.json | 8 +- .../priv/couchdb/views/token_auth.json | 12 +- core/kazoo_auth/priv/couchdb/views/apps.json | 19 +- core/kazoo_auth/priv/couchdb/views/auth.json | 19 +- .../priv/couchdb/views/providers.json | 12 +- core/kazoo_auth/priv/couchdb/views/users.json | 13 +- .../priv/couchdb/views/storage.json | 37 +++- core/kazoo_data/priv/couchdb/views/views.json | 26 +-- core/kazoo_data/src/kz_datamgr.erl | 32 ++- .../priv/couchdb/views/dedicated_ips.json | 59 +++++- .../kazoo_media/priv/couchdb/views/media.json | 76 +++++++- .../priv/couchdb/views/allotments.json | 14 +- core/kazoo_modb/priv/couchdb/views/auth.json | 12 +- core/kazoo_modb/priv/couchdb/views/cdrs.json | 183 ++++++++++-------- .../priv/couchdb/views/clicktocall.json | 7 +- core/kazoo_modb/priv/couchdb/views/faxes.json | 70 ++++++- .../priv/couchdb/views/functions.json | 7 +- .../priv/couchdb/views/interactions.json | 16 +- .../priv/couchdb/views/ledgers.json | 35 ++-- .../priv/couchdb/views/mailbox_messages.json | 19 +- .../priv/couchdb/views/notifications.json | 16 +- core/kazoo_modb/priv/couchdb/views/pivot.json | 30 ++- .../priv/couchdb/views/recordings.json | 14 +- .../priv/couchdb/views/resources.json | 19 +- .../priv/couchdb/views/services.json | 10 +- .../priv/couchdb/views/storage.json | 36 +++- .../priv/couchdb/views/transactions.json | 38 +++- .../priv/couchdb/views/webhooks.json | 14 +- .../priv/couchdb/views/numbers.json | 26 ++- .../priv/couchdb/views/numbers_inum.json | 6 +- .../priv/couchdb/views/numbers_managed.json | 6 +- .../priv/couchdb/views/port_requests.json | 7 +- .../priv/couchdb/views/services.json | 24 +-- core/webseq/priv/couchdb/views/webseq.json | 7 +- make/fmt.mk | 10 +- scripts/README.md | 10 + scripts/format-couchdb-views.py | 88 +++++++++ 140 files changed, 2412 insertions(+), 756 deletions(-) create mode 100755 scripts/format-couchdb-views.py diff --git a/.circleci/config.yml b/.circleci/config.yml index eaa0d583fcb..bd494e08ce4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -29,7 +29,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 working_directory: ~/2600hz/kazoo shell: /bin/bash --login environment: @@ -183,7 +183,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq environment: diff --git a/Makefile b/Makefile index 57d6475dbac..6bfb869a616 100644 --- a/Makefile +++ b/Makefile @@ -341,6 +341,12 @@ apis: @$(ROOT)/scripts/format-json.py $(shell find applications core -wholename '*/api/*.json') @ERL_LIBS=deps:core:applications $(ROOT)/scripts/generate-fs-headers-hrl.escript @ERL_LIBS=deps:core:applications $(ROOT)/scripts/generate-kzd-builders.escript + ## FIXME: copy-paste from fmt.mk fmt-views-all target + ## adding that target to circleci steps for every app is painful + ## also this formatting is better to be done before validate-js ci step to make sure + ## the view is still in correct shape + @$(ROOT)/scripts/format-couchdb-views.py core/kazoo_apps/priv/couchdb/account + @$(ROOT)/scripts/format-couchdb-views.py $(shell find applications core -wholename '*/couchdb/views/*.json') schemas: @ERL_LIBS=deps:core:applications $(ROOT)/scripts/generate-schemas.escript diff --git a/applications/acdc/.circleci/config.yml b/applications/acdc/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/acdc/.circleci/config.yml +++ b/applications/acdc/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/acdc/priv/couchdb/views/acdc.json b/applications/acdc/priv/couchdb/views/acdc.json index 718b66de6ec..60badd1e1b1 100644 --- a/applications/acdc/priv/couchdb/views/acdc.json +++ b/applications/acdc/priv/couchdb/views/acdc.json @@ -10,7 +10,12 @@ "language": "javascript", "views": { "accounts_listing": { - "map": "function(doc) { if (doc.pvt_type != 'acdc_activation' || doc.pvt_deleted) return; emit(doc.pvt_account_id, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'acdc_activation' || doc.pvt_deleted) return;", + " emit(doc.pvt_account_id, null);", + "}" + ] } } } diff --git a/applications/acdc/priv/couchdb/views/agent_stats.json b/applications/acdc/priv/couchdb/views/agent_stats.json index f30cfdb0b3d..008006df366 100644 --- a/applications/acdc/priv/couchdb/views/agent_stats.json +++ b/applications/acdc/priv/couchdb/views/agent_stats.json @@ -10,13 +10,28 @@ "language": "javascript", "views": { "most_recent_by_agent": { - "map": "function(doc) { if ( doc.pvt_type != 'status_stat' ) return; emit([doc.agent_id, doc.timestamp], null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'status_stat') return;", + " emit([doc.agent_id, doc.timestamp], null);", + "}" + ] }, "most_recent_by_timestamp": { - "map": "function(doc) { if ( doc.pvt_type != 'status_stat' ) return; emit([doc.timestamp, doc.agent_id], null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'status_stat') return;", + " emit([doc.timestamp, doc.agent_id], null);", + "}" + ] }, "status_log": { - "map": "function(doc) { if ( doc.pvt_type != 'status_stat' ) return; emit([doc.agent_id, doc.timestamp], doc.status); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'status_stat') return;", + " emit([doc.agent_id, doc.timestamp], doc.status);", + "}" + ] } } } diff --git a/applications/acdc/priv/couchdb/views/agents.json b/applications/acdc/priv/couchdb/views/agents.json index 8f2d79e55ad..09e2f86f3fe 100644 --- a/applications/acdc/priv/couchdb/views/agents.json +++ b/applications/acdc/priv/couchdb/views/agents.json @@ -10,7 +10,16 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type !== 'user' || typeof doc.queues !== 'object' || doc.pvt_deleted) return; emit(doc._id, {'first_name': doc.first_name, 'last_name': doc.last_name, 'queues':doc.queues}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type !== 'user' || typeof doc.queues !== 'object' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'first_name': doc.first_name,", + " 'last_name': doc.last_name,", + " 'queues': doc.queues", + " });", + "}" + ] } } } diff --git a/applications/acdc/priv/couchdb/views/call_stats.json b/applications/acdc/priv/couchdb/views/call_stats.json index bb2f02b845a..094dcd25d8a 100644 --- a/applications/acdc/priv/couchdb/views/call_stats.json +++ b/applications/acdc/priv/couchdb/views/call_stats.json @@ -12,30 +12,28 @@ "call_log": { "map": [ "function(doc) {", - " if ( doc.pvt_type != 'call_stat' )", - " return;", - " emit([doc.queue_id, doc.entered_timestamp], null);", + " if (doc.pvt_type != 'call_stat') return;", + " emit([doc.queue_id, doc.entered_timestamp], null);", "}" ] }, "crossbar_listing": { "map": [ "function(doc) {", - " if ( doc.pvt_type != 'call_stat' )", - " return;", - " emit(doc.entered_timestamp, {", - " id: doc._id,", - " entered_timestamp: doc.entered_timestamp,", - " handled_timestamp: doc.handled_timestamp,", - " caller_id_number: doc.caller_id_number,", - " caller_id_name: doc.caller_id_name,", - " entered_position: doc.entered_position,", - " status: doc.status,", - " agent_id: doc.agent_id,", - " wait_time: doc.wait_time,", - " talk_time: doc.talk_time,", - " queue_id: doc.queue_id", - " });", + " if (doc.pvt_type != 'call_stat') return;", + " emit(doc.entered_timestamp, {", + " id: doc._id,", + " entered_timestamp: doc.entered_timestamp,", + " handled_timestamp: doc.handled_timestamp,", + " caller_id_number: doc.caller_id_number,", + " caller_id_name: doc.caller_id_name,", + " entered_position: doc.entered_position,", + " status: doc.status,", + " agent_id: doc.agent_id,", + " wait_time: doc.wait_time,", + " talk_time: doc.talk_time,", + " queue_id: doc.queue_id", + " });", "}" ] } diff --git a/applications/acdc/priv/couchdb/views/queues.json b/applications/acdc/priv/couchdb/views/queues.json index b83c9dc7582..f6864e86884 100644 --- a/applications/acdc/priv/couchdb/views/queues.json +++ b/applications/acdc/priv/couchdb/views/queues.json @@ -10,11 +10,27 @@ "language": "javascript", "views": { "agents_listing": { - "map": "function(doc) { if (doc.pvt_type !== 'user' || doc.pvt_deleted || typeof doc.queues !== 'object' ) return; for ( i in doc.queues ) { emit(doc.queues[i], doc._id); }}", + "map": [ + "function(doc) {", + " if (doc.pvt_type !== 'user' || doc.pvt_deleted || typeof doc.queues !== 'object') return;", + " for (i in doc.queues) {", + " emit(doc.queues[i], doc._id);", + " }", + "}" + ], "reduce": "_count" }, "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'queue' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'strategy': doc.strategy}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'queue' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'strategy': doc.strategy", + " });", + "}" + ] } } } diff --git a/applications/ananke/.circleci/config.yml b/applications/ananke/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/ananke/.circleci/config.yml +++ b/applications/ananke/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/blackhole/.circleci/config.yml b/applications/blackhole/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/blackhole/.circleci/config.yml +++ b/applications/blackhole/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/braintree/.circleci/config.yml b/applications/braintree/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/braintree/.circleci/config.yml +++ b/applications/braintree/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/call_inspector/.circleci/config.yml b/applications/call_inspector/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/call_inspector/.circleci/config.yml +++ b/applications/call_inspector/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/callflow/.circleci/config.yml b/applications/callflow/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/callflow/.circleci/config.yml +++ b/applications/callflow/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/camper/.circleci/config.yml b/applications/camper/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/camper/.circleci/config.yml +++ b/applications/camper/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/cccp/.circleci/config.yml b/applications/cccp/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/cccp/.circleci/config.yml +++ b/applications/cccp/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/cccp/priv/couchdb/views/cccps.json b/applications/cccp/priv/couchdb/views/cccps.json index 83bf3419bf0..3a0b3aa0d4f 100644 --- a/applications/cccp/priv/couchdb/views/cccps.json +++ b/applications/cccp/priv/couchdb/views/cccps.json @@ -13,13 +13,47 @@ "language": "javascript", "views": { "cid_listing": { - "map": "function(doc) { if (doc.pvt_type != 'cccp' || !doc.active || !doc.cid || doc.pvt_deleted) return; emit(doc.cid, {'id': doc._id, 'account_id': doc.pvt_account_id, 'user_id':doc.user_id, 'retain_cid':doc.retain_cid}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'cccp' || !doc.active || !doc.cid || doc.pvt_deleted) return;", + " emit(doc.cid, {", + " 'id': doc._id,", + " 'account_id': doc.pvt_account_id,", + " 'user_id': doc.user_id,", + " 'retain_cid': doc.retain_cid", + " });", + "}" + ] }, "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'cccp' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'account_id': doc.pvt_account_id, 'active':doc.active, 'user_id':doc.user_id, 'cid':doc.cid, 'pin':doc.pin, 'retain_cid':doc.retain_cid, 'comment':doc.comment}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'cccp' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'account_id': doc.pvt_account_id,", + " 'active': doc.active,", + " 'user_id': doc.user_id,", + " 'cid': doc.cid,", + " 'pin': doc.pin,", + " 'retain_cid': doc.retain_cid,", + " 'comment': doc.comment", + " });", + "}" + ] }, "pin_listing": { - "map": "function(doc) { if (doc.pvt_type != 'cccp' || !doc.active || !doc.pin || doc.pvt_deleted) return; emit(doc.pin, {'id': doc._id, 'account_id': doc.pvt_account_id, 'user_id':doc.user_id, 'retain_cid':doc.retain_cid}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'cccp' || !doc.active || !doc.pin || doc.pvt_deleted) return;", + " emit(doc.pin, {", + " 'id': doc._id,", + " 'account_id': doc.pvt_account_id,", + " 'user_id': doc.user_id,", + " 'retain_cid': doc.retain_cid", + " });", + "}" + ] } } } diff --git a/applications/cdr/.circleci/config.yml b/applications/cdr/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/cdr/.circleci/config.yml +++ b/applications/cdr/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/cdr/priv/couchdb/views/cdr.json b/applications/cdr/priv/couchdb/views/cdr.json index 7fb0c96b772..23cc1fdcfe1 100644 --- a/applications/cdr/priv/couchdb/views/cdr.json +++ b/applications/cdr/priv/couchdb/views/cdr.json @@ -10,7 +10,24 @@ "language": "javascript", "views": { "listing_by_id": { - "map": "function(doc) { if(doc.pvt_deleted || doc.pvt_type != 'cdr') return; emit(doc._id, {'id':doc._id, 'call_id':doc.call_id, 'hangup_cause':doc.hangup_cause, 'other_leg_call_id':doc.other_leg_call_id, 'timestamp':doc.timestamp, 'call_direction':doc.call_direction, 'to_uri':doc.to_uri, 'from_uri':doc.from_uri, 'duration_seconds':doc.duration_seconds, 'billing_seconds':doc.billing_seconds, 'ringing_seconds':doc.ringing_seconds,})}" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || doc.pvt_type != 'cdr') return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'call_id': doc.call_id,", + " 'hangup_cause': doc.hangup_cause,", + " 'other_leg_call_id': doc.other_leg_call_id,", + " 'timestamp': doc.timestamp,", + " 'call_direction': doc.call_direction,", + " 'to_uri': doc.to_uri,", + " 'from_uri': doc.from_uri,", + " 'duration_seconds': doc.duration_seconds,", + " 'billing_seconds': doc.billing_seconds,", + " 'ringing_seconds': doc.ringing_seconds,", + " })", + "}" + ] } } } diff --git a/applications/conference/.circleci/config.yml b/applications/conference/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/conference/.circleci/config.yml +++ b/applications/conference/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/crossbar/.circleci/config.yml b/applications/crossbar/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/crossbar/.circleci/config.yml +++ b/applications/crossbar/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/crossbar/priv/couchdb/views/account-functions.json b/applications/crossbar/priv/couchdb/views/account-functions.json index f7e42f4c93b..450173194dd 100644 --- a/applications/crossbar/priv/couchdb/views/account-functions.json +++ b/applications/crossbar/priv/couchdb/views/account-functions.json @@ -10,7 +10,12 @@ "language": "javascript", "views": { "function_meta_listing": { - "map": "function(doc) { if(doc.pvt_type != 'function_meta' || doc.pvt_deleted) return; emit(doc.name, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'function_meta' || doc.pvt_deleted) return;", + " emit(doc.name, null);", + "}" + ] } } } diff --git a/applications/crossbar/priv/couchdb/views/functionsdb-functions.json b/applications/crossbar/priv/couchdb/views/functionsdb-functions.json index dea176c9f64..6fffe1be5eb 100644 --- a/applications/crossbar/priv/couchdb/views/functionsdb-functions.json +++ b/applications/crossbar/priv/couchdb/views/functionsdb-functions.json @@ -9,19 +9,74 @@ }, "language": "javascript", "shows": { - "print_doc": "function(doc, req) { if(doc==null) return {'json': {'error' : 'empty function definition'}}; return {'json': {'doc':doc, 'call':req.query}}; }", - "wh": "function(doc, req) { if (req==null || req.query==null) return {'json': {'error' : 'empty callflow document'}}; if (doc == null || doc == '') return {'json': {'error' : 'empty function definition'}}; var mRc = new Function('call', doc.function_js); return {'json': mRc(req.query)}; }" + "print_doc": [ + "function(doc, req) {", + " if (doc == null) return {", + " 'json': {", + " 'error': 'empty function definition'", + " }", + " };", + " return {", + " 'json': {", + " 'doc': doc,", + " 'call': req.query", + " }", + " };", + "}" + ], + "wh": [ + "function(doc, req) {", + " if (req == null || req.query == null) return {", + " 'json': {", + " 'error': 'empty callflow document'", + " }", + " };", + " if (doc == null || doc == '') return {", + " 'json': {", + " 'error': 'empty function definition'", + " }", + " };", + " var mRc = new Function('call', doc.function_js);", + " return {", + " 'json': mRc(req.query)", + " };", + "}" + ] }, "views": { "accounts_listing": { - "map": "function(doc) { if (doc.pvt_type !== 'function' || doc.pvt_deleted) return; emit(doc.pvt_account_id, null); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type !== 'function' || doc.pvt_deleted) return;", + " emit(doc.pvt_account_id, null);", + "}" + ], "reduce": "_count" }, "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type !== 'function' || doc.pvt_deleted) return; var enabled = (typeof doc.enabled === 'undefined') ? true : doc.enabled; emit([doc.pvt_account_id, doc._id], {'name':doc.name, 'function_js': doc.function_js, 'enabled':enabled, 'disable_reason':doc.pvt_disabled_message}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type !== 'function' || doc.pvt_deleted) return;", + " var enabled = (typeof doc.enabled === 'undefined') ? true : doc.enabled;", + " emit([doc.pvt_account_id, doc._id], {", + " 'name': doc.name,", + " 'function_js': doc.function_js,", + " 'enabled': enabled,", + " 'disable_reason': doc.pvt_disabled_message", + " });", + "}" + ] }, "functions_listing": { - "map": "function(doc) { if (doc.pvt_type !== 'function' || doc.pvt_deleted || doc.enabled === false) return; emit([doc.pvt_account_id, doc._id], {'name':doc.name, 'function_js': doc.function_js}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type !== 'function' || doc.pvt_deleted || doc.enabled === false) return;", + " emit([doc.pvt_account_id, doc._id], {", + " 'name': doc.name,", + " 'function_js': doc.function_js", + " });", + "}" + ] } } } diff --git a/applications/doodle/.circleci/config.yml b/applications/doodle/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/doodle/.circleci/config.yml +++ b/applications/doodle/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/doodle/priv/couchdb/views/sms.json b/applications/doodle/priv/couchdb/views/sms.json index 470ce4b59cf..17536907741 100644 --- a/applications/doodle/priv/couchdb/views/sms.json +++ b/applications/doodle/priv/couchdb/views/sms.json @@ -15,14 +15,14 @@ " if (doc.pvt_type != 'sms' || doc.pvt_deleted) return;", " var direction = doc.pvt_authorization_type == 'resource' ? 'inbound' : 'outbound';", " emit([doc.pvt_created, doc._id], {", - " 'id' : doc._id,", - " 'from' : doc.from_user,", - " 'to' : doc.to_user,", - " 'created' : doc.pvt_created,", - " 'direction' : direction,", - " 'status' : doc.pvt_status,", - " 'body' : doc.Body", - " });", + " 'id': doc._id,", + " 'from': doc.from_user,", + " 'to': doc.to_user,", + " 'created': doc.pvt_created,", + " 'direction': direction,", + " 'status': doc.pvt_status,", + " 'body': doc.Body", + " });", "}" ] }, @@ -30,7 +30,9 @@ "map": [ "function(doc) {", " if (doc.pvt_type != 'sms' || doc.pvt_deleted || (doc.pvt_status != 'queued' && doc.pvt_status != 'pending')) return;", - " emit( (doc.pvt_schedule.start_time ? doc.pvt_schedule.start_time : doc.pvt_created), {'id' : doc._id} );", + " emit((doc.pvt_schedule.start_time ? doc.pvt_schedule.start_time : doc.pvt_created), {", + " 'id': doc._id", + " });", "}" ] }, @@ -38,7 +40,9 @@ "map": [ "function(doc) {", " if (doc.pvt_type != 'sms' || doc.pvt_deleted || (!doc.pvt_target_device_id) || doc.pvt_status != 'pending') return;", - " emit([pvt_target_device_id, doc.pvt_schedule.start_time], {'id': doc._id});", + " emit([pvt_target_device_id, doc.pvt_schedule.start_time], {", + " 'id': doc._id", + " });", "}" ] }, @@ -46,69 +50,71 @@ "map": [ "function(doc) {", " if (doc.pvt_type != 'sms' || doc.pvt_deleted || doc.pvt_status != 'pending' || (doc.pvt_call['Key-Value-Store'].cf_flow.module != 'offnet' && doc.pvt_call['Key-Value-Store'].cf_flow.module != 'resources')) return;", - " emit( doc.pvt_schedule.start_time, {'id': doc._id});", + " emit(doc.pvt_schedule.start_time, {", + " 'id': doc._id", + " });", "}" ] }, "deliver_to_owner": { "map": [ - "function(doc) { if (doc.pvt_type != 'sms' || doc.pvt_deleted || (!doc.pvt_target_owner_id) || doc.pvt_status != 'pending') return;", - " emit([doc.pvt_target_owner_id, doc.pvt_schedule.start_time], {'id': doc._id});", + "function(doc) {", + " if (doc.pvt_type != 'sms' || doc.pvt_deleted || (!doc.pvt_target_owner_id) || doc.pvt_status != 'pending') return;", + " emit([doc.pvt_target_owner_id, doc.pvt_schedule.start_time], {", + " 'id': doc._id", + " });", "}" ] }, "listing_by_device": { "map": [ - "function(doc) { if (doc.pvt_type != 'sms' || doc.pvt_deleted) return;", + "function(doc) {", + " if (doc.pvt_type != 'sms' || doc.pvt_deleted) return;", " if ((doc.pvt_authorization_type != 'device' || doc.pvt_authorization_type != 'mobile') && !doc.pvt_target_device_id) return;", - " if (doc.pvt_target_device_id)", - " emit([doc.pvt_target_device_id, doc.pvt_created], {", - " 'id' : doc._id,", - " 'from' : doc.from_user,", - " 'to' : doc.to_user,", - " 'created' : doc.pvt_created,", - " 'direction' : 'inbound',", - " 'status' : doc.pvt_status,", - " 'body' : doc.Body", - " });", - " if (doc.pvt_authorization_type == 'device' || doc.pvt_authorization_type == 'mobile')", - " emit([doc.pvt_authorization_id, doc.pvt_created], {", - " 'id' : doc._id,", - " 'from' : doc.from_user,", - " 'to' : doc.to_user,", - " 'created' : doc.pvt_created,", - " 'direction' : 'outbound',", - " 'status' : doc.pvt_status,", - " 'body' : doc.Body", - " });", + " if (doc.pvt_target_device_id) emit([doc.pvt_target_device_id, doc.pvt_created], {", + " 'id': doc._id,", + " 'from': doc.from_user,", + " 'to': doc.to_user,", + " 'created': doc.pvt_created,", + " 'direction': 'inbound',", + " 'status': doc.pvt_status,", + " 'body': doc.Body", + " });", + " if (doc.pvt_authorization_type == 'device' || doc.pvt_authorization_type == 'mobile') emit([doc.pvt_authorization_id, doc.pvt_created], {", + " 'id': doc._id,", + " 'from': doc.from_user,", + " 'to': doc.to_user,", + " 'created': doc.pvt_created,", + " 'direction': 'outbound',", + " 'status': doc.pvt_status,", + " 'body': doc.Body", + " });", "}" ] }, "listing_by_owner": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type != 'sms' || doc.pvt_deleted) return;", " if (doc.pvt_authorization_type != 'user' && !doc.pvt_owner_id && !doc.pvt_target_owner_id) return;", - " if (doc.pvt_target_owner_id)", - " emit([doc.pvt_target_owner_id, doc.pvt_created], {", - " 'id' : doc._id,", - " 'from' : doc.from_user,", - " 'to' : doc.to_user,", - " 'created' : doc.pvt_created,", - " 'direction' : 'inbound',", - " 'status' : doc.pvt_status,", - " 'body' : doc.Body", - " });", - " if (doc.pvt_owner_id)", - " emit([doc.pvt_owner_id, doc.pvt_created], {", - " 'id' : doc._id,", - " 'from' : doc.from_user,", - " 'to' : doc.to_user,", - " 'created' : doc.pvt_created,", - " 'direction' : 'outbound',", - " 'status' : doc.pvt_status,", - " 'body' : doc.Body", - " });", + " if (doc.pvt_target_owner_id) emit([doc.pvt_target_owner_id, doc.pvt_created], {", + " 'id': doc._id,", + " 'from': doc.from_user,", + " 'to': doc.to_user,", + " 'created': doc.pvt_created,", + " 'direction': 'inbound',", + " 'status': doc.pvt_status,", + " 'body': doc.Body", + " });", + " if (doc.pvt_owner_id) emit([doc.pvt_owner_id, doc.pvt_created], {", + " 'id': doc._id,", + " 'from': doc.from_user,", + " 'to': doc.to_user,", + " 'created': doc.pvt_created,", + " 'direction': 'outbound',", + " 'status': doc.pvt_status,", + " 'body': doc.Body", + " });", "}" ] }, @@ -116,7 +122,9 @@ "map": [ "function(doc) {", " if (doc.pvt_type != 'sms' || doc.pvt_deleted || doc.pvt_status != 'queued') return;", - " emit(doc.pvt_created, {'id' : doc._id} );", + " emit(doc.pvt_created, {", + " 'id': doc._id", + " });", "}" ] } diff --git a/applications/ecallmgr/.circleci/config.yml b/applications/ecallmgr/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/ecallmgr/.circleci/config.yml +++ b/applications/ecallmgr/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/edr/.circleci/config.yml b/applications/edr/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/edr/.circleci/config.yml +++ b/applications/edr/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/fax/.circleci/config.yml b/applications/fax/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/fax/.circleci/config.yml +++ b/applications/fax/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/fax/priv/couchdb/views/faxbox.json b/applications/fax/priv/couchdb/views/faxbox.json index e4ac2dbc8a5..4202c71ced8 100644 --- a/applications/fax/priv/couchdb/views/faxbox.json +++ b/applications/fax/priv/couchdb/views/faxbox.json @@ -10,16 +10,51 @@ "language": "javascript", "views": { "cloud": { - "map": "function(doc) { if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.pvt_cloud_printer_id) return; emit(doc.pvt_cloud_printer_id, {'faxbox_id' : doc._id, 'account_id' : doc.pvt_account_id, 'cloud_printer_id': doc.pvt_cloud_printer_id, 'state': doc.pvt_cloud_state, 'xmpp_jid' : doc.pvt_cloud_xmpp_jid } ); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.pvt_cloud_printer_id) return;", + " emit(doc.pvt_cloud_printer_id, {", + " 'faxbox_id': doc._id,", + " 'account_id': doc.pvt_account_id,", + " 'cloud_printer_id': doc.pvt_cloud_printer_id,", + " 'state': doc.pvt_cloud_state,", + " 'xmpp_jid': doc.pvt_cloud_xmpp_jid", + " });", + "}" + ] }, "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'faxbox' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'created': doc.pvt_created }); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'faxbox' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'created': doc.pvt_created", + " });", + "}" + ] }, "email_address": { - "map": "function(doc) { if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.pvt_smtp_email_address ) return; emit(doc.pvt_smtp_email_address, doc.pvt_account_id); if(doc.custom_smtp_email_address) { emit(doc.custom_smtp_email_address, doc.pvt_account_id); }; }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.pvt_smtp_email_address) return;", + " emit(doc.pvt_smtp_email_address, doc.pvt_account_id);", + " if (doc.custom_smtp_email_address) {", + " emit(doc.custom_smtp_email_address, doc.pvt_account_id);", + " };", + "}" + ] }, "email_permissions": { - "map": "function(doc) { if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.smtp_permission_list || ! Array.isArray(doc.smtp_permission_list) ) return; doc.smtp_permission_list.forEach(function (tag) { emit(tag.toLowerCase(), 1); }); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.smtp_permission_list || !Array.isArray(doc.smtp_permission_list)) return;", + " doc.smtp_permission_list.forEach(function(tag) {", + " emit(tag.toLowerCase(), 1);", + " });", + "}" + ], "reduce": "_count" } } diff --git a/applications/fax/priv/couchdb/views/faxes.json b/applications/fax/priv/couchdb/views/faxes.json index d06c423a980..7ced5405176 100644 --- a/applications/fax/priv/couchdb/views/faxes.json +++ b/applications/fax/priv/couchdb/views/faxes.json @@ -12,8 +12,7 @@ "crossbar_listing": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted) return;", " emit(doc._id, {", " 'modified': doc.pvt_modified", " });", @@ -23,18 +22,17 @@ "jobs": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted || (doc.pvt_job_status != 'pending' && doc.pvt_job_status != 'locked' ))", - " return;", - " key = doc.pvt_modified + (doc.retry_after != null ? doc.retry_after : 0);", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || (doc.pvt_job_status != 'pending' && doc.pvt_job_status != 'locked')) return;", + " key = doc.pvt_modified + (doc.retry_after != null ? doc.retry_after : 0);", " emit(key, {", - " 'id' : doc._id,", - " 'account_id': doc.pvt_account_id,", - " 'faxbox_id': doc.faxbox_id,", - " 'to': doc.to_number,", - " 'from': doc.from_number,", - " 'modified': doc.pvt_modified,", - " 'retry_after': doc.retry_after,", - " 'tries' : doc.attempts+'/'+doc.retries ", + " 'id': doc._id,", + " 'account_id': doc.pvt_account_id,", + " 'faxbox_id': doc.faxbox_id,", + " 'to': doc.to_number,", + " 'from': doc.from_number,", + " 'modified': doc.pvt_modified,", + " 'retry_after': doc.retry_after,", + " 'tries': doc.attempts + '/' + doc.retries", " });", "}" ] @@ -42,8 +40,7 @@ "jobs_by_account": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted || doc.pvt_job_status != 'pending')", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || doc.pvt_job_status != 'pending') return;", " key = doc.pvt_modified + (doc.retry_after != null ? doc.retry_after : 0);", " emit([doc.pvt_account_id, key], {", " 'id': doc._id,", @@ -60,8 +57,7 @@ "list_by_account": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted) return;", " emit([doc.pvt_account_id, doc.pvt_created], {", " 'id': doc._id,", " 'faxbox_id': doc.faxbox_id,", @@ -77,8 +73,7 @@ "list_by_account_state": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted) return;", " emit([doc.pvt_account_id, doc.pvt_job_status, doc.pvt_created], {", " 'id': doc._id,", " 'account_id': doc.pvt_account_id,", @@ -95,8 +90,7 @@ "list_by_faxbox": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.faxbox_id)", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.faxbox_id) return;", " emit([doc.faxbox_id, doc.pvt_created], {", " 'id': doc._id,", " 'faxbox_id': doc.faxbox_id,", @@ -112,8 +106,7 @@ "list_by_faxbox_state": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.faxbox_id)", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.faxbox_id) return;", " emit([doc.faxbox_id, doc.pvt_job_status, doc.pvt_created], {", " 'id': doc._id,", " 'account_id': doc.pvt_account_id,", @@ -122,7 +115,7 @@ " 'to': doc.to_number,", " 'from': doc.from_number,", " 'created': doc.pvt_created,", - " 'modified' : doc.pvt_modified", + " 'modified': doc.pvt_modified", " });", "}" ] @@ -130,8 +123,7 @@ "list_by_owner": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.owner_id)", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.owner_id) return;", " emit([doc.owner_id, doc.pvt_created], {", " 'id': doc._id,", " 'status': doc.pvt_job_status,", @@ -145,8 +137,7 @@ "locked_jobs_by_account": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted || doc.pvt_job_status != 'locked')", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || doc.pvt_job_status != 'locked') return;", " emit(doc.pvt_account_id, {", " 'id': doc._id,", " 'account_id': doc.pvt_account_id,", @@ -162,8 +153,7 @@ "processing_by_node": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_job_status != 'processing' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_job_status != 'processing' || doc.pvt_deleted) return;", " emit(doc.pvt_job_node, {", " 'node': doc.pvt_job_node,", " 'id': doc._id,", @@ -179,8 +169,7 @@ "schedule_accounts": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'fax' || doc.pvt_deleted || (doc.pvt_job_status != 'pending'))", - " return;", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || (doc.pvt_job_status != 'pending')) return;", " emit(doc.pvt_account_id, 1);", "}" ], diff --git a/applications/frontier/.circleci/config.yml b/applications/frontier/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/frontier/.circleci/config.yml +++ b/applications/frontier/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/hangups/.circleci/config.yml b/applications/hangups/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/hangups/.circleci/config.yml +++ b/applications/hangups/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/hotornot/.circleci/config.yml b/applications/hotornot/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/hotornot/.circleci/config.yml +++ b/applications/hotornot/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/jonny5/.circleci/config.yml b/applications/jonny5/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/jonny5/.circleci/config.yml +++ b/applications/jonny5/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/konami/.circleci/config.yml b/applications/konami/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/konami/.circleci/config.yml +++ b/applications/konami/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/media_mgr/.circleci/config.yml b/applications/media_mgr/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/media_mgr/.circleci/config.yml +++ b/applications/media_mgr/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/milliwatt/.circleci/config.yml b/applications/milliwatt/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/milliwatt/.circleci/config.yml +++ b/applications/milliwatt/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/notify/.circleci/config.yml b/applications/notify/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/notify/.circleci/config.yml +++ b/applications/notify/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/omnipresence/.circleci/config.yml b/applications/omnipresence/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/omnipresence/.circleci/config.yml +++ b/applications/omnipresence/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/pivot/.circleci/config.yml b/applications/pivot/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/pivot/.circleci/config.yml +++ b/applications/pivot/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/pusher/.circleci/config.yml b/applications/pusher/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/pusher/.circleci/config.yml +++ b/applications/pusher/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/registrar/.circleci/config.yml b/applications/registrar/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/registrar/.circleci/config.yml +++ b/applications/registrar/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/registrar/priv/couchdb/views/credentials.json b/applications/registrar/priv/couchdb/views/credentials.json index 4936714977e..92efe63cb4e 100644 --- a/applications/registrar/priv/couchdb/views/credentials.json +++ b/applications/registrar/priv/couchdb/views/credentials.json @@ -11,7 +11,7 @@ "views": { "lookup": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type != 'device' || typeof doc.sip == 'undefined' || doc.pvt_deleted) return;", " var sip = JSON.parse(JSON.stringify(doc.sip));", " sip.id = doc._id;", @@ -19,11 +19,10 @@ " sip.account_db = doc.pvt_account_db;", " sip.authorizing_id = doc._id;", " sip.authorizing_type = doc.device_type == 'mobile' ? 'mobile' : doc.pvt_type;", - " if (typeof (sip.realm) == 'string') {", + " if (typeof(sip.realm) == 'string') {", " emit([sip.realm.toLowerCase(), sip.username.toLowerCase()], sip);", " } else {", - " for (var i in sip.realm)", - " emit([sip.realm[i].toLowerCase(), sip.username.toLowerCase()], sip);", + " for (var i in sip.realm) emit([sip.realm[i].toLowerCase(), sip.username.toLowerCase()], sip);", " }", "}" ] @@ -38,7 +37,7 @@ }, "lookup_by_ip": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_deleted || doc.enabled == false) return;", " if (doc.pvt_type == 'device' && doc.sip && doc.sip.ip && doc.sip.method == 'ip') {", " emit(doc.sip.inbound_ip || doc.sip.ip, {", @@ -48,13 +47,12 @@ " 'authorizing_type': doc.device_type == 'mobile' ? 'mobile' : doc.pvt_type", " });", " } else if (doc.pvt_type == 'resource' && doc.gateways && doc.peer) {", - " doc.gateways.forEach(function (gateway) {", - " if (gateway.inbound_ip || gateway.server)", - " emit(gateway.inbound_ip || gateway.server, {", - " 'account_id': doc.pvt_account_id,", - " 'authorizing_id': doc._id,", - " 'authorizing_type': doc.pvt_type", - " });", + " doc.gateways.forEach(function(gateway) {", + " if (gateway.inbound_ip || gateway.server) emit(gateway.inbound_ip || gateway.server, {", + " 'account_id': doc.pvt_account_id,", + " 'authorizing_id': doc._id,", + " 'authorizing_type': doc.pvt_type", + " });", " });", " }", "}" diff --git a/applications/reorder/.circleci/config.yml b/applications/reorder/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/reorder/.circleci/config.yml +++ b/applications/reorder/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/skel/.circleci/config.yml b/applications/skel/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/skel/.circleci/config.yml +++ b/applications/skel/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/spyvsspy/.circleci/config.yml b/applications/spyvsspy/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/spyvsspy/.circleci/config.yml +++ b/applications/spyvsspy/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/stats/.circleci/config.yml b/applications/stats/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/stats/.circleci/config.yml +++ b/applications/stats/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/stepswitch/.circleci/config.yml b/applications/stepswitch/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/stepswitch/.circleci/config.yml +++ b/applications/stepswitch/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/stepswitch/priv/couchdb/views/multi_db-resources.json b/applications/stepswitch/priv/couchdb/views/multi_db-resources.json index dff1c2d03b4..7a4877371ae 100644 --- a/applications/stepswitch/priv/couchdb/views/multi_db-resources.json +++ b/applications/stepswitch/priv/couchdb/views/multi_db-resources.json @@ -13,19 +13,75 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) {if (doc.pvt_type != 'resource' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id,'name': doc.name,'enabled': doc.enabled,'weight_cost': doc.weight_cost,'template_name': doc.template_name,'classifiers': doc.classifiers});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'enabled': doc.enabled,", + " 'weight_cost': doc.weight_cost,", + " 'template_name': doc.template_name,", + " 'classifiers': doc.classifiers", + " });", + "}" + ] }, "listing_active_by_rules": { - "map": "function(doc) { if (doc.pvt_type != 'resource' || ! doc.enabled || doc.pvt_deleted) return; for (var i in doc.rules) emit([doc.weight_cost, doc.rules[i]], {'id': doc._id, 'gateways': doc.gateways, 'caller_id_options': doc.caller_id_options, 'flags':doc.flags || []}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource' || !doc.enabled || doc.pvt_deleted) return;", + " for (var i in doc.rules) emit([doc.weight_cost, doc.rules[i]], {", + " 'id': doc._id,", + " 'gateways': doc.gateways,", + " 'caller_id_options': doc.caller_id_options,", + " 'flags': doc.flags || []", + " });", + "}" + ] }, "listing_active_by_weight": { - "map": "function(doc) { if (doc.pvt_type != 'resource' || ! doc.enabled || doc.pvt_deleted) return; emit([parseInt(doc.weight_cost, 10), doc._id], doc.name); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource' || !doc.enabled || doc.pvt_deleted) return;", + " emit([parseInt(doc.weight_cost, 10), doc._id], doc.name);", + "}" + ] }, "listing_by_id": { - "map": "function(doc) { if (doc.pvt_type != 'resource' || doc.pvt_deleted) return; emit(doc._id, doc.name); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource' || doc.pvt_deleted) return;", + " emit(doc._id, doc.name);", + "}" + ] }, "listing_uac_gateways": { - "map": "function (doc) { if (doc.pvt_type != 'resource' || doc.pvt_deleted || !doc.enabled) return; for (var index in doc.gateways) { if (!doc.gateways[index] || !doc.gateways[index].register || doc.gateways[index].enabled == false) { continue; } var gateway = doc.gateways[index]; emit(doc._id, {'username': gateway.username, 'auth_username': gateway.auth_username, 'server': gateway.server, 'password': gateway.password, 'realm': gateway.realm, 'expiration': gateway.expiration, 'proxy': gateway.proxy, 'account_id': doc.pvt_account_id, 'id': doc._id + '-' + index, 'resource_id': doc._id, 'register_extension': gateway.register_extension, 'version': doc._rev})}}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource' || doc.pvt_deleted || !doc.enabled) return;", + " for (var index in doc.gateways) {", + " if (!doc.gateways[index] || !doc.gateways[index].register || doc.gateways[index].enabled == false) {", + " continue;", + " }", + " var gateway = doc.gateways[index];", + " emit(doc._id, {", + " 'username': gateway.username,", + " 'auth_username': gateway.auth_username,", + " 'server': gateway.server,", + " 'password': gateway.password,", + " 'realm': gateway.realm,", + " 'expiration': gateway.expiration,", + " 'proxy': gateway.proxy,", + " 'account_id': doc.pvt_account_id,", + " 'id': doc._id + '-' + index,", + " 'resource_id': doc._id,", + " 'register_extension': gateway.register_extension,", + " 'version': doc._rev", + " })", + " }", + "}" + ] } } } diff --git a/applications/stepswitch/priv/couchdb/views/resource_selectors.json b/applications/stepswitch/priv/couchdb/views/resource_selectors.json index 3d62ba0d182..22f89bd4ecd 100644 --- a/applications/stepswitch/priv/couchdb/views/resource_selectors.json +++ b/applications/stepswitch/priv/couchdb/views/resource_selectors.json @@ -10,32 +10,128 @@ "language": "javascript", "views": { "id_listing": { - "map": "function(doc) { if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return; emit([doc._id], {'name': doc.name, 'selector': doc.selector, 'value': doc.value, 'resource': doc.resource, 'start_time': doc.start_time, 'stop_time': doc.stop_time}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return;", + " emit([doc._id], {", + " 'name': doc.name,", + " 'selector': doc.selector,", + " 'value': doc.value,", + " 'resource': doc.resource,", + " 'start_time': doc.start_time,", + " 'stop_time': doc.stop_time", + " });", + "}" + ] }, "name_listing": { - "map": "function(doc) { if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return; emit([doc.name], {'name': doc.name, 'selector': doc.selector, 'value': doc.value, 'resource': doc.resource, 'start_time': doc.start_time, 'stop_time': doc.stop_time}); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return;", + " emit([doc.name], {", + " 'name': doc.name,", + " 'selector': doc.selector,", + " 'value': doc.value,", + " 'resource': doc.resource,", + " 'start_time': doc.start_time,", + " 'stop_time': doc.stop_time", + " });", + "}" + ], "reduce": "_count" }, "name_resource_listing": { - "map": "function(doc) { if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return; emit([doc.name, doc.resource], {'name': doc.name, 'selector': doc.selector, 'value': doc.value, 'resource': doc.resource, 'start_time': doc.start_time, 'stop_time': doc.stop_time}); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return;", + " emit([doc.name, doc.resource], {", + " 'name': doc.name,", + " 'selector': doc.selector,", + " 'value': doc.value,", + " 'resource': doc.resource,", + " 'start_time': doc.start_time,", + " 'stop_time': doc.stop_time", + " });", + "}" + ], "reduce": "_count" }, "name_selector_listing": { - "map": "function(doc) { if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return; emit([doc.name, doc.selector], {'name': doc.name, 'selector': doc.selector, 'value': doc.value, 'resource': doc.resource, 'start_time': doc.start_time, 'stop_time': doc.stop_time}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return;", + " emit([doc.name, doc.selector], {", + " 'name': doc.name,", + " 'selector': doc.selector,", + " 'value': doc.value,", + " 'resource': doc.resource,", + " 'start_time': doc.start_time,", + " 'stop_time': doc.stop_time", + " });", + "}" + ] }, "resource_listing": { - "map": "function(doc) { if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return; emit([doc.resource], {'name': doc.name, 'selector': doc.selector, 'value': doc.value, 'resource': doc.resource, 'start_time': doc.start_time, 'stop_time': doc.stop_time}); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return;", + " emit([doc.resource], {", + " 'name': doc.name,", + " 'selector': doc.selector,", + " 'value': doc.value,", + " 'resource': doc.resource,", + " 'start_time': doc.start_time,", + " 'stop_time': doc.stop_time", + " });", + "}" + ], "reduce": "_count" }, "resource_name_id_listing": { - "map": "function(doc) { if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return; emit([doc.resource, doc.name, doc._id], {'name': doc.name, 'selector': doc.selector, 'value': doc.value, 'resource': doc.resource, 'start_time': doc.start_time, 'stop_time': doc.stop_time}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return;", + " emit([doc.resource, doc.name, doc._id], {", + " 'name': doc.name,", + " 'selector': doc.selector,", + " 'value': doc.value,", + " 'resource': doc.resource,", + " 'start_time': doc.start_time,", + " 'stop_time': doc.stop_time", + " });", + "}" + ] }, "resource_name_listing": { - "map": "function(doc) { if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return; emit([doc.resource, doc.name], {'name': doc.name, 'selector': doc.selector, 'value': doc.value, 'resource': doc.resource, 'start_time': doc.start_time, 'stop_time': doc.stop_time}); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return;", + " emit([doc.resource, doc.name], {", + " 'name': doc.name,", + " 'selector': doc.selector,", + " 'value': doc.value,", + " 'resource': doc.resource,", + " 'start_time': doc.start_time,", + " 'stop_time': doc.stop_time", + " });", + "}" + ], "reduce": "_count" }, "resource_name_selector_listing": { - "map": "function(doc) { if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return; emit([doc.resource, doc.name, doc.selector], {'name': doc.name, 'selector': doc.selector, 'value': doc.value, 'resource': doc.resource, 'start_time': doc.start_time, 'stop_time': doc.stop_time}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_selector' || doc.pvt_deleted || !doc.name) return;", + " emit([doc.resource, doc.name, doc.selector], {", + " 'name': doc.name,", + " 'selector': doc.selector,", + " 'value': doc.value,", + " 'resource': doc.resource,", + " 'start_time': doc.start_time,", + " 'stop_time': doc.stop_time", + " });", + "}" + ] } } } diff --git a/applications/sysconf/.circleci/config.yml b/applications/sysconf/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/sysconf/.circleci/config.yml +++ b/applications/sysconf/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/tasks/.circleci/config.yml b/applications/tasks/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/tasks/.circleci/config.yml +++ b/applications/tasks/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/tasks/priv/couchdb/views/compactor.json b/applications/tasks/priv/couchdb/views/compactor.json index fd9f23148d0..9668ebe14b5 100644 --- a/applications/tasks/priv/couchdb/views/compactor.json +++ b/applications/tasks/priv/couchdb/views/compactor.json @@ -16,7 +16,7 @@ "map": [ "function(doc) {", " for (var node in doc['by_node']) {", - " emit([node, doc._id], null);", + " emit([node, doc._id], null);", " }", "}" ] diff --git a/applications/tasks/priv/couchdb/views/tasks.json b/applications/tasks/priv/couchdb/views/tasks.json index b1a8486b624..e80e6e9ad11 100644 --- a/applications/tasks/priv/couchdb/views/tasks.json +++ b/applications/tasks/priv/couchdb/views/tasks.json @@ -15,9 +15,11 @@ " if (doc.pvt_type != 'task' || doc.pvt_deleted) return;", " var csvs;", " if ('_attachments' in doc) {", - " csvs = []; ", - " for (var k in doc['_attachments']) { csvs.push(k); } ", - " } ", + " csvs = [];", + " for (var k in doc['_attachments']) {", + " csvs.push(k);", + " }", + " }", " emit([doc.pvt_account_id, doc._id], {", " id: doc._id,", " account_id: doc.pvt_account_id,", @@ -43,9 +45,11 @@ " if (doc.pvt_type != 'task' || doc.pvt_deleted) return;", " var csvs;", " if ('_attachments' in doc) {", - " csvs = []; ", - " for (var k in doc['_attachments']) { csvs.push(k); } ", - " } ", + " csvs = [];", + " for (var k in doc['_attachments']) {", + " csvs.push(k);", + " }", + " }", " emit([doc.pvt_account_id, doc.pvt_created, doc._id], {", " id: doc._id,", " account_id: doc.pvt_account_id,", diff --git a/applications/teletype/.circleci/config.yml b/applications/teletype/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/teletype/.circleci/config.yml +++ b/applications/teletype/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/teletype/priv/couchdb/views/notifications.json b/applications/teletype/priv/couchdb/views/notifications.json index b381f8a5e50..8633dcc2d33 100644 --- a/applications/teletype/priv/couchdb/views/notifications.json +++ b/applications/teletype/priv/couchdb/views/notifications.json @@ -10,7 +10,19 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) {if (doc.pvt_type != 'notification' || doc.pvt_deleted) return; var id = doc._id.replace(\"notification.\", \"\"); emit(id, {'id': id, 'category':doc.category, 'friendly_name':doc.friendly_name, 'macros':doc.macros, 'enabled': doc.enabled});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'notification' || doc.pvt_deleted) return;", + " var id = doc._id.replace(\"notification.\", \"\");", + " emit(id, {", + " 'id': id,", + " 'category': doc.category,", + " 'friendly_name': doc.friendly_name,", + " 'macros': doc.macros,", + " 'enabled': doc.enabled", + " });", + "}" + ] } } } diff --git a/applications/trunkstore/.circleci/config.yml b/applications/trunkstore/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/trunkstore/.circleci/config.yml +++ b/applications/trunkstore/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/webhooks/.circleci/config.yml b/applications/webhooks/.circleci/config.yml index bf56912d21b..c8466bd8a92 100644 --- a/applications/webhooks/.circleci/config.yml +++ b/applications/webhooks/.circleci/config.yml @@ -117,7 +117,7 @@ workflows: defaults: &defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 shell: /bin/bash --login working_directory: ~/2600hz/the_app environment: @@ -334,7 +334,7 @@ jobs: release: <<: *defaults docker: - - image: offical2600hz/circleci:21.3.8.8 + - image: offical2600hz/circleci:21.3.8.12 - image: couchdb:2.3.1 - image: 2600hz/rabbitmq steps: diff --git a/applications/webhooks/priv/couchdb/views/account-webhooks.json b/applications/webhooks/priv/couchdb/views/account-webhooks.json index 01bf1bf6572..8adfcf27b7d 100644 --- a/applications/webhooks/priv/couchdb/views/account-webhooks.json +++ b/applications/webhooks/priv/couchdb/views/account-webhooks.json @@ -10,7 +10,12 @@ "language": "javascript", "views": { "webhook_meta_listing": { - "map": "function(doc) { if(doc.pvt_type != 'webhook_meta' || doc.pvt_deleted) return; emit(doc.name, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'webhook_meta' || doc.pvt_deleted) return;", + " emit(doc.name, null);", + "}" + ] } } } diff --git a/applications/webhooks/priv/couchdb/views/webhooksdb-webhooks.json b/applications/webhooks/priv/couchdb/views/webhooksdb-webhooks.json index fde7e04a8a1..121aeb804ae 100644 --- a/applications/webhooks/priv/couchdb/views/webhooksdb-webhooks.json +++ b/applications/webhooks/priv/couchdb/views/webhooksdb-webhooks.json @@ -10,17 +10,51 @@ "language": "javascript", "views": { "accounts_listing": { - "map": "function(doc) { if (doc.pvt_type != 'webhook' || doc.pvt_deleted) return; emit(doc.pvt_account_id, null); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'webhook' || doc.pvt_deleted) return;", + " emit(doc.pvt_account_id, null);", + "}" + ], "reduce": "_count" }, "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'webhook' || doc.pvt_deleted) return; var enabled = (typeof doc.enabled === 'undefined') ? true : doc.enabled; emit([doc.pvt_account_id, doc._id], {'id': doc._id, 'hook': doc.hook, 'name':doc.name, 'uri': doc.uri, 'group': doc.group, 'enabled':enabled, 'disable_reason':doc.pvt_disabled_message}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'webhook' || doc.pvt_deleted) return;", + " var enabled = (typeof doc.enabled === 'undefined') ? true : doc.enabled;", + " emit([doc.pvt_account_id, doc._id], {", + " 'id': doc._id,", + " 'hook': doc.hook,", + " 'name': doc.name,", + " 'uri': doc.uri,", + " 'group': doc.group,", + " 'enabled': enabled,", + " 'disable_reason': doc.pvt_disabled_message", + " });", + "}" + ] }, "hook_listing": { - "map": "function(doc) { if (doc.pvt_type != 'webhook' || doc.pvt_deleted) return; emit(doc.hook, doc.pvt_account_id); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'webhook' || doc.pvt_deleted) return;", + " emit(doc.hook, doc.pvt_account_id);", + "}" + ] }, "webhooks_listing": { - "map": "function(doc) { if (doc.pvt_type != 'webhook' || doc.pvt_deleted || doc.enabled === false) return; emit([doc.pvt_account_id, doc._id], {'id': doc._id, 'hook': doc.hook, 'name':doc.name, 'uri': doc.uri}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'webhook' || doc.pvt_deleted || doc.enabled === false) return;", + " emit([doc.pvt_account_id, doc._id], {", + " 'id': doc._id,", + " 'hook': doc.hook,", + " 'name': doc.name,", + " 'uri': doc.uri", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/access_lists.json b/core/kazoo_apps/priv/couchdb/account/access_lists.json index 7e94edd098c..4ab8afb6caf 100644 --- a/core/kazoo_apps/priv/couchdb/account/access_lists.json +++ b/core/kazoo_apps/priv/couchdb/account/access_lists.json @@ -10,7 +10,21 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) {if ((doc.pvt_type != 'account' && doc.pvt_type != 'device') || doc.pvt_deleted) return;var name = doc.realm || doc.sip.username;var type = '';if (doc.pvt_type == 'account') type = 'realm';else type = 'device';if (doc.access_lists) {emit(name, {'type': type,'acls': doc.access_lists});}};" + "map": [ + "function(doc) {", + " if ((doc.pvt_type != 'account' && doc.pvt_type != 'device') || doc.pvt_deleted) return;", + " var name = doc.realm || doc.sip.username;", + " var type = '';", + " if (doc.pvt_type == 'account') type = 'realm';", + " else type = 'device';", + " if (doc.access_lists) {", + " emit(name, {", + " 'type': type,", + " 'acls': doc.access_lists", + " });", + " }", + "};" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/account.json b/core/kazoo_apps/priv/couchdb/account/account.json index ca7495b46d4..3c0a7901fc5 100644 --- a/core/kazoo_apps/priv/couchdb/account/account.json +++ b/core/kazoo_apps/priv/couchdb/account/account.json @@ -10,13 +10,37 @@ "language": "javascript", "views": { "listing_by_id": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name", + " });", + "}" + ] }, "listing_by_name": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted) return; emit(doc.name, {'id': doc._id, 'name': doc.name}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " emit(doc.name, {", + " 'id': doc._id,", + " 'name': doc.name", + " });", + "}" + ] }, "listing_by_realm": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted) return; emit(doc.realm, {'account_id': doc._id, 'account_db': doc.pvt_account_db}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " emit(doc.realm, {", + " 'account_id': doc._id,", + " 'account_db': doc.pvt_account_db", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/apps_store.json b/core/kazoo_apps/priv/couchdb/account/apps_store.json index f0d0ba54fe5..efe56d1218c 100644 --- a/core/kazoo_apps/priv/couchdb/account/apps_store.json +++ b/core/kazoo_apps/priv/couchdb/account/apps_store.json @@ -11,7 +11,7 @@ "views": { "crossbar_listing": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type !== 'app' || doc.pvt_deleted) return;", " emit(doc.name, {", " id: doc._id,", diff --git a/core/kazoo_apps/priv/couchdb/account/attributes.json b/core/kazoo_apps/priv/couchdb/account/attributes.json index e8c0c72bb4a..318642c8353 100644 --- a/core/kazoo_apps/priv/couchdb/account/attributes.json +++ b/core/kazoo_apps/priv/couchdb/account/attributes.json @@ -10,28 +10,53 @@ "language": "javascript", "views": { "active_resources_by_rules": { - "map": "function(doc) { if (doc.pvt_type != 'resource' || ! doc.enabled || doc.pvt_deleted) return; for (var i in doc.rules) emit([doc.weight_cost, doc.rules[i]], {'id': doc._id, 'gateways': doc.gateways, 'caller_id_options': doc.caller_id_options,'flags':doc.flags||[]}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource' || !doc.enabled || doc.pvt_deleted) return;", + " for (var i in doc.rules) emit([doc.weight_cost, doc.rules[i]], {", + " 'id': doc._id,", + " 'gateways': doc.gateways,", + " 'caller_id_options': doc.caller_id_options,", + " 'flags': doc.flags || []", + " });", + "}" + ] }, "endpoints_lookup": { - "map": "function(doc) { if (typeof doc.caller_id === 'undefined') return; for(var type in doc.caller_id) emit([doc.caller_id[type].number, type], doc.pvt_type); }" + "map": [ + "function(doc) {", + " if (typeof doc.caller_id === 'undefined') return;", + " for (var type in doc.caller_id) emit([doc.caller_id[type].number, type], doc.pvt_type);", + "}" + ] }, "groups": { - "map": "function (doc) {if (doc.pvt_type != 'group' || doc.pvt_deleted || !doc.endpoints) return;emit(null, doc.endpoints);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'group' || doc.pvt_deleted || !doc.endpoints) return;", + " emit(null, doc.endpoints);", + "}" + ] }, "hotdesk_id": { - "map": "function(doc) { if (!doc.hotdesk || !doc.hotdesk.id || doc.pvt_deleted) return; emit(doc.hotdesk.id, null); }" + "map": [ + "function(doc) {", + " if (!doc.hotdesk || !doc.hotdesk.id || doc.pvt_deleted) return;", + " emit(doc.hotdesk.id, null);", + "}" + ] }, "hotdesk_users": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_deleted) return;", - " var has_users = false, o = (doc.hotdesk || {}).users || {};", + " var has_users = false,", + " o = (doc.hotdesk || {}).users || {};", " for (var p in o)", " if (o.hasOwnProperty(p)) {", " has_users = true;", " break;", - " }", - " if (doc.hotdesk && doc.hotdesk.users && has_users) {", + " } if (doc.hotdesk && doc.hotdesk.users && has_users) {", " for (owner_id in doc.hotdesk.users) {", " emit(owner_id, null);", " };", @@ -40,19 +65,24 @@ ] }, "mailbox_number": { - "map": "function(doc) { if (doc.pvt_type != 'vmbox' || doc.pvt_deleted) return; emit(doc.mailbox, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'vmbox' || doc.pvt_deleted) return;", + " emit(doc.mailbox, null);", + "}" + ] }, "owned": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_deleted) return;", - " var has_users = false, o = (doc.hotdesk || {}).users || {};", + " var has_users = false,", + " o = (doc.hotdesk || {}).users || {};", " for (var p in o)", " if (o.hasOwnProperty(p)) {", " has_users = true;", " break;", - " }", - " if (doc.hotdesk && doc.hotdesk.users && has_users) {", + " } if (doc.hotdesk && doc.hotdesk.users && has_users) {", " for (owner_id in doc.hotdesk.users) {", " emit([owner_id, doc.pvt_type], doc._id);", " };", @@ -64,15 +94,15 @@ }, "owner": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_deleted) return;", - " var has_users = false, o = (doc.hotdesk || {}).users || {};", + " var has_users = false,", + " o = (doc.hotdesk || {}).users || {};", " for (var p in o)", " if (o.hasOwnProperty(p)) {", " has_users = true;", " break;", - " }", - " if (doc.hotdesk && doc.hotdesk.users && has_users) {", + " } if (doc.hotdesk && doc.hotdesk.users && has_users) {", " for (owner_id in doc.hotdesk.users) {", " emit(doc._id, owner_id);", " };", @@ -84,13 +114,13 @@ }, "sip_username": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_deleted) return;", " var owners;", - " var users = [], o = (doc.hotdesk || {}).users || {};", + " var users = [],", + " o = (doc.hotdesk || {}).users || {};", " for (var p in o)", - " if (o.hasOwnProperty(p))", - " users.push(p);", + " if (o.hasOwnProperty(p)) users.push(p);", " if (doc.hotdesk && doc.hotdesk.users && users.length) {", " owners = users;", " } else if (doc.owner_id) {", @@ -113,7 +143,12 @@ ] }, "temporal_rules": { - "map": "function(doc) { if (doc.pvt_type != 'temporal_rule' || doc.pvt_deleted) return; emit(doc._id, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'temporal_rule' || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/auth.json b/core/kazoo_apps/priv/couchdb/account/auth.json index 4306fd0d579..15b1a06c492 100644 --- a/core/kazoo_apps/priv/couchdb/account/auth.json +++ b/core/kazoo_apps/priv/couchdb/account/auth.json @@ -12,8 +12,7 @@ "providers_by_type": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'provider' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'provider' || doc.pvt_deleted) return;", " emit([doc.pvt_provider_type, doc._id], {", " 'id': doc._id,", " 'enabled': doc.enabled,", diff --git a/core/kazoo_apps/priv/couchdb/account/blacklists.json b/core/kazoo_apps/priv/couchdb/account/blacklists.json index 5373bfcdb45..b4a7f8887e0 100644 --- a/core/kazoo_apps/priv/couchdb/account/blacklists.json +++ b/core/kazoo_apps/priv/couchdb/account/blacklists.json @@ -10,7 +10,16 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'blacklist' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'flags': doc.flags || [] }); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'blacklist' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'flags': doc.flags || []", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/callflows.json b/core/kazoo_apps/priv/couchdb/account/callflows.json index 23534aa81a3..0965f832996 100644 --- a/core/kazoo_apps/priv/couchdb/account/callflows.json +++ b/core/kazoo_apps/priv/couchdb/account/callflows.json @@ -11,35 +11,36 @@ "views": { "crossbar_listing": { "map": [ - "function (doc) {", - " if (doc.pvt_type != 'callflow' || doc.pvt_deleted) return;", - " var featurecode = (!doc.featurecode) ? false : doc.featurecode;", - " var modules = [];", - " if (doc.flow)", - " var walkTree = (function recursiveWalkTree(flow) {", - " if (flow.module && (flow.data && flow.data.skip_module !== true))", - " modules.push(flow.module);", - " if (flow.children) {", - " var children = flow.children;", - " for (var key in children) {", - " if (!children.hasOwnProperty(key)) continue;", - " recursiveWalkTree(children[key]);", - " }", - " }", - " })(doc.flow);", - " var onlyUnique = function(value, index, self) { return self.indexOf(value) === index; };", - " modules = modules.filter(onlyUnique);", - " emit(doc._id, {'id': doc._id", - " ,'name': doc.name", - " ,'type': doc.type", - " ,'numbers': doc.numbers", - " ,'patterns': doc.patterns", - " ,'featurecode': featurecode", - " ,'owner_id': doc.owner_id", - " ,'group_id': doc.group_id", - " ,'modules': modules", - " ,'flags': doc.flags || []", - " });", + "function(doc) {", + " if (doc.pvt_type != 'callflow' || doc.pvt_deleted) return;", + " var featurecode = (!doc.featurecode) ? false : doc.featurecode;", + " var modules = [];", + " if (doc.flow) var walkTree = (function recursiveWalkTree(flow) {", + " if (flow.module && (flow.data && flow.data.skip_module !== true)) modules.push(flow.module);", + " if (flow.children) {", + " var children = flow.children;", + " for (var key in children) {", + " if (!children.hasOwnProperty(key)) continue;", + " recursiveWalkTree(children[key]);", + " }", + " }", + " })(doc.flow);", + " var onlyUnique = function(value, index, self) {", + " return self.indexOf(value) === index;", + " };", + " modules = modules.filter(onlyUnique);", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'type': doc.type,", + " 'numbers': doc.numbers,", + " 'patterns': doc.patterns,", + " 'featurecode': featurecode,", + " 'owner_id': doc.owner_id,", + " 'group_id': doc.group_id,", + " 'modules': modules,", + " 'flags': doc.flags || []", + " });", "}" ] }, @@ -47,22 +48,30 @@ "map": [ "function(doc) {", " if (doc.pvt_type != 'callflow' || doc.pvt_deleted) return;", - " for (var i in doc.numbers) emit(doc.numbers[i], {'name' : doc.name || doc._id} ); }" + " for (var i in doc.numbers) emit(doc.numbers[i], {", + " 'name': doc.name || doc._id", + " });", + "}" ] }, "listing_by_pattern": { "map": [ "function(doc) {", " if (doc.pvt_type != 'callflow' || doc.pvt_deleted) return;", - "for (var i in doc.patterns) emit(doc.patterns[i], {'name' : doc.name || doc._id}); }" + " for (var i in doc.patterns) emit(doc.patterns[i], {", + " 'name': doc.name || doc._id", + " });", + "}" ] }, "msisdn": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'callflow' || doc.pvt_deleted || (doc.flow.module != 'user' && doc.flow.module != 'device') ) return; ", - " for (var i in doc.numbers) ", - " if(doc.numbers[i].charAt(0) == '+') emit([doc.flow.module, doc.flow.data.id, doc.numbers[i] ], {'msisdn' : doc.numbers[i]}); ", + " if (doc.pvt_type != 'callflow' || doc.pvt_deleted || (doc.flow.module != 'user' && doc.flow.module != 'device')) return;", + " for (var i in doc.numbers)", + " if (doc.numbers[i].charAt(0) == '+') emit([doc.flow.module, doc.flow.data.id, doc.numbers[i]], {", + " 'msisdn': doc.numbers[i]", + " });", "}" ] } diff --git a/core/kazoo_apps/priv/couchdb/account/click2call.json b/core/kazoo_apps/priv/couchdb/account/click2call.json index c85a66c333a..ae994bf7723 100644 --- a/core/kazoo_apps/priv/couchdb/account/click2call.json +++ b/core/kazoo_apps/priv/couchdb/account/click2call.json @@ -10,7 +10,17 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'click2call' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'extension': doc.extension, 'realm': doc.relam}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'click2call' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'extension': doc.extension,", + " 'realm': doc.relam", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/conference.json b/core/kazoo_apps/priv/couchdb/account/conference.json index 7c89ae1d582..012a077865c 100644 --- a/core/kazoo_apps/priv/couchdb/account/conference.json +++ b/core/kazoo_apps/priv/couchdb/account/conference.json @@ -10,7 +10,20 @@ "language": "javascript", "views": { "listing_by_number": { - "map": "function(doc) { if (doc.pvt_type != 'conference' || doc.pvt_deleted) return; if (typeof doc.moderator == 'object' && doc.moderator.numbers) doc.moderator.numbers.forEach(function (Num) {emit(Num, null)}); if (typeof doc.member == 'object' && doc.member.numbers) doc.member.numbers.forEach(function (Num) {emit(Num, null)}); if (doc.conference_numbers) doc.conference_numbers.forEach(function (Num) {emit(Num, null)});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'conference' || doc.pvt_deleted) return;", + " if (typeof doc.moderator == 'object' && doc.moderator.numbers) doc.moderator.numbers.forEach(function(Num) {", + " emit(Num, null)", + " });", + " if (typeof doc.member == 'object' && doc.member.numbers) doc.member.numbers.forEach(function(Num) {", + " emit(Num, null)", + " });", + " if (doc.conference_numbers) doc.conference_numbers.forEach(function(Num) {", + " emit(Num, null)", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/conferences.json b/core/kazoo_apps/priv/couchdb/account/conferences.json index 988d343ff82..d926ca199a4 100644 --- a/core/kazoo_apps/priv/couchdb/account/conferences.json +++ b/core/kazoo_apps/priv/couchdb/account/conferences.json @@ -10,10 +10,29 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'conference' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'owner_id': doc.owner_id, 'member': doc.member, 'moderator': doc.moderator, 'ui_flags': doc.ui_flags, 'conference_numbers': doc.conference_numbers, 'flags': doc.flags || []}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'conference' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'owner_id': doc.owner_id,", + " 'member': doc.member,", + " 'moderator': doc.moderator,", + " 'ui_flags': doc.ui_flags,", + " 'conference_numbers': doc.conference_numbers,", + " 'flags': doc.flags || []", + " });", + "}" + ] }, "listing_by_name": { - "map": "function(doc) { if (doc.pvt_type != 'conference' || doc.pvt_deleted) return; emit(doc.name, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'conference' || doc.pvt_deleted) return;", + " emit(doc.name, null);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/contact_list.json b/core/kazoo_apps/priv/couchdb/account/contact_list.json index 6ad11c12533..8c0a19ad25c 100644 --- a/core/kazoo_apps/priv/couchdb/account/contact_list.json +++ b/core/kazoo_apps/priv/couchdb/account/contact_list.json @@ -10,13 +10,73 @@ "language": "javascript", "views": { "excluded": { - "map": "function (doc) {\n if (!doc.pvt_deleted && (doc.contact_list || {}).exclude) emit(doc._id, null);\n}" + "map": [ + "function(doc) {", + " if (!doc.pvt_deleted && (doc.contact_list || {}).exclude) emit(doc._id, null);", + "}" + ] }, "extensions": { - "map": "function (doc) {if (doc.pvt_type != 'callflow' || doc.pvt_deleted || (doc.contact_list || {}).exclude) return;if ('numbers' in doc) {var requireid = ['menu', 'conference', 'directory', 'receive_fax', 'voicemail'];var featurecodes = ['call_forward', 'do_not_disturb', 'intercom', 'privacy', 'record_call', 'disa', 'dynamic_cid', 'hotdesk', 'manual_presence', 'park', , 'voicemail'];var first_module = (doc.flow || {}).module;var second_module = (((doc.flow || {}).children || {})._ || {}).module;var name = doc.name || ((doc.flow || {}).data || {}).name;var id = ((doc.flow || {}).data || {}).id || ((doc.flow || {}).data || {}).owner_id;if ((first_module == 'user' || first_module == 'device') && (second_module == 'voicemail' || !second_module) && id) {emit('extension', {'id': id,'numbers': doc.numbers});} else if (name) {emit((!doc.featurecode) ? 'custom' : 'featurecode', {'name': name,'first_module': first_module.replace('_', ' '),'numbers': doc.numbers});} else if (requireid.indexOf(first_module) >= 0 && id) {emit((!doc.featurecode) ? 'custom' : 'featurecode', {'id': id,'name': name,'first_module': first_module,'numbers': doc.numbers});} else if (featurecodes.indexOf(first_module) >= 0) {var action = ((doc.flow || {}).data || {}).action;if (!action) return;if (action == first_module) action = '';else action = ' (' + action + ')';emit((!doc.featurecode) ? 'custom' : 'featurecode', {'name': name || first_module.replace(/_/g, ' ') + action.replace(/_/g, ' '),'numbers': doc.numbers});}}}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'callflow' || doc.pvt_deleted || (doc.contact_list || {}).exclude) return;", + " if ('numbers' in doc) {", + " var requireid = ['menu', 'conference', 'directory', 'receive_fax', 'voicemail'];", + " var featurecodes = ['call_forward', 'do_not_disturb', 'intercom', 'privacy', 'record_call', 'disa', 'dynamic_cid', 'hotdesk', 'manual_presence', 'park', , 'voicemail'];", + " var first_module = (doc.flow || {}).module;", + " var second_module = (((doc.flow || {}).children || {})._ || {}).module;", + " var name = doc.name || ((doc.flow || {}).data || {}).name;", + " var id = ((doc.flow || {}).data || {}).id || ((doc.flow || {}).data || {}).owner_id;", + " if ((first_module == 'user' || first_module == 'device') && (second_module == 'voicemail' || !second_module) && id) {", + " emit('extension', {", + " 'id': id,", + " 'numbers': doc.numbers", + " });", + " } else if (name) {", + " emit((!doc.featurecode) ? 'custom' : 'featurecode', {", + " 'name': name,", + " 'first_module': first_module.replace('_', ' '),", + " 'numbers': doc.numbers", + " });", + " } else if (requireid.indexOf(first_module) >= 0 && id) {", + " emit((!doc.featurecode) ? 'custom' : 'featurecode', {", + " 'id': id,", + " 'name': name,", + " 'first_module': first_module,", + " 'numbers': doc.numbers", + " });", + " } else if (featurecodes.indexOf(first_module) >= 0) {", + " var action = ((doc.flow || {}).data || {}).action;", + " if (!action) return;", + " if (action == first_module) action = '';", + " else action = ' (' + action + ')';", + " emit((!doc.featurecode) ? 'custom' : 'featurecode', {", + " 'name': name || first_module.replace(/_/g, ' ') + action.replace(/_/g, ' '),", + " 'numbers': doc.numbers", + " });", + " }", + " }", + "}" + ] }, "names": { - "map": "function (doc) {\n if (doc.pvt_deleted || (doc.contact_list || {}).exclude) return;\n var named = ['menu', 'conference', 'directory', 'device', 'vmbox']; \n if (doc.pvt_type == 'user') {\n emit(null, {'id':doc._id, 'name': doc.first_name + ' ' + doc.last_name});\n } else if (named.indexOf(doc.pvt_type) >= 0) {\n emit(null, {'id':doc._id, 'name': doc.name});\n }\n}" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || (doc.contact_list || {}).exclude) return;", + " var named = ['menu', 'conference', 'directory', 'device', 'vmbox'];", + " if (doc.pvt_type == 'user') {", + " emit(null, {", + " 'id': doc._id,", + " 'name': doc.first_name + ' ' + doc.last_name", + " });", + " } else if (named.indexOf(doc.pvt_type) >= 0) {", + " emit(null, {", + " 'id': doc._id,", + " 'name': doc.name", + " });", + " }", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/devices.json b/core/kazoo_apps/priv/couchdb/account/devices.json index deb31916c4a..9cb600d4f2e 100644 --- a/core/kazoo_apps/priv/couchdb/account/devices.json +++ b/core/kazoo_apps/priv/couchdb/account/devices.json @@ -30,10 +30,9 @@ }, "listing_by_macaddress": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type != 'device' || doc.pvt_deleted) return;", - " if(doc.mac_address)", - " emit(doc.mac_address, null)", + " if (doc.mac_address) emit(doc.mac_address, null)", "}" ] }, @@ -42,21 +41,20 @@ "function(doc) {", " if (doc.pvt_type != 'device' || doc.pvt_deleted) return;", " var owners = {};", - " if (doc.owner_id)", - " owners[doc.owner_id] = true;", + " if (doc.owner_id) owners[doc.owner_id] = true;", " if (typeof doc.hotdesk == 'object' && typeof doc.hotdesk.users == 'object') {", - " var users = [], o = (doc.hotdesk || {}).users || {};", + " var users = [],", + " o = (doc.hotdesk || {}).users || {};", " for (var p in o)", - " if (o.hasOwnProperty(p))", - " users.push(p);", + " if (o.hasOwnProperty(p)) users.push(p);", " users.forEach(function(u) {", " owners[u] = true;", " });", " }", - " var owners_keys = [], o = owners || {};", + " var owners_keys = [],", + " o = owners || {};", " for (var p in o)", - " if (o.hasOwnProperty(p))", - " owners_keys.push(p);", + " if (o.hasOwnProperty(p)) owners_keys.push(p);", " owners_keys.forEach(function(os) {", " emit(os, {", " 'id': doc._id,", @@ -77,17 +75,16 @@ "function(doc) {", " if (doc.pvt_type != 'device' || doc.pvt_deleted) return;", " if (doc.provision && doc.provision.feature_keys)", - " for(var i in doc.provision.feature_keys) {", + " for (var i in doc.provision.feature_keys) {", " var key = doc.provision.feature_keys[i];", - " if(key.type == 'presence' || key.type == 'personal_parking')", - " emit(key.value, null);", + " if (key.type == 'presence' || key.type == 'personal_parking') emit(key.value, null);", " }", "}" ] }, "sip_credentials": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_deleted) return;", " if (doc.sip) {", " var sip = JSON.parse(JSON.stringify(doc.sip));", @@ -96,8 +93,7 @@ " emit(sip.username.toLowerCase(), sip);", " } else if (doc.pvt_type === 'sys_info') {", " for (var i in doc.servers) {", - " if (!doc.servers[i].auth || !doc.servers[i].auth.auth_method || doc.servers[i].auth.auth_method.toLowerCase() != \"password\")", - " continue;", + " if (!doc.servers[i].auth || !doc.servers[i].auth.auth_method || doc.servers[i].auth.auth_method.toLowerCase() != \"password\") continue;", " var auth = doc.servers[i].auth;", " emit(auth.auth_user.toLowerCase(), {", " 'password': auth.auth_password,", diff --git a/core/kazoo_apps/priv/couchdb/account/directories.json b/core/kazoo_apps/priv/couchdb/account/directories.json index 705637ffe38..28921f1423e 100644 --- a/core/kazoo_apps/priv/couchdb/account/directories.json +++ b/core/kazoo_apps/priv/couchdb/account/directories.json @@ -10,10 +10,26 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'directory' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'flags': doc.flags || []}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'directory' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'flags': doc.flags || []", + " });", + "}" + ] }, "users_listing": { - "map": "function(doc) { if ( doc.pvt_deleted || typeof doc.directories !== 'object' ) return; for ( directory_id in doc.directories ) { emit([directory_id, doc._id], doc.directories[directory_id]); }}" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || typeof doc.directories !== 'object') return;", + " for (directory_id in doc.directories) {", + " emit([directory_id, doc._id], doc.directories[directory_id]);", + " }", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/faxbox.json b/core/kazoo_apps/priv/couchdb/account/faxbox.json index 6031d0a95e7..e30f82dc90f 100644 --- a/core/kazoo_apps/priv/couchdb/account/faxbox.json +++ b/core/kazoo_apps/priv/couchdb/account/faxbox.json @@ -10,19 +10,60 @@ "language": "javascript", "views": { "cloud": { - "map": "function(doc) { if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.pvt_cloud_printer_id) return; emit(doc.pvt_cloud_printer_id, {'faxbox_id' : doc._id, 'account_id' : doc.pvt_account_id, 'cloud_printer_id': doc.pvt_cloud_printer_id, 'state': doc.pvt_cloud_state, 'xmpp_jid' : doc.pvt_cloud_xmpp_jid } ); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.pvt_cloud_printer_id) return;", + " emit(doc.pvt_cloud_printer_id, {", + " 'faxbox_id': doc._id,", + " 'account_id': doc.pvt_account_id,", + " 'cloud_printer_id': doc.pvt_cloud_printer_id,", + " 'state': doc.pvt_cloud_state,", + " 'xmpp_jid': doc.pvt_cloud_xmpp_jid", + " });", + "}" + ] }, "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'faxbox' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'created': doc.pvt_created, 'flags': doc.flags || []}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'faxbox' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'created': doc.pvt_created,", + " 'flags': doc.flags || []", + " });", + "}" + ] }, "email_address": { - "map": "function(doc) { if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.pvt_smtp_email_address ) return; emit(doc.pvt_smtp_email_address, doc.pvt_account_id); if(doc.custom_smtp_email_address) { emit(doc.custom_smtp_email_address, doc.pvt_account_id); }; }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.pvt_smtp_email_address) return;", + " emit(doc.pvt_smtp_email_address, doc.pvt_account_id);", + " if (doc.custom_smtp_email_address) {", + " emit(doc.custom_smtp_email_address, doc.pvt_account_id);", + " };", + "}" + ] }, "email_permissions": { - "map": "function(doc) { if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.smtp_permission_list || ! Array.isArray(doc.smtp_permission_list) ) return; doc.smtp_permission_list.forEach(function (tag){ if(tag != '') emit(tag.toLowerCase()); }); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.smtp_permission_list || !Array.isArray(doc.smtp_permission_list)) return;", + " doc.smtp_permission_list.forEach(function(tag) {", + " if (tag != '') emit(tag.toLowerCase());", + " });", + "}" + ] }, "list_by_ownerid": { - "map": "function(doc) { if ( doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.owner_id ) return; emit(doc.owner_id); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'faxbox' || doc.pvt_deleted || !doc.owner_id) return;", + " emit(doc.owner_id);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/faxes.json b/core/kazoo_apps/priv/couchdb/account/faxes.json index 3329903e1c9..66fd9d710a0 100644 --- a/core/kazoo_apps/priv/couchdb/account/faxes.json +++ b/core/kazoo_apps/priv/couchdb/account/faxes.json @@ -10,13 +10,46 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'fax' || doc.pvt_deleted) return; emit([doc.pvt_created, doc._id], {'id': doc._id, 'status': doc.pvt_job_status, 'to': doc.to_number, 'from': doc.from_number, 'created': doc.pvt_created}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted) return;", + " emit([doc.pvt_created, doc._id], {", + " 'id': doc._id,", + " 'status': doc.pvt_job_status,", + " 'to': doc.to_number,", + " 'from': doc.from_number,", + " 'created': doc.pvt_created", + " });", + "}" + ] }, "list_by_faxbox": { - "map": "function(doc) { if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.faxbox_id) return; emit([doc.faxbox_id, doc.pvt_created], {'id': doc._id, 'status': doc.pvt_job_status, 'to': doc.to_number, 'from': doc.from_number, 'created': doc.pvt_created}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.faxbox_id) return;", + " emit([doc.faxbox_id, doc.pvt_created], {", + " 'id': doc._id,", + " 'status': doc.pvt_job_status,", + " 'to': doc.to_number,", + " 'from': doc.from_number,", + " 'created': doc.pvt_created", + " });", + "}" + ] }, "list_by_ownerid": { - "map": "function(doc) { if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.owner_id) return; emit([doc.owner_id, doc.pvt_created], {'id': doc._id, 'status': doc.pvt_job_status, 'to': doc.to_number, 'from': doc.from_number, 'created': doc.pvt_created}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.owner_id) return;", + " emit([doc.owner_id, doc.pvt_created], {", + " 'id': doc._id,", + " 'status': doc.pvt_job_status,", + " 'to': doc.to_number,", + " 'from': doc.from_number,", + " 'created': doc.pvt_created", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/groups.json b/core/kazoo_apps/priv/couchdb/account/groups.json index ca0848666e8..1c81e617456 100644 --- a/core/kazoo_apps/priv/couchdb/account/groups.json +++ b/core/kazoo_apps/priv/couchdb/account/groups.json @@ -11,7 +11,7 @@ "views": { "crossbar_listing": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type != 'group' || doc.pvt_deleted) return;", " var features = [];", " if (doc.smartpbx) {", @@ -24,10 +24,10 @@ " if (doc.music_on_hold && doc.music_on_hold.media_id) {", " features.push('music_on_hold');", " }", - " var endpoints = 0, o = doc.endpoints || {};", + " var endpoints = 0,", + " o = doc.endpoints || {};", " for (var p in o)", - " if (o.hasOwnProperty(p))", - " endpoints++;", + " if (o.hasOwnProperty(p)) endpoints++;", " emit(doc._id, {", " 'id': doc._id,", " 'name': doc.name,", @@ -40,7 +40,7 @@ }, "crossbar_listing_by_user": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type != 'group' || doc.pvt_deleted) return;", " var features = [];", " if (doc.smartpbx) {", @@ -53,19 +53,18 @@ " if (doc.music_on_hold && doc.music_on_hold.media_id) {", " features.push('music_on_hold');", " }", - " var endpoints = 0, o = doc.endpoints || {};", + " var endpoints = 0,", + " o = doc.endpoints || {};", " for (var p in o)", - " if (o.hasOwnProperty(p))", - " endpoints++;", + " if (o.hasOwnProperty(p)) endpoints++;", " for (var id in doc.endpoints)", - " if (doc.endpoints[id].type === 'user')", - " emit(id, {", - " 'id': doc._id,", - " 'name': doc.name,", - " 'features': features,", - " 'endpoints': endpoints,", - " 'flags': doc.flags || []", - " });", + " if (doc.endpoints[id].type === 'user') emit(id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'features': features,", + " 'endpoints': endpoints,", + " 'flags': doc.flags || []", + " });", "}" ] } diff --git a/core/kazoo_apps/priv/couchdb/account/hotdesks.json b/core/kazoo_apps/priv/couchdb/account/hotdesks.json index ca18d98fdff..3f9744409e7 100644 --- a/core/kazoo_apps/priv/couchdb/account/hotdesks.json +++ b/core/kazoo_apps/priv/couchdb/account/hotdesks.json @@ -10,7 +10,17 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_deleted || !doc.hotdesk || !doc.hotdesk.users || doc.pvt_type != 'device') return; for (user_id in doc.hotdesk.users) {emit(user_id, {'device_id': doc._id, 'device_name': doc.name});} }" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || !doc.hotdesk || !doc.hotdesk.users || doc.pvt_type != 'device') return;", + " for (user_id in doc.hotdesk.users) {", + " emit(user_id, {", + " 'device_id': doc._id,", + " 'device_name': doc.name", + " });", + " }", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/lists.json b/core/kazoo_apps/priv/couchdb/account/lists.json index d635c969adf..369a16dc63c 100644 --- a/core/kazoo_apps/priv/couchdb/account/lists.json +++ b/core/kazoo_apps/priv/couchdb/account/lists.json @@ -12,8 +12,7 @@ "crossbar_listing": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'list' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'list' || doc.pvt_deleted) return;", " emit(doc._id, {", " 'id': doc._id,", " 'name': doc.name,", @@ -26,8 +25,7 @@ "entries": { "map": [ "function(doc) {", - " if (doc.pvt_deleted)", - " return;", + " if (doc.pvt_deleted) return;", " if (doc.pvt_type === 'list_entry') {", " emit(doc.list_id, {", " capture_group_key: doc.capture_group_key,", @@ -41,8 +39,7 @@ " })", " } else if (doc.pvt_type === 'list' && doc.entries) {", " for (var key in doc.entries) {", - " if (!doc.entries.hasOwnProperty(key))", - " continue;", + " if (!doc.entries.hasOwnProperty(key)) continue;", " emit(doc._id, {", " capture_group_key: key,", " capture_group_length: doc.length,", @@ -63,8 +60,7 @@ "match_prefix": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'list_entry' || doc.pvt_deleted || !(doc.number || doc.prefix))", - " return;", + " if (doc.pvt_type != 'list_entry' || doc.pvt_deleted || !(doc.number || doc.prefix)) return;", " emit(doc.number ? doc.number : doc.prefix, null);", "}" ] @@ -72,8 +68,7 @@ "match_prefix_in_list": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'list_entry' || doc.pvt_deleted || !(doc.number || doc.prefix))", - " return;", + " if (doc.pvt_type != 'list_entry' || doc.pvt_deleted || !(doc.number || doc.prefix)) return;", " emit([doc.list_id, doc.number ? doc.number : doc.prefix], null);", "}" ] @@ -81,8 +76,7 @@ "regexps_in_list": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'list_entry' || doc.pvt_deleted || !(doc.regexp || doc.pattern))", - " return;", + " if (doc.pvt_type != 'list_entry' || doc.pvt_deleted || !(doc.regexp || doc.pattern)) return;", " emit(doc.list_id, doc.regexp ? doc.regexp : doc.pattern);", "}" ] diff --git a/core/kazoo_apps/priv/couchdb/account/menus.json b/core/kazoo_apps/priv/couchdb/account/menus.json index 84b800eeaa1..4e71f552182 100644 --- a/core/kazoo_apps/priv/couchdb/account/menus.json +++ b/core/kazoo_apps/priv/couchdb/account/menus.json @@ -10,7 +10,16 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'menu' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'flags': doc.flags || []}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'menu' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'flags': doc.flags || []", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/message.json b/core/kazoo_apps/priv/couchdb/account/message.json index 2e39f70c51d..259a58cad6c 100644 --- a/core/kazoo_apps/priv/couchdb/account/message.json +++ b/core/kazoo_apps/priv/couchdb/account/message.json @@ -11,34 +11,35 @@ "views": { "crossbar_listing": { "map": [ - "function (doc) {", - " if (doc.pvt_type != 'textflow' || doc.pvt_deleted) return;", - " var featurecode = (!doc.featurecode) ? false : doc.featurecode;", - " var modules = [];", - " if (doc.flow)", - " var walkTree = (function recursiveWalkTree(flow) {", - " if (flow.module && (flow.data && flow.data.skip_module !== true))", - " modules.push(flow.module);", - " if (flow.children) {", - " var children = flow.children;", - " for (var key in children) {", - " if (!children.hasOwnProperty(key)) continue;", - " recursiveWalkTree(children[key]);", - " }", - " }", - " })(doc.flow);", - " var onlyUnique = function(value, index, self) { return self.indexOf(value) === index; };", - " modules = modules.filter(onlyUnique);", - " emit(doc._id, {'id': doc._id", - " ,'name': doc.name", - " ,'type': doc.type", - " ,'numbers': doc.numbers", - " ,'patterns': doc.patterns", - " ,'featurecode': featurecode", - " ,'owner_id': doc.owner_id", - " ,'group_id': doc.group_id", - " ,'modules': modules", - " });", + "function(doc) {", + " if (doc.pvt_type != 'textflow' || doc.pvt_deleted) return;", + " var featurecode = (!doc.featurecode) ? false : doc.featurecode;", + " var modules = [];", + " if (doc.flow) var walkTree = (function recursiveWalkTree(flow) {", + " if (flow.module && (flow.data && flow.data.skip_module !== true)) modules.push(flow.module);", + " if (flow.children) {", + " var children = flow.children;", + " for (var key in children) {", + " if (!children.hasOwnProperty(key)) continue;", + " recursiveWalkTree(children[key]);", + " }", + " }", + " })(doc.flow);", + " var onlyUnique = function(value, index, self) {", + " return self.indexOf(value) === index;", + " };", + " modules = modules.filter(onlyUnique);", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'type': doc.type,", + " 'numbers': doc.numbers,", + " 'patterns': doc.patterns,", + " 'featurecode': featurecode,", + " 'owner_id': doc.owner_id,", + " 'group_id': doc.group_id,", + " 'modules': modules", + " });", "}" ] }, @@ -46,22 +47,30 @@ "map": [ "function(doc) {", " if (doc.pvt_type != 'textflow' || doc.pvt_deleted) return;", - " for (var i in doc.numbers) emit(doc.numbers[i], {'name' : doc.name || doc._id} ); }" + " for (var i in doc.numbers) emit(doc.numbers[i], {", + " 'name': doc.name || doc._id", + " });", + "}" ] }, "listing_by_pattern": { "map": [ "function(doc) {", " if (doc.pvt_type != 'textflow' || doc.pvt_deleted) return;", - "for (var i in doc.patterns) emit(doc.patterns[i], {'name' : doc.name || doc._id}); }" + " for (var i in doc.patterns) emit(doc.patterns[i], {", + " 'name': doc.name || doc._id", + " });", + "}" ] }, "msisdn": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'textflow' || doc.pvt_deleted || (doc.flow.module != 'user' && doc.flow.module != 'device') ) return; ", - " for (var i in doc.numbers) ", - " if(doc.numbers[i].charAt(0) == '+') emit([doc.flow.module, doc.flow.data.id, doc.numbers[i] ], {'msisdn' : doc.numbers[i]}); ", + " if (doc.pvt_type != 'textflow' || doc.pvt_deleted || (doc.flow.module != 'user' && doc.flow.module != 'device')) return;", + " for (var i in doc.numbers)", + " if (doc.numbers[i].charAt(0) == '+') emit([doc.flow.module, doc.flow.data.id, doc.numbers[i]], {", + " 'msisdn': doc.numbers[i]", + " });", "}" ] } diff --git a/core/kazoo_apps/priv/couchdb/account/metaflows.json b/core/kazoo_apps/priv/couchdb/account/metaflows.json index a6b0b7dd5f7..8a283907377 100644 --- a/core/kazoo_apps/priv/couchdb/account/metaflows.json +++ b/core/kazoo_apps/priv/couchdb/account/metaflows.json @@ -10,7 +10,12 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (!doc.metaflows || doc.pvt_deleted) return; emit(doc._id, doc.metaflows); }" + "map": [ + "function(doc) {", + " if (!doc.metaflows || doc.pvt_deleted) return;", + " emit(doc._id, doc.metaflows);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/mobile.json b/core/kazoo_apps/priv/couchdb/account/mobile.json index 3343830ef91..924a7cdf273 100644 --- a/core/kazoo_apps/priv/couchdb/account/mobile.json +++ b/core/kazoo_apps/priv/couchdb/account/mobile.json @@ -10,7 +10,17 @@ "language": "javascript", "views": { "listing_by_mdn": { - "map": "function(doc) { if (doc.pvt_type != 'device' || doc.pvt_deleted || doc.device_type != 'mobile') return; var owner_id = doc.pvt_owner_id ? doc.pvt_owner_id : doc.owner_id; emit(doc.mobile.mdn, {'id': doc._id, 'owner_id' : owner_id, 'name': doc.name}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'device' || doc.pvt_deleted || doc.device_type != 'mobile') return;", + " var owner_id = doc.pvt_owner_id ? doc.pvt_owner_id : doc.owner_id;", + " emit(doc.mobile.mdn, {", + " 'id': doc._id,", + " 'owner_id': owner_id,", + " 'name': doc.name", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/notifications.json b/core/kazoo_apps/priv/couchdb/account/notifications.json index f3ead999de3..69d3e98ed0d 100644 --- a/core/kazoo_apps/priv/couchdb/account/notifications.json +++ b/core/kazoo_apps/priv/couchdb/account/notifications.json @@ -10,7 +10,19 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) {if (doc.pvt_type != 'notification' || doc.pvt_deleted) return; var id = doc._id.replace(\"notification.\", \"\"); emit(id, {'id': id, 'category':doc.category, 'friendly_name':doc.friendly_name, 'macros':doc.macros, 'enabled': doc.enabled});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'notification' || doc.pvt_deleted) return;", + " var id = doc._id.replace(\"notification.\", \"\");", + " emit(id, {", + " 'id': id,", + " 'category': doc.category,", + " 'friendly_name': doc.friendly_name,", + " 'macros': doc.macros,", + " 'enabled': doc.enabled", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/numbers.json b/core/kazoo_apps/priv/couchdb/account/numbers.json index d1b4e776997..783f74a7bb1 100644 --- a/core/kazoo_apps/priv/couchdb/account/numbers.json +++ b/core/kazoo_apps/priv/couchdb/account/numbers.json @@ -26,10 +26,20 @@ ] }, "list_by_number": { - "map": "function(doc) {if (doc.pvt_type != 'number' || doc.pvt_deleted) return;emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'number' || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] }, "list_reserved": { - "map": "function(doc) {if (doc.pvt_type != 'number' || doc.pvt_deleted || doc.pvt_state != 'reserved') return; emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'number' || doc.pvt_deleted || doc.pvt_state != 'reserved') return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/parking.json b/core/kazoo_apps/priv/couchdb/account/parking.json index 4ce79a73dcd..fbc3447fd4c 100644 --- a/core/kazoo_apps/priv/couchdb/account/parking.json +++ b/core/kazoo_apps/priv/couchdb/account/parking.json @@ -10,10 +10,20 @@ "language": "javascript", "views": { "parked_call": { - "map": "function(doc) { if(doc.pvt_type != 'parked_call' || !doc.slot || doc.pvt_deleted) return; emit(doc.slot[\"Call-ID\"], null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'parked_call' || !doc.slot || doc.pvt_deleted) return;", + " emit(doc.slot[\"Call-ID\"], null);", + "}" + ] }, "parked_calls": { - "map": "function(doc) { if(doc.pvt_type != 'parked_call' || !doc.slot || doc.pvt_deleted) return; emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'parked_call' || !doc.slot || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/phone_numbers.json b/core/kazoo_apps/priv/couchdb/account/phone_numbers.json index 2b8780e695e..695d79ba991 100644 --- a/core/kazoo_apps/priv/couchdb/account/phone_numbers.json +++ b/core/kazoo_apps/priv/couchdb/account/phone_numbers.json @@ -13,10 +13,10 @@ "map": [ "function(doc) {", " if (doc.pvt_type != 'number' || doc.pvt_deleted) return;", - " var features = [], o = doc.pvt_features || {};", + " var features = [],", + " o = doc.pvt_features || {};", " for (var p in o)", - " if (o.hasOwnProperty(p))", - " features.push(p);", + " if (o.hasOwnProperty(p)) features.push(p);", " emit(doc._id, {", " state: doc.pvt_state,", " features: features,", diff --git a/core/kazoo_apps/priv/couchdb/account/pivot.json b/core/kazoo_apps/priv/couchdb/account/pivot.json index 35b70b06753..4a36f70d201 100644 --- a/core/kazoo_apps/priv/couchdb/account/pivot.json +++ b/core/kazoo_apps/priv/couchdb/account/pivot.json @@ -10,13 +10,35 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if(doc.pvt_type != 'pivot' || doc.pvt_deleted) return; emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'pivot' || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] }, "debug_listing": { - "map": "function(doc) {if (doc.pvt_type != 'pivot_debug' || doc.pvt_deleted) return; emit([doc.call_id, doc.pvt_created], null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'pivot_debug' || doc.pvt_deleted) return;", + " emit([doc.call_id, doc.pvt_created], null);", + "}" + ] }, "first_iteration": { - "map": "function(doc) {if (doc.pvt_type != 'pivot_debug' || doc.pvt_deleted || doc.iteration != 1) return;emit(doc.call_id, {'call_id': doc.call_id,'created': doc.pvt_created,'uri': doc.uri,'status_code': doc.resp_status_code,'node': doc.pvt_node,'iteration': doc.iteration});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'pivot_debug' || doc.pvt_deleted || doc.iteration != 1) return;", + " emit(doc.call_id, {", + " 'call_id': doc.call_id,", + " 'created': doc.pvt_created,", + " 'uri': doc.uri,", + " 'status_code': doc.resp_status_code,", + " 'node': doc.pvt_node,", + " 'iteration': doc.iteration", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/rate_limits.json b/core/kazoo_apps/priv/couchdb/account/rate_limits.json index 5a082fe14de..31f884fab0e 100644 --- a/core/kazoo_apps/priv/couchdb/account/rate_limits.json +++ b/core/kazoo_apps/priv/couchdb/account/rate_limits.json @@ -10,10 +10,38 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) {if (doc.pvt_type != 'rate_limits' || doc.pvt_deleted) return;var emit_records = function(Name, Type, Limits) {for (SipMethod in Limits.per_minute) {emit([Name, SipMethod], {'type': Type,'per_minute': Limits.per_minute[SipMethod]})};for (SipMethod in Limits.per_second) {emit([Name, SipMethod], {'type': Type,'per_second': Limits.per_second[SipMethod]})};};if (doc.pvt_owner_type == 'account') {emit_records('device-default-rate-limits', 'device', doc.device);emit_records(doc.pvt_queryname, 'realm', doc.account);}if (doc.pvt_owner_type == 'device') emit_records(doc.pvt_queryname, 'device', doc);};" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'rate_limits' || doc.pvt_deleted) return;", + " var emit_records = function(Name, Type, Limits) {", + " for (SipMethod in Limits.per_minute) {", + " emit([Name, SipMethod], {", + " 'type': Type,", + " 'per_minute': Limits.per_minute[SipMethod]", + " })", + " };", + " for (SipMethod in Limits.per_second) {", + " emit([Name, SipMethod], {", + " 'type': Type,", + " 'per_second': Limits.per_second[SipMethod]", + " })", + " };", + " };", + " if (doc.pvt_owner_type == 'account') {", + " emit_records('device-default-rate-limits', 'device', doc.device);", + " emit_records(doc.pvt_queryname, 'realm', doc.account);", + " }", + " if (doc.pvt_owner_type == 'device') emit_records(doc.pvt_queryname, 'device', doc);", + "};" + ] }, "list_by_owner": { - "map": "function(doc) {if (doc.pvt_type != 'rate_limits' || doc.pvt_deleted) return; emit(doc.pvt_owner_id);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'rate_limits' || doc.pvt_deleted) return;", + " emit(doc.pvt_owner_id);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/resources.json b/core/kazoo_apps/priv/couchdb/account/resources.json index 669f128ae24..c2c25363a22 100644 --- a/core/kazoo_apps/priv/couchdb/account/resources.json +++ b/core/kazoo_apps/priv/couchdb/account/resources.json @@ -10,16 +10,53 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) {if (doc.pvt_type != 'resource' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id,'name': doc.name,'enabled': doc.enabled,'weight_cost': doc.weight_cost,'template_name': doc.template_name,'classifiers': doc.classifiers});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'enabled': doc.enabled,", + " 'weight_cost': doc.weight_cost,", + " 'template_name': doc.template_name,", + " 'classifiers': doc.classifiers", + " });", + "}" + ] }, "listing_active_by_rules": { - "map": "function(doc) { if (doc.pvt_type != 'resource' || ! doc.enabled || doc.pvt_deleted) return; for (var i in doc.rules) emit([doc.weight_cost, doc.rules[i]], {'id': doc._id, 'gateways': doc.gateways, 'caller_id_options': doc.caller_id_options, 'flags':doc.flags || []}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource' || !doc.enabled || doc.pvt_deleted) return;", + " for (var i in doc.rules) emit([doc.weight_cost, doc.rules[i]], {", + " 'id': doc._id,", + " 'gateways': doc.gateways,", + " 'caller_id_options': doc.caller_id_options,", + " 'flags': doc.flags || []", + " });", + "}" + ] }, "listing_by_id": { - "map": "function(doc) { if (doc.pvt_type != 'resource' || doc.pvt_deleted) return; emit(doc._id, doc.name); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource' || doc.pvt_deleted) return;", + " emit(doc._id, doc.name);", + "}" + ] }, "resource_templates": { - "map": "function(doc) { if (doc.pvt_type != 'resource_template' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'template_name': doc.template_name, 'classifiers': doc.classifiers}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_template' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'template_name': doc.template_name,", + " 'classifiers': doc.classifiers", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/search.json b/core/kazoo_apps/priv/couchdb/account/search.json index 4239f942ec6..030d5182f27 100644 --- a/core/kazoo_apps/priv/couchdb/account/search.json +++ b/core/kazoo_apps/priv/couchdb/account/search.json @@ -13,7 +13,8 @@ "map": [ "function(doc) {", " if (doc.pvt_deleted || !doc.pvt_type) return;", - " var actual_name = '', name = '';", + " var actual_name = '',", + " name = '';", " var obj = {};", " if (doc.hasOwnProperty('first_name') || doc.hasOwnProperty('last_name')) {", " obj.first_name = (doc.first_name || '').toLowerCase().replace(/[^a-z0-9]/g, '');", @@ -39,7 +40,8 @@ "map": [ "function(doc) {", " if (doc.pvt_deleted || !doc.pvt_type) return;", - " var actual_name = '', name = '';", + " var actual_name = '',", + " name = '';", " var name_obj = {};", " if (doc.hasOwnProperty('first_name') || doc.hasOwnProperty('last_name')) {", " name_obj.first_name = (doc.first_name || '').toLowerCase().replace(/[^a-z0-9]/g, '');", diff --git a/core/kazoo_apps/priv/couchdb/account/servers.json b/core/kazoo_apps/priv/couchdb/account/servers.json index b27c890e49f..67506a93a54 100644 --- a/core/kazoo_apps/priv/couchdb/account/servers.json +++ b/core/kazoo_apps/priv/couchdb/account/servers.json @@ -10,10 +10,27 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'server' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'hostname': doc.hostname, 'deploy_status': doc.pvt_deploy_status, 'roles': doc.roles, 'ip':doc.ip}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'server' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'hostname': doc.hostname,", + " 'deploy_status': doc.pvt_deploy_status,", + " 'roles': doc.roles,", + " 'ip': doc.ip", + " });", + "}" + ] }, "list_deployment_roles": { - "map": "function(doc) { if (doc.pvt_type != 'deployment_role' || doc.pvt_deleted) return; emit(doc._id, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'deployment_role' || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/service_plans.json b/core/kazoo_apps/priv/couchdb/account/service_plans.json index 59d59129a90..c6bb540d750 100644 --- a/core/kazoo_apps/priv/couchdb/account/service_plans.json +++ b/core/kazoo_apps/priv/couchdb/account/service_plans.json @@ -10,7 +10,17 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'service_plan' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'description': doc.description, 'category': doc.category}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'service_plan' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'description': doc.description,", + " 'category': doc.category", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/skels.json b/core/kazoo_apps/priv/couchdb/account/skels.json index e2dffac897b..7089b0148ee 100644 --- a/core/kazoo_apps/priv/couchdb/account/skels.json +++ b/core/kazoo_apps/priv/couchdb/account/skels.json @@ -10,7 +10,12 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if(doc.pvt_type != 'skel' || doc.pvt_deleted) return; emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'skel' || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/temporal_rules.json b/core/kazoo_apps/priv/couchdb/account/temporal_rules.json index bd679c48fdc..e2fd9972822 100644 --- a/core/kazoo_apps/priv/couchdb/account/temporal_rules.json +++ b/core/kazoo_apps/priv/couchdb/account/temporal_rules.json @@ -10,7 +10,17 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'temporal_rule' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'type': doc.type, 'flags': doc.flags || []}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'temporal_rule' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'type': doc.type,", + " 'flags': doc.flags || []", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/temporal_rules_sets.json b/core/kazoo_apps/priv/couchdb/account/temporal_rules_sets.json index 83d9d5493db..4a08378b1a7 100644 --- a/core/kazoo_apps/priv/couchdb/account/temporal_rules_sets.json +++ b/core/kazoo_apps/priv/couchdb/account/temporal_rules_sets.json @@ -10,7 +10,17 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'temporal_rule_set' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'rules': doc.temporal_rules, 'flags': doc.flags || []}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'temporal_rule_set' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'rules': doc.temporal_rules,", + " 'flags': doc.flags || []", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/trunkstore.json b/core/kazoo_apps/priv/couchdb/account/trunkstore.json index dcf41d9bd52..9988d8466d0 100644 --- a/core/kazoo_apps/priv/couchdb/account/trunkstore.json +++ b/core/kazoo_apps/priv/couchdb/account/trunkstore.json @@ -10,14 +10,73 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'sys_info' || doc.pvt_deleted) return; emit(doc._id, {'name': doc.name, 'servers':doc.servers}); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'sys_info' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'name': doc.name,", + " 'servers': doc.servers", + " });", + "}" + ], "reduce": "_count" }, "lookup_did": { - "map": "function(doc) { if(doc.pvt_type != 'sys_info' || doc.pvt_deleted ) return; var realm = doc.account.auth_realm; if(doc.servers) { var srvs = Iterator(doc.servers); for (var srv in srvs) { var auth_clone = JSON.parse(JSON.stringify(srv[1].auth)); auth_clone.auth_realm = realm; if (srv[1].enabled != false && srv[1].DIDs) { var DIDs = Iterator(srv[1].DIDs); for (var DID in DIDs) { emit(DID[0], { 'callerid_server': srv[1].callerid || '', 'callerid_account': doc.callerid || '', 'e911_callerid_server': srv[1].e911_callerid || '', 'e911_callerid_account': doc.e911_callerid || '', 'auth': auth_clone, 'DID_Opts': DID[1], 'inbound_format': srv[1].inbound_format || 'npan', 'server': srv[1].options, 'account': doc.account}); } } } } }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'sys_info' || doc.pvt_deleted) return;", + " var realm = doc.account.auth_realm;", + " if (doc.servers) {", + " var srvs = Iterator(doc.servers);", + " for (var srv in srvs) {", + " var auth_clone = JSON.parse(JSON.stringify(srv[1].auth));", + " auth_clone.auth_realm = realm;", + " if (srv[1].enabled != false && srv[1].DIDs) {", + " var DIDs = Iterator(srv[1].DIDs);", + " for (var DID in DIDs) {", + " emit(DID[0], {", + " 'callerid_server': srv[1].callerid || '',", + " 'callerid_account': doc.callerid || '',", + " 'e911_callerid_server': srv[1].e911_callerid || '',", + " 'e911_callerid_account': doc.e911_callerid || '',", + " 'auth': auth_clone,", + " 'DID_Opts': DID[1],", + " 'inbound_format': srv[1].inbound_format || 'npan',", + " 'server': srv[1].options,", + " 'account': doc.account", + " });", + " }", + " }", + " }", + " }", + "}" + ] }, "lookup_user_flags": { - "map": "function(doc) { if(doc.pvt_type != 'sys_info') return; var realm = doc.account.auth_realm; if(doc.call_restriction) { var call_restriction = JSON.parse(JSON.stringify(doc.call_restriction)) }; if(doc.servers) { var acct_clone = JSON.parse(JSON.stringify(doc.account)); var srvs = Iterator(doc.servers); for (var srv in srvs) { if (srv[1].auth) { var srv_clone = JSON.parse(JSON.stringify(srv[1])); srv_clone.auth.auth_realm = realm; emit([realm.toLowerCase(), srv_clone.auth.auth_user.toLowerCase()], {\"server\": srv_clone, \"account\": acct_clone, \"call_restriction\": call_restriction}); } } }}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'sys_info') return;", + " var realm = doc.account.auth_realm;", + " if (doc.call_restriction) {", + " var call_restriction = JSON.parse(JSON.stringify(doc.call_restriction))", + " };", + " if (doc.servers) {", + " var acct_clone = JSON.parse(JSON.stringify(doc.account));", + " var srvs = Iterator(doc.servers);", + " for (var srv in srvs) {", + " if (srv[1].auth) {", + " var srv_clone = JSON.parse(JSON.stringify(srv[1]));", + " srv_clone.auth.auth_realm = realm;", + " emit([realm.toLowerCase(), srv_clone.auth.auth_user.toLowerCase()], {", + " \"server\": srv_clone,", + " \"account\": acct_clone,", + " \"call_restriction\": call_restriction", + " });", + " }", + " }", + " }", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/account/users.json b/core/kazoo_apps/priv/couchdb/account/users.json index b4e67bcc6ad..6a90ae5dfa5 100644 --- a/core/kazoo_apps/priv/couchdb/account/users.json +++ b/core/kazoo_apps/priv/couchdb/account/users.json @@ -12,7 +12,7 @@ "creds_by_md5": { "map": [ "function(doc) {", - " if(!doc.pvt_md5_auth || (doc.pvt_type != 'user' || doc.pvt_deleted || !doc.enabled)) return;", + " if (!doc.pvt_md5_auth || (doc.pvt_type != 'user' || doc.pvt_deleted || !doc.enabled)) return;", " emit(doc.pvt_md5_auth, {", " 'owner_id': doc._id,", " 'account_id': doc.pvt_account_id", @@ -38,7 +38,7 @@ " var features = doc.features || [];", " if (doc.smartpbx)", " for (var feature in doc.smartpbx)", - " if(doc.smartpbx[feature].enabled) features.push(feature);", + " if (doc.smartpbx[feature].enabled) features.push(feature);", " if (doc.hotdesk && doc.hotdesk.enabled) features.push('hotdesk');", " if (doc.call_forward && doc.call_forward.enabled) features.push('call_forward');", " if (doc.call_forward && doc.call_forward.failover && !doc.call_forward.enabled) features.push('call_forward_failover');", @@ -69,8 +69,8 @@ "list_by_email": { "map": [ "function(doc) {", - " if(doc.pvt_type != 'user' || doc.pvt_deleted) return;", - " if(!doc.email || doc.email == '') return;", + " if (doc.pvt_type != 'user' || doc.pvt_deleted) return;", + " if (!doc.email || doc.email == '') return;", " emit(doc.email.toLowerCase(), null);", "}" ] @@ -78,7 +78,7 @@ "list_by_hotdesk_id": { "map": [ "function(doc) {", - " if(doc.pvt_type != 'user' || !doc.hotdesk.id || doc.pvt_deleted) return;", + " if (doc.pvt_type != 'user' || !doc.hotdesk.id || doc.pvt_deleted) return;", " emit(doc.hotdesk.id, null);", "}" ] @@ -89,7 +89,7 @@ " if (doc.pvt_type != 'user' || doc.pvt_deleted) return;", " var features = [];", " if (doc.smartpbx)", - " for (var feature in doc.smartpbx) ", + " for (var feature in doc.smartpbx)", " if (doc.smartpbx[feature].enabled) features.push(feature);", " if (doc.hotdesk && doc.hotdesk.enabled) features.push('hotdesk');", " if (doc.call_forward && doc.call_forward.enabled) features.push('call_forward');", @@ -117,7 +117,7 @@ "list_by_username": { "map": [ "function(doc) {", - " if(doc.pvt_type != 'user' || !doc.username || doc.pvt_deleted) return;", + " if (doc.pvt_type != 'user' || !doc.username || doc.pvt_deleted) return;", " emit(doc.username, null);", "}" ] diff --git a/core/kazoo_apps/priv/couchdb/account/vmboxes.json b/core/kazoo_apps/priv/couchdb/account/vmboxes.json index 165d85304c3..27934230d50 100644 --- a/core/kazoo_apps/priv/couchdb/account/vmboxes.json +++ b/core/kazoo_apps/priv/couchdb/account/vmboxes.json @@ -28,34 +28,31 @@ "legacy_msg_by_timestamp": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'vmbox' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'vmbox' || doc.pvt_deleted) return;", " var messages_count = doc.messages ? doc.messages.length || 0 : 0;", " if (messages_count) {", - " doc.messages.forEach(", - " function(Message) {", - " if (Message.migration_error)", - " return;", - " var timestamp = parseInt(Message.timestamp, 10);", - " emit(timestamp, {", - " source_id: doc._id,", - " owner_id: doc.owner_id,", - " mailbox: doc.mailbox,", - " box_timestamp: parseInt(doc.modified || doc.created, 10),", - " timezone: doc.timezone,", - " metadata: {", - " timestamp: timestamp,", - " from: Message.from,", - " to: Message.to,", - " caller_id_number: Message.caller_id_number,", - " caller_id_name: Message.caller_id_name,", - " call_id: Message.call_id,", - " folder: Message.folder,", - " length: Message.length,", - " media_id: Message.media_id", - " }", - " })", + " doc.messages.forEach(function(Message) {", + " if (Message.migration_error) return;", + " var timestamp = parseInt(Message.timestamp, 10);", + " emit(timestamp, {", + " source_id: doc._id,", + " owner_id: doc.owner_id,", + " mailbox: doc.mailbox,", + " box_timestamp: parseInt(doc.modified || doc.created, 10),", + " timezone: doc.timezone,", + " metadata: {", + " timestamp: timestamp,", + " from: Message.from,", + " to: Message.to,", + " caller_id_number: Message.caller_id_number,", + " caller_id_name: Message.caller_id_name,", + " call_id: Message.call_id,", + " folder: Message.folder,", + " length: Message.length,", + " media_id: Message.media_id", + " }", " })", + " })", " }", "}" ] diff --git a/core/kazoo_apps/priv/couchdb/account/whitelabel.json b/core/kazoo_apps/priv/couchdb/account/whitelabel.json index 479befb9772..3d21304b94e 100644 --- a/core/kazoo_apps/priv/couchdb/account/whitelabel.json +++ b/core/kazoo_apps/priv/couchdb/account/whitelabel.json @@ -10,7 +10,12 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'whitelabel' || doc.pvt_deleted) return; emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'whitelabel' || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/views/accounts.json b/core/kazoo_apps/priv/couchdb/views/accounts.json index 5d4aa0419b6..3eaaa6969b9 100644 --- a/core/kazoo_apps/priv/couchdb/views/accounts.json +++ b/core/kazoo_apps/priv/couchdb/views/accounts.json @@ -10,41 +10,160 @@ "language": "javascript", "views": { "list_by_whitelabel_domain": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted || !doc.pvt_whitelabel_domain) return; var domain = doc.pvt_whitelabel_domain.toLowerCase(); emit(domain, {'account_id': doc.pvt_account_id, 'account_db': doc.pvt_account_db}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted || !doc.pvt_whitelabel_domain) return;", + " var domain = doc.pvt_whitelabel_domain.toLowerCase();", + " emit(domain, {", + " 'account_id': doc.pvt_account_id,", + " 'account_db': doc.pvt_account_db", + " });", + "}" + ] }, "listing_by_api": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted) return; emit(doc.pvt_api_key, {'account_id': doc.pvt_account_id}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " emit(doc.pvt_api_key, {", + " 'account_id': doc.pvt_account_id", + " });", + "}" + ] }, "listing_by_children": { - "map": "function(doc) {if (doc.pvt_type != 'account' || doc.pvt_deleted) return;var tree = doc.pvt_tree.slice(0),parent = tree[tree.length - 1];emit([parent, doc.name], {'id': doc.pvt_account_id,'name': doc.name,'realm': doc.realm,'descendants_count': doc.descendants_count || 0, 'flags': doc.flags || []});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " var tree = doc.pvt_tree.slice(0),", + " parent = tree[tree.length - 1];", + " emit([parent, doc.name], {", + " 'id': doc.pvt_account_id,", + " 'name': doc.name,", + " 'realm': doc.realm,", + " 'descendants_count': doc.descendants_count || 0,", + " 'flags': doc.flags || []", + " });", + "}" + ] }, "listing_by_descendants": { - "map": "function(doc) {if (doc.pvt_type != 'account' || doc.pvt_deleted) return;var t = doc.pvt_tree.slice(0);for (var i in t) {emit([t[i], doc.name], {'id': doc.pvt_account_id,'name': doc.name,'realm': doc.realm,'tree': doc.pvt_tree, 'flags': doc.flags || []});}}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " var t = doc.pvt_tree.slice(0);", + " for (var i in t) {", + " emit([t[i], doc.name], {", + " 'id': doc.pvt_account_id,", + " 'name': doc.name,", + " 'realm': doc.realm,", + " 'tree': doc.pvt_tree,", + " 'flags': doc.flags || []", + " });", + " }", + "}" + ] }, "listing_by_descendants_count": { - "map": "function(doc) {if (doc.pvt_type != 'account' || doc.pvt_deleted) return;var t = doc.pvt_tree.slice(0);for (var i in t) {emit(t[i], 1);}}", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " var t = doc.pvt_tree.slice(0);", + " for (var i in t) {", + " emit(t[i], 1);", + " }", + "}" + ], "reduce": "_count" }, "listing_by_id": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted) return; var t = doc.pvt_tree.slice(0); t.push(doc.pvt_account_id); emit([doc.pvt_account_id, t], {'id': doc.pvt_account_id, 'name': doc.name, 'realm' : doc.realm, 'flags': doc.flags || []}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " var t = doc.pvt_tree.slice(0);", + " t.push(doc.pvt_account_id);", + " emit([doc.pvt_account_id, t], {", + " 'id': doc.pvt_account_id,", + " 'name': doc.name,", + " 'realm': doc.realm,", + " 'flags': doc.flags || []", + " });", + "}" + ] }, "listing_by_ip": { - "map": "function(doc) {if (doc.pvt_type != 'account' || doc.pvt_deleted || !doc.ips) return;for(var z in doc.ips) {emit(doc.ips[z].ip, {'owner_id': doc.ips[z].owner_id, 'account_id': doc.pvt_account_id});}}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted || !doc.ips) return;", + " for (var z in doc.ips) {", + " emit(doc.ips[z].ip, {", + " 'owner_id': doc.ips[z].owner_id,", + " 'account_id': doc.pvt_account_id", + " });", + " }", + "}" + ] }, "listing_by_name": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted) return; var name = doc.name.toLowerCase(); name = name.replace(/[^a-z0-9]/g, ''); emit(name, {'account_id': doc.pvt_account_id, 'account_db': doc.pvt_account_db}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " var name = doc.name.toLowerCase();", + " name = name.replace(/[^a-z0-9]/g, '');", + " emit(name, {", + " 'account_id': doc.pvt_account_id,", + " 'account_db': doc.pvt_account_db", + " });", + "}" + ] }, "listing_by_parent": { - "map": "function(doc) {if (doc.pvt_type != 'account' || doc.pvt_deleted) return;var tree = doc.pvt_tree.slice(0);emit(doc.pvt_account_id, {'id': tree[tree.length-1], 'flags': doc.flags || []});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " var tree = doc.pvt_tree.slice(0);", + " emit(doc.pvt_account_id, {", + " 'id': tree[tree.length - 1],", + " 'flags': doc.flags || []", + " });", + "}" + ] }, "listing_by_realm": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted) return; emit(doc.realm.toLowerCase(), {'account_id': doc.pvt_account_id, 'account_db': doc.pvt_account_db}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " emit(doc.realm.toLowerCase(), {", + " 'account_id': doc.pvt_account_id,", + " 'account_db': doc.pvt_account_db", + " });", + "}" + ] }, "listing_by_simple_id": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted) return; emit(doc._id, {'id': doc.pvt_account_id, 'name': doc.name, 'realm' : doc.realm}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted) return;", + " emit(doc._id, {", + " 'id': doc.pvt_account_id,", + " 'name': doc.name,", + " 'realm': doc.realm", + " });", + "}" + ] }, "listing_by_sso": { - "map": "function(doc) { if (doc.pvt_type != 'account' || doc.pvt_deleted || !doc.sso ) return; for(id in doc.sso.ids) {emit([doc.sso.provider, doc.sso.ids[id]], {'account_id': doc._id, 'account_db': doc.pvt_account_db});} }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'account' || doc.pvt_deleted || !doc.sso) return;", + " for (id in doc.sso.ids) {", + " emit([doc.sso.provider, doc.sso.ids[id]], {", + " 'account_id': doc._id,", + " 'account_db': doc.pvt_account_db", + " });", + " }", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/views/alerts.json b/core/kazoo_apps/priv/couchdb/views/alerts.json index 49d91c4154d..7bb9fc84654 100644 --- a/core/kazoo_apps/priv/couchdb/views/alerts.json +++ b/core/kazoo_apps/priv/couchdb/views/alerts.json @@ -10,7 +10,24 @@ "language": "javascript", "views": { "available": { - "map": "function(doc) {if (doc.pvt_type != 'alert' || doc.pvt_deleted) return;doc.to.forEach(function(to) {emit([to.type, to.value], {id: doc._id,title: doc.title,message: doc.message,category: doc.category,level: doc.level,metadata: doc.metadata,from: doc.from,expiration_date: doc.expiration_date,created: doc.pvt_created});});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'alert' || doc.pvt_deleted) return;", + " doc.to.forEach(function(to) {", + " emit([to.type, to.value], {", + " id: doc._id,", + " title: doc.title,", + " message: doc.message,", + " category: doc.category,", + " level: doc.level,", + " metadata: doc.metadata,", + " from: doc.from,", + " expiration_date: doc.expiration_date,", + " created: doc.pvt_created", + " });", + " });", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/views/maintenance.json b/core/kazoo_apps/priv/couchdb/views/maintenance.json index da0a14f8da1..f31c1b22ed2 100644 --- a/core/kazoo_apps/priv/couchdb/views/maintenance.json +++ b/core/kazoo_apps/priv/couchdb/views/maintenance.json @@ -25,23 +25,75 @@ "language": "javascript", "views": { "conflicts": { - "map": "function(doc) { if(doc._conflicts) { emit(doc._conflicts, null); } }" + "map": [ + "function(doc) {", + " if (doc._conflicts) {", + " emit(doc._conflicts, null);", + " }", + "}" + ] }, "listing_by_ctime": { - "map": "function(doc) { if(doc.pvt_deleted) return; emit(doc.pvt_created, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted) return;", + " emit(doc.pvt_created, null);", + "}" + ] }, "listing_by_mtime": { - "map": "function(doc) { if(doc.pvt_deleted) return; emit(doc.pvt_modified, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted) return;", + " emit(doc.pvt_modified, null);", + "}" + ] }, "listing_by_type": { - "map": "function(doc) { if(!doc.pvt_deleted) { if (doc.pvt_type == 'user') emit(doc.pvt_type, {'name': doc.first_name + ' ' + doc.last_name}); else if (doc.pvt_type == 'callflow') emit(doc.pvt_type, {'numbers': doc.numbers, 'patterns': doc.patterns}); else emit(doc.pvt_type, {'name': doc.name}); } }" + "map": [ + "function(doc) {", + " if (!doc.pvt_deleted) {", + " if (doc.pvt_type == 'user') emit(doc.pvt_type, {", + " 'name': doc.first_name + ' ' + doc.last_name", + " });", + " else if (doc.pvt_type == 'callflow') emit(doc.pvt_type, {", + " 'numbers': doc.numbers,", + " 'patterns': doc.patterns", + " });", + " else emit(doc.pvt_type, {", + " 'name': doc.name", + " });", + " }", + "}" + ] }, "reduced_by_type": { - "map": "function(doc) { if(!doc.pvt_deleted) { if (doc.pvt_type == 'user') emit(doc.pvt_type, {'name': doc.first_name + ' ' + doc.last_name}); else if (doc.pvt_type == 'callflow') emit(doc.pvt_type, {'numbers': doc.numbers, 'patterns': doc.patterns}); else emit(doc.pvt_type, {'name': doc.name}); } }", + "map": [ + "function(doc) {", + " if (!doc.pvt_deleted) {", + " if (doc.pvt_type == 'user') emit(doc.pvt_type, {", + " 'name': doc.first_name + ' ' + doc.last_name", + " });", + " else if (doc.pvt_type == 'callflow') emit(doc.pvt_type, {", + " 'numbers': doc.numbers,", + " 'patterns': doc.patterns", + " });", + " else emit(doc.pvt_type, {", + " 'name': doc.name", + " });", + " }", + "}" + ], "reduce": "_count" }, "soft_deletes": { - "map": "function(doc) { if(doc.pvt_deleted) { emit(doc.pvt_type, null); } }" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted) {", + " emit(doc.pvt_type, null);", + " }", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/views/rates.json b/core/kazoo_apps/priv/couchdb/views/rates.json index 733b008cc72..b24bd4a5c2d 100644 --- a/core/kazoo_apps/priv/couchdb/views/rates.json +++ b/core/kazoo_apps/priv/couchdb/views/rates.json @@ -12,7 +12,7 @@ "crossbar_listing": { "map": [ "function(doc) {", - " if ( doc.pvt_deleted || doc.pvt_type !== 'rate') return;", + " if (doc.pvt_deleted || doc.pvt_type !== 'rate') return;", " emit(doc._id, {", " 'name': doc.rate_name,", " 'cost': doc.rate_cost,", @@ -21,13 +21,17 @@ " 'surcharge': doc.rate_surcharge,", " 'carrier': doc.carrier,", " 'id': doc._id", - " }", - " );", + " });", "}" ] }, "lookup": { - "map": "function(doc) { if (doc.pvt_deleted || doc.pvt_type !== 'rate') return; emit(parseInt(doc.prefix), null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || doc.pvt_type !== 'rate') return;", + " emit(parseInt(doc.prefix), null);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/views/search.json b/core/kazoo_apps/priv/couchdb/views/search.json index 3faaf3106cf..327f5dc17b7 100644 --- a/core/kazoo_apps/priv/couchdb/views/search.json +++ b/core/kazoo_apps/priv/couchdb/views/search.json @@ -12,14 +12,13 @@ "search_by_id": { "map": [ "function(doc) {", - " if (doc.pvt_deleted)", - " return;", + " if (doc.pvt_deleted) return;", " for (i in doc.pvt_tree) {", " emit([doc.pvt_tree[i], doc.pvt_type, doc._id], {", " 'id': doc._id,", " 'descendants_count': doc.descendants_count || 0,", " 'name': doc.name,", - " 'realm' : doc.realm", + " 'realm': doc.realm", " });", " }", "}" @@ -28,13 +27,13 @@ "search_by_name": { "map": [ "function(doc) {", - " if (doc.pvt_deleted)", - " return;", + " if (doc.pvt_deleted) return;", " for (i in doc.pvt_tree) {", " var name = '';", " if (doc.pvt_alphanum_name) {", " name = doc.pvt_alphanum_name;", - " } if (doc.name) {", + " }", + " if (doc.name) {", " name = doc.name.toLowerCase().replace(/[^a-z0-9]/g, '');", " } else {", " return", @@ -43,7 +42,7 @@ " 'id': doc._id,", " 'descendants_count': doc.descendants_count || 0,", " 'name': doc.name,", - " 'realm' : doc.realm", + " 'realm': doc.realm", " });", " }", "}" @@ -52,14 +51,13 @@ "search_by_realm": { "map": [ "function(doc) {", - " if (doc.pvt_deleted)", - " return;", + " if (doc.pvt_deleted) return;", " for (i in doc.pvt_tree) {", " emit([doc.pvt_tree[i], doc.pvt_type, doc.realm.toLowerCase().replace(/[^a-z0-9]/g, '')], {", " 'id': doc._id,", " 'descendants_count': doc.descendants_count || 0,", " 'name': doc.name,", - " 'realm' : doc.realm", + " 'realm': doc.realm", " });", " }", "}" diff --git a/core/kazoo_apps/priv/couchdb/views/system_configs.json b/core/kazoo_apps/priv/couchdb/views/system_configs.json index e1ae084f10d..2a066fd3b20 100644 --- a/core/kazoo_apps/priv/couchdb/views/system_configs.json +++ b/core/kazoo_apps/priv/couchdb/views/system_configs.json @@ -10,7 +10,13 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_deleted) return; if(doc.pvt_type != 'config') return; emit(doc._id, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted) return;", + " if (doc.pvt_type != 'config') return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_apps/priv/couchdb/views/token_auth.json b/core/kazoo_apps/priv/couchdb/views/token_auth.json index 539538f3e97..28acce4b3e6 100644 --- a/core/kazoo_apps/priv/couchdb/views/token_auth.json +++ b/core/kazoo_apps/priv/couchdb/views/token_auth.json @@ -10,10 +10,18 @@ "language": "javascript", "views": { "listing_by_ctime": { - "map": "function(doc) { emit(doc.created || doc.pvt_created, doc._rev); }" + "map": [ + "function(doc) {", + " emit(doc.created || doc.pvt_created, doc._rev);", + "}" + ] }, "listing_by_mtime": { - "map": "function(doc) { emit(doc.modified || doc.pvt_modified, doc._rev); }" + "map": [ + "function(doc) {", + " emit(doc.modified || doc.pvt_modified, doc._rev);", + "}" + ] } } } diff --git a/core/kazoo_auth/priv/couchdb/views/apps.json b/core/kazoo_auth/priv/couchdb/views/apps.json index 5b4b1940dea..a5c270b11b4 100644 --- a/core/kazoo_auth/priv/couchdb/views/apps.json +++ b/core/kazoo_auth/priv/couchdb/views/apps.json @@ -10,10 +10,25 @@ "language": "javascript", "views": { "list_by_account": { - "map": "function(doc) { if (doc.pvt_type != 'app' || doc.pvt_deleted ) return; emit(doc.pvt_account_id, {id : doc._id, name : doc.name, description : doc.description, provider : doc.pvt_auth_provider}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'app' || doc.pvt_deleted) return;", + " emit(doc.pvt_account_id, {", + " id: doc._id,", + " name: doc.name,", + " description: doc.description,", + " provider: doc.pvt_auth_provider", + " });", + "}" + ] }, "list_by_provider": { - "map": "function(doc) { if (doc.pvt_type != 'app' || doc.pvt_deleted ) return; emit([doc.pvt_auth_provider,doc.pvt_account_id, doc._id]); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'app' || doc.pvt_deleted) return;", + " emit([doc.pvt_auth_provider, doc.pvt_account_id, doc._id]);", + "}" + ] } } } diff --git a/core/kazoo_auth/priv/couchdb/views/auth.json b/core/kazoo_auth/priv/couchdb/views/auth.json index bdbe341c8bf..1ab0c6377f7 100644 --- a/core/kazoo_auth/priv/couchdb/views/auth.json +++ b/core/kazoo_auth/priv/couchdb/views/auth.json @@ -12,17 +12,15 @@ "auth": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'user' || doc.pvt_deleted )", - " return;", - " emit([doc.pvt_app_provider_id, doc.pvt_app_id,doc.pvt_user_identity]);", + " if (doc.pvt_type != 'user' || doc.pvt_deleted) return;", + " emit([doc.pvt_app_provider_id, doc.pvt_app_id, doc.pvt_user_identity]);", "}" ] }, "auth_by_system_ids": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'user' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'user' || doc.pvt_deleted) return;", " emit([doc.pvt_app_id, doc.pvt_account_id, doc.pvt_owner_id], null);", "}" ] @@ -30,9 +28,8 @@ "issuer_domain": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'provider' || doc.pvt_deleted || !doc.issuer_domains || !Array.isArray(doc.issuer_domains))", - " return;", - " doc.issuer_domains.forEach(function (domain) {", + " if (doc.pvt_type != 'provider' || doc.pvt_deleted || !doc.issuer_domains || !Array.isArray(doc.issuer_domains)) return;", + " doc.issuer_domains.forEach(function(domain) {", " emit(domain.toLowerCase());", " });", "}" @@ -41,8 +38,7 @@ "list_apps_by_id": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'app' || doc.pvt_deleted )", - " return;", + " if (doc.pvt_type != 'app' || doc.pvt_deleted) return;", " emit(doc.pvt_auth_provider, doc._id);", "}" ] @@ -50,8 +46,7 @@ "list_users_by_id": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'user' || doc.pvt_deleted )", - " return;", + " if (doc.pvt_type != 'user' || doc.pvt_deleted) return;", " emit(doc.pvt_user_identity);", "}" ] diff --git a/core/kazoo_auth/priv/couchdb/views/providers.json b/core/kazoo_auth/priv/couchdb/views/providers.json index 859be809123..d8ba1187343 100644 --- a/core/kazoo_auth/priv/couchdb/views/providers.json +++ b/core/kazoo_auth/priv/couchdb/views/providers.json @@ -12,9 +12,10 @@ "list_by_account_id": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'app' || doc.pvt_deleted )", - " return;", - " emit([doc.pvt_account_id, doc.pvt_auth_provider], {_id : doc.pvt_auth_provider});", + " if (doc.pvt_type != 'app' || doc.pvt_deleted) return;", + " emit([doc.pvt_account_id, doc.pvt_auth_provider], {", + " _id: doc.pvt_auth_provider", + " });", "}" ], "reduce": "_count" @@ -22,10 +23,9 @@ "list_by_type": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'provider' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'provider' || doc.pvt_deleted) return;", " emit([doc.pvt_provider_type, doc._id], {", - " 'id' : doc._id,", + " 'id': doc._id,", " 'enabled': doc.enabled,", " 'name': doc.name,", " 'provider_name': doc.provider_name,", diff --git a/core/kazoo_auth/priv/couchdb/views/users.json b/core/kazoo_auth/priv/couchdb/views/users.json index a6d91ffd109..8533aa8babd 100644 --- a/core/kazoo_auth/priv/couchdb/views/users.json +++ b/core/kazoo_auth/priv/couchdb/views/users.json @@ -10,7 +10,18 @@ "language": "javascript", "views": { "list_linked_users": { - "map": "function(doc) {if (doc.pvt_type != 'user' || doc.pvt_deleted) return; emit([doc.pvt_account_id, doc.pvt_owner_id], {id : doc._id, app : doc.pvt_app_id, provider : doc.pvt_app_provider_id, scopes : doc.scopes, email : doc.email});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'user' || doc.pvt_deleted) return;", + " emit([doc.pvt_account_id, doc.pvt_owner_id], {", + " id: doc._id,", + " app: doc.pvt_app_id,", + " provider: doc.pvt_app_provider_id,", + " scopes: doc.scopes,", + " email: doc.email", + " });", + "}" + ] } } } diff --git a/core/kazoo_data/priv/couchdb/views/storage.json b/core/kazoo_data/priv/couchdb/views/storage.json index 22a9155fbe7..037c5af377b 100644 --- a/core/kazoo_data/priv/couchdb/views/storage.json +++ b/core/kazoo_data/priv/couchdb/views/storage.json @@ -10,19 +10,46 @@ "language": "javascript", "views": { "accounts": { - "map": "function(doc) {if (doc.pvt_type != 'storage' || doc.pvt_deleted) return; if(doc._id != doc.pvt_account_id) return; emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'storage' || doc.pvt_deleted) return;", + " if (doc._id != doc.pvt_account_id) return;", + " emit(doc._id, null);", + "}" + ] }, "crossbar_listing": { - "map": "function(doc) {if (doc.pvt_type != 'storage_plan' || doc.pvt_deleted) return; emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'storage_plan' || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] }, "plans_by_account": { - "map": "function(doc) { if (doc.pvt_type != 'storage_plan' || doc.pvt_deleted || doc.pvt_system_plan) return; emit([doc.pvt_account_id, doc._id], null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'storage_plan' || doc.pvt_deleted || doc.pvt_system_plan) return;", + " emit([doc.pvt_account_id, doc._id], null);", + "}" + ] }, "storage_by_account": { - "map": "function(doc) { if (doc.pvt_type != 'storage' || doc.pvt_deleted || doc.pvt_system_plan) return; if(doc._id == doc.pvt_account_id) return; emit(doc.pvt_account_id, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'storage' || doc.pvt_deleted || doc.pvt_system_plan) return;", + " if (doc._id == doc.pvt_account_id) return;", + " emit(doc.pvt_account_id, null);", + "}" + ] }, "system_plans": { - "map": "function(doc) { if (doc.pvt_type != 'storage_plan' || doc.pvt_deleted || !doc.pvt_system_plan) return; emit(doc._id, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'storage_plan' || doc.pvt_deleted || !doc.pvt_system_plan) return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_data/priv/couchdb/views/views.json b/core/kazoo_data/priv/couchdb/views/views.json index 55f035b8270..1cddd12a7a8 100644 --- a/core/kazoo_data/priv/couchdb/views/views.json +++ b/core/kazoo_data/priv/couchdb/views/views.json @@ -15,19 +15,19 @@ " if (doc.pvt_type != 'view_definition' || doc.pvt_deleted) return;", " if (!doc.kazoo || !doc.kazoo.view_map) return;", " for (i in doc.kazoo.view_map) {", - " var map = doc.kazoo.view_map[i];", - " viewname = doc.view_definition._id.split('/').pop();", - " viewtype = '';", - " if (map.classification) {", - " viewtype = map.classification;", - " }", - " if (map.database) {", - " viewtype = map.database;", - " }", - " for (j in doc.view_definition.views) {", - " var v = doc.view_definition.views[j];", - " emit([viewtype, viewname+'/'+j], null);", - " }", + " var map = doc.kazoo.view_map[i];", + " viewname = doc.view_definition._id.split('/').pop();", + " viewtype = '';", + " if (map.classification) {", + " viewtype = map.classification;", + " }", + " if (map.database) {", + " viewtype = map.database;", + " }", + " for (j in doc.view_definition.views) {", + " var v = doc.view_definition.views[j];", + " emit([viewtype, viewname + '/' + j], null);", + " }", " }", "}" ] diff --git a/core/kazoo_data/src/kz_datamgr.erl b/core/kazoo_data/src/kz_datamgr.erl index eb1cf27a2f5..c6ff71e61d9 100644 --- a/core/kazoo_data/src/kz_datamgr.erl +++ b/core/kazoo_data/src/kz_datamgr.erl @@ -270,15 +270,29 @@ should_update(_, _, {'error', _}) -> %%------------------------------------------------------------------------------ -spec maybe_adapt_multilines(kz_json:object()) -> kz_json:object(). maybe_adapt_multilines(JObj) -> - case kz_json:get_json_value(<<"views">>, JObj) of - 'undefined' -> JObj; - Views -> - NewViews = - [{View, kz_json:foldl(fun inline_js_fun/3, kz_json:new(), Pairs)} - || {View, Pairs} <- kz_json:to_proplist(Views) - ], - kz_json:set_value(<<"views">>, kz_json:from_list(NewViews), JObj) - end. + kz_json:map(fun maybe_adapt_multilines/2, JObj). + +-spec maybe_adapt_multilines(kz_json:key(), kz_json:json_term()) -> + {kz_json:key(), kz_json:json_term()}. +maybe_adapt_multilines(Key, JObj) + when Key =:= <<"filters">> + orelse Key =:= <<"lists">> + orelse Key =:= <<"shows">> + orelse Key =:= <<"updates">> -> + Prop = kz_json:foldl(fun inline_js_fun/3, kz_json:new(), JObj), + {Key, Prop}; +maybe_adapt_multilines(<<"views">> = Key, JObj) -> + NewViews = + [{View, kz_json:foldl(fun inline_js_fun/3, kz_json:new(), Pairs)} + || {View, Pairs} <- kz_json:to_proplist(JObj) + ], + {Key, kz_json:from_list(NewViews)}; +maybe_adapt_multilines(<<"rewrites">> = Key, Code=[<<"function", _/binary>>|_]) -> + {Key, iolist_to_binary(Code)}; +maybe_adapt_multilines(<<"validate_doc_update">> = Key, Code=[<<"function", _/binary>>|_]) -> + {Key, iolist_to_binary(Code)}; +maybe_adapt_multilines(Key, Value) -> + {Key, Value}. -spec inline_js_fun(kz_term:ne_binary(), kz_term:ne_binaries() | kz_json:json_term(), kz_json:object()) -> kz_json:object(). diff --git a/core/kazoo_ips/priv/couchdb/views/dedicated_ips.json b/core/kazoo_ips/priv/couchdb/views/dedicated_ips.json index c079c81e54d..298a9a2b9d9 100644 --- a/core/kazoo_ips/priv/couchdb/views/dedicated_ips.json +++ b/core/kazoo_ips/priv/couchdb/views/dedicated_ips.json @@ -10,21 +10,66 @@ "language": "javascript", "views": { "assigned_to_listing": { - "map": "function(doc) { if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted || doc.pvt_status != 'assigned') return; emit(doc.pvt_assigned_to, {'ip': doc._id, 'zone': doc.pvt_zone}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted || doc.pvt_status != 'assigned') return;", + " emit(doc.pvt_assigned_to, {", + " 'ip': doc._id,", + " 'zone': doc.pvt_zone", + " });", + "}" + ] }, "available_listing": { - "map": "function(doc) { if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted || doc.pvt_status != 'available') return; emit(doc.pvt_zone, {'ip': doc._id, 'zone': doc.pvt_zone}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted || doc.pvt_status != 'available') return;", + " emit(doc.pvt_zone, {", + " 'ip': doc._id,", + " 'zone': doc.pvt_zone", + " });", + "}" + ] }, "host_listing": { - "map": "function(doc) { if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted) return; emit(doc.pvt_host, null); }", - "reduce": "function(keys, values) { return true; }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted) return;", + " emit(doc.pvt_host, null);", + "}" + ], + "reduce": [ + "function(keys, values) {", + " return true;", + "}" + ] }, "summary_listing": { - "map": "function(doc) { if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted) return; emit(doc.pvt_host, {'ip': doc._id, 'zone': doc.pvt_zone, 'host': doc.pvt_host, 'status': doc.pvt_status, 'assigned_to': doc.pvt_assigned_to || '' }); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted) return;", + " emit(doc.pvt_host, {", + " 'ip': doc._id,", + " 'zone': doc.pvt_zone,", + " 'host': doc.pvt_host,", + " 'status': doc.pvt_status,", + " 'assigned_to': doc.pvt_assigned_to || ''", + " });", + "}" + ] }, "zone_listing": { - "map": "function(doc) { if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted) return; emit(doc.pvt_zone, null); }", - "reduce": "function(keys, values) { return true; }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'dedicated_ip' || doc.pvt_deleted) return;", + " emit(doc.pvt_zone, null);", + "}" + ], + "reduce": [ + "function(keys, values) {", + " return true;", + "}" + ] } } } diff --git a/core/kazoo_media/priv/couchdb/views/media.json b/core/kazoo_media/priv/couchdb/views/media.json index 02ec5ced01e..60306be5ee0 100644 --- a/core/kazoo_media/priv/couchdb/views/media.json +++ b/core/kazoo_media/priv/couchdb/views/media.json @@ -13,21 +13,87 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'media' || doc.pvt_deleted) return; var l = doc.language || ''; var is_prompt = false; if(doc.prompt_id) {is_prompt = true;} emit(doc._id, {'id': doc._id, 'name': doc.name, 'media_type': doc.media_type, 'media_source': doc.media_source, 'language':l.toLowerCase(), 'is_prompt': is_prompt}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'media' || doc.pvt_deleted) return;", + " var l = doc.language || '';", + " var is_prompt = false;", + " if (doc.prompt_id) {", + " is_prompt = true;", + " }", + " emit(doc._id, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'media_type': doc.media_type,", + " 'media_source': doc.media_source,", + " 'language': l.toLowerCase(),", + " 'is_prompt': is_prompt", + " });", + "}" + ] }, "listing_by_language": { - "map": "function(doc) { if (doc.pvt_type != 'media' || doc.pvt_deleted) return; var l = doc.language || ''; var is_prompt = false; if(doc.prompt_id) {is_prompt = true;} emit([l.toLowerCase(), doc.prompt_id || doc.name], {'is_prompt': is_prompt}); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'media' || doc.pvt_deleted) return;", + " var l = doc.language || '';", + " var is_prompt = false;", + " if (doc.prompt_id) {", + " is_prompt = true;", + " }", + " emit([l.toLowerCase(), doc.prompt_id || doc.name], {", + " 'is_prompt': is_prompt", + " });", + "}" + ], "reduce": "_count" }, "listing_by_name": { - "map": "function(doc) { if (doc.pvt_type != 'media' || doc.pvt_deleted) return; var is_prompt = false; if(doc.prompt_id) {is_prompt = true;} emit(doc.name, {'id': doc._id, 'name': doc.name, 'media_type': doc.media_type, 'is_prompt': is_prompt}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'media' || doc.pvt_deleted) return;", + " var is_prompt = false;", + " if (doc.prompt_id) {", + " is_prompt = true;", + " }", + " emit(doc.name, {", + " 'id': doc._id,", + " 'name': doc.name,", + " 'media_type': doc.media_type,", + " 'is_prompt': is_prompt", + " });", + "}" + ] }, "listing_by_prompt": { - "map": "function(doc) { if (doc.pvt_type != 'media' || doc.pvt_deleted || !doc.prompt_id) return; var l = doc.language || ''; var is_prompt = false; if(doc.prompt_id) {is_prompt = true;} emit([doc.prompt_id, l.toLowerCase()], {'id': doc._id, 'prompt_id': doc.prompt_id, 'langauge':l.toLowerCase(), 'is_prompt': is_prompt});}", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'media' || doc.pvt_deleted || !doc.prompt_id) return;", + " var l = doc.language || '';", + " var is_prompt = false;", + " if (doc.prompt_id) {", + " is_prompt = true;", + " }", + " emit([doc.prompt_id, l.toLowerCase()], {", + " 'id': doc._id,", + " 'prompt_id': doc.prompt_id,", + " 'langauge': l.toLowerCase(),", + " 'is_prompt': is_prompt", + " });", + "}" + ], "reduce": "_count" }, "listing_private_media": { - "map": "function(doc) { if (doc.pvt_type != 'private_media' || doc.pvt_deleted) return; emit([doc.media_type, doc._id], {'name': doc.name, 'media_type': doc.media_type}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'private_media' || doc.pvt_deleted) return;", + " emit([doc.media_type, doc._id], {", + " 'name': doc.name,", + " 'media_type': doc.media_type", + " });", + "}" + ] } } } diff --git a/core/kazoo_modb/priv/couchdb/views/allotments.json b/core/kazoo_modb/priv/couchdb/views/allotments.json index 7ab498b8c84..9a6fb42e4f2 100644 --- a/core/kazoo_modb/priv/couchdb/views/allotments.json +++ b/core/kazoo_modb/priv/couchdb/views/allotments.json @@ -10,11 +10,21 @@ "language": "javascript", "views": { "consumed": { - "map": "function (doc) { if (doc.pvt_type != 'allotment_consumption' || doc.pvt_deleted) return; emit([doc.classification, doc.pvt_created], doc.seconds); }", + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'allotment_consumption' || doc.pvt_deleted) return;", + " emit([doc.classification, doc.pvt_created], doc.seconds);", + "}" + ], "reduce": "_sum" }, "consumed_by_callid": { - "map": "function (doc) { if (doc.pvt_type != 'allotment_consumption' || doc.pvt_deleted) return; emit(doc.call_id, doc.seconds);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'allotment_consumption' || doc.pvt_deleted) return;", + " emit(doc.call_id, doc.seconds);", + "}" + ] } } } diff --git a/core/kazoo_modb/priv/couchdb/views/auth.json b/core/kazoo_modb/priv/couchdb/views/auth.json index 296aef9540c..d9ac4ffe00a 100644 --- a/core/kazoo_modb/priv/couchdb/views/auth.json +++ b/core/kazoo_modb/priv/couchdb/views/auth.json @@ -12,8 +12,7 @@ "login_attempt_by_auth_module": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'login_attempt' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'login_attempt' || doc.pvt_deleted) return;", " emit([doc.auth_module, doc.pvt_created], {", " 'id': doc._id,", " 'auth_type': doc.auth_type,", @@ -29,8 +28,7 @@ "login_attempt_by_auth_type": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'login_attempt' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'login_attempt' || doc.pvt_deleted) return;", " emit([doc.auth_type, doc.pvt_created], {", " 'id': doc._id,", " 'auth_type': doc.auth_type,", @@ -46,8 +44,7 @@ "login_attempt_by_status": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'login_attempt' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'login_attempt' || doc.pvt_deleted) return;", " emit([doc.status, doc.pvt_created], {", " 'id': doc._id,", " 'auth_type': doc.auth_type,", @@ -63,8 +60,7 @@ "login_attempt_by_time": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'login_attempt' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'login_attempt' || doc.pvt_deleted) return;", " emit(doc.pvt_created, {", " 'id': doc._id,", " 'auth_type': doc.auth_type,", diff --git a/core/kazoo_modb/priv/couchdb/views/cdrs.json b/core/kazoo_modb/priv/couchdb/views/cdrs.json index f82b8d1b00c..4d0caeaffea 100644 --- a/core/kazoo_modb/priv/couchdb/views/cdrs.json +++ b/core/kazoo_modb/priv/couchdb/views/cdrs.json @@ -9,102 +9,127 @@ }, "language": "javascript", "lists": { - "format_summary": "function() { var row, results = {'inbound': {}, 'outbound': {}}; while(row = getRow()){ var value = row.value; if(!results[value.direction][value.domain]) results[value.direction][value.domain] = {}; if(!results[value.direction][value.domain][value.classifier]) results[value.direction][value.domain][value.classifier] = {'total': 0}; results[value.direction][value.domain][value.classifier]['total'] += value.billable_seconds; if(value.rate_name) { if(!results[value.direction][value.domain][value.classifier][value.rate_name]) results[value.direction][value.domain][value.classifier][value.rate_name] = 0; results[value.direction][value.domain][value.classifier][value.rate_name] += value.billable_seconds; }} return JSON.stringify({'total_rows':1,'offset':0,'rows':[results]});}" + "format_summary": [ + "function() {", + " var row, results = {", + " 'inbound': {},", + " 'outbound': {}", + " };", + " while (row = getRow()) {", + " var value = row.value;", + " if (!results[value.direction][value.domain]) results[value.direction][value.domain] = {};", + " if (!results[value.direction][value.domain][value.classifier]) results[value.direction][value.domain][value.classifier] = {", + " 'total': 0", + " };", + " results[value.direction][value.domain][value.classifier]['total'] += value.billable_seconds;", + " if (value.rate_name) {", + " if (!results[value.direction][value.domain][value.classifier][value.rate_name]) results[value.direction][value.domain][value.classifier][value.rate_name] = 0;", + " results[value.direction][value.domain][value.classifier][value.rate_name] += value.billable_seconds;", + " }", + " }", + " return JSON.stringify({", + " 'total_rows': 1,", + " 'offset': 0,", + " 'rows': [results]", + " });", + "}" + ] }, "views": { "crossbar_listing": { "map": [ "function(doc) {", - " if (doc.pvt_deleted || doc.pvt_type != 'cdr') return;", - " emit([doc.pvt_created, doc._id], {", - " id: doc._id,", - " call_id: doc.call_id,", - " caller_id_name: doc.caller_id_name,", - " caller_id_number: doc.caller_id_number,", - " callee_id_name: doc.callee_id_name,", - " callee_id_number: doc.callee_id_number,", - " duration_seconds: doc.duration_seconds,", - " interaction_id: doc.interaction_id,", - " billing_seconds: doc.billing_seconds,", - " timestamp: doc.timestamp,", - " hangup_cause: doc.hangup_cause,", - " other_leg_call_id: doc.other_leg_call_id,", - " owner_id: doc.custom_channel_vars.owner_id,", - " to: doc.to_uri,", - " from: doc.from_uri,", - " inception: doc.custom_channel_vars.inception,", - " direction: doc.call_direction,", - " request: doc.request,", - " authorizing_id: doc.custom_channel_vars.authorizing_id,", - " media_recordings: doc.custom_channel_vars.media_recordings", - " });", + " if (doc.pvt_deleted || doc.pvt_type != 'cdr') return;", + " emit([doc.pvt_created, doc._id], {", + " id: doc._id,", + " call_id: doc.call_id,", + " caller_id_name: doc.caller_id_name,", + " caller_id_number: doc.caller_id_number,", + " callee_id_name: doc.callee_id_name,", + " callee_id_number: doc.callee_id_number,", + " duration_seconds: doc.duration_seconds,", + " interaction_id: doc.interaction_id,", + " billing_seconds: doc.billing_seconds,", + " timestamp: doc.timestamp,", + " hangup_cause: doc.hangup_cause,", + " other_leg_call_id: doc.other_leg_call_id,", + " owner_id: doc.custom_channel_vars.owner_id,", + " to: doc.to_uri,", + " from: doc.from_uri,", + " inception: doc.custom_channel_vars.inception,", + " direction: doc.call_direction,", + " request: doc.request,", + " authorizing_id: doc.custom_channel_vars.authorizing_id,", + " media_recordings: doc.custom_channel_vars.media_recordings", + " });", "}" ] }, "listing_by_owner": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'cdr' || doc.pvt_deleted || !doc.custom_channel_vars || !doc.custom_channel_vars.owner_id) return;", - " emit([doc.custom_channel_vars.owner_id, doc.pvt_created, doc._id], {", - " 'id': doc._id,", - " 'call_id': doc.call_id,", - " 'caller_id_name': doc.caller_id_name,", - " 'caller_id_number': doc.caller_id_number,", - " 'callee_id_name': doc.callee_id_name,", - " 'callee_id_number': doc.callee_id_number,", - " 'duration_seconds': doc.duration_seconds,", - " 'billing_seconds': doc.billing_seconds,", - " 'timestamp': doc.timestamp,", - " 'hangup_cause': doc.hangup_cause,", - " 'other_leg_call_id': doc.other_leg_call_id,", - " 'call_direction': doc.call_direction,", - " 'to': doc.to_uri,", - " 'from': doc.from_uri,", - " 'inception': doc.custom_channel_vars.inception", - " })", + " if (doc.pvt_type != 'cdr' || doc.pvt_deleted || !doc.custom_channel_vars || !doc.custom_channel_vars.owner_id) return;", + " emit([doc.custom_channel_vars.owner_id, doc.pvt_created, doc._id], {", + " 'id': doc._id,", + " 'call_id': doc.call_id,", + " 'caller_id_name': doc.caller_id_name,", + " 'caller_id_number': doc.caller_id_number,", + " 'callee_id_name': doc.callee_id_name,", + " 'callee_id_number': doc.callee_id_number,", + " 'duration_seconds': doc.duration_seconds,", + " 'billing_seconds': doc.billing_seconds,", + " 'timestamp': doc.timestamp,", + " 'hangup_cause': doc.hangup_cause,", + " 'other_leg_call_id': doc.other_leg_call_id,", + " 'call_direction': doc.call_direction,", + " 'to': doc.to_uri,", + " 'from': doc.from_uri,", + " 'inception': doc.custom_channel_vars.inception", + " })", "}" ] }, "summarize_cdrs": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'cdr' || doc.pvt_deleted || !doc.custom_channel_vars || doc.channel_name.indexOf('loopback') !== -1 || (doc.call_direction == 'inbound' && doc.custom_channel_vars.authorizing_id) || (doc.call_direction == 'outbound' && !doc.custom_channel_vars.resource_id)) return;", - " if (doc.call_direction == 'inbound') {", - " var domain = doc.from.substr(doc.from.indexOf('@') + 1);", - " } else {", - " var domain = doc.to.substr(doc.to.indexOf('@') + 1);", - " }", - " var number = doc.to.substr(0, doc.to.indexOf('@'));", - " if (number.match(/^\\+1((?:800|888|877|866|855)\\d{7})$/)) {", - " var classifier = 'tollfree_us';", - " } else if (number.match(/^\\+1(900\\d{7})$/)) {", - " var classifier = 'toll_us';", - " } else if (number.match(/^(911|933)$/)) {", - " var classifier = 'emergency';", - " } else if (number.match(/^\\+?1((?:684|264|268|242|246|441|284|345|767|809|829|849|473|671|876|664|670|787|939|869|758|784|721|868|649|340)\\d{7})$/)) {", - " var classifier = 'caribbean';", - " } else if (number.match(/^\\+?1?([2-9][0-9]{2}[2-9][0-9]{6})$/)) {", - " var classifier = 'did_us';", - " } else if (number.match(/^\\+[2-9]\\d{7,}$/)) {", - " var classifier = 'international';", - " } else {", - " var classifier = 'unknown';", - " } if (doc.custom_channel_vars.rate_name) {", - " emit([doc.pvt_created, doc._id], {", - " 'direction': doc.call_direction,", - " 'classifier': classifier,", - " 'domain': domain,", - " 'billable_seconds': parseInt(doc.billing_seconds),", - " 'rate_name': doc.custom_channel_vars.rate_name", - " });", - " } else {", - " emit([doc.pvt_created, doc._id], {", - " 'direction': doc.call_direction,", - " 'classifier': classifier,", - " 'domain': domain,", - " 'billable_seconds': parseInt(doc.billing_seconds)", - " });", - " }", + " if (doc.pvt_type != 'cdr' || doc.pvt_deleted || !doc.custom_channel_vars || doc.channel_name.indexOf('loopback') !== -1 || (doc.call_direction == 'inbound' && doc.custom_channel_vars.authorizing_id) || (doc.call_direction == 'outbound' && !doc.custom_channel_vars.resource_id)) return;", + " if (doc.call_direction == 'inbound') {", + " var domain = doc.from.substr(doc.from.indexOf('@') + 1);", + " } else {", + " var domain = doc.to.substr(doc.to.indexOf('@') + 1);", + " }", + " var number = doc.to.substr(0, doc.to.indexOf('@'));", + " if (number.match(/^\\+1((?:800|888|877|866|855)\\d{7})$/)) {", + " var classifier = 'tollfree_us';", + " } else if (number.match(/^\\+1(900\\d{7})$/)) {", + " var classifier = 'toll_us';", + " } else if (number.match(/^(911|933)$/)) {", + " var classifier = 'emergency';", + " } else if (number.match(/^\\+?1((?:684|264|268|242|246|441|284|345|767|809|829|849|473|671|876|664|670|787|939|869|758|784|721|868|649|340)\\d{7})$/)) {", + " var classifier = 'caribbean';", + " } else if (number.match(/^\\+?1?([2-9][0-9]{2}[2-9][0-9]{6})$/)) {", + " var classifier = 'did_us';", + " } else if (number.match(/^\\+[2-9]\\d{7,}$/)) {", + " var classifier = 'international';", + " } else {", + " var classifier = 'unknown';", + " }", + " if (doc.custom_channel_vars.rate_name) {", + " emit([doc.pvt_created, doc._id], {", + " 'direction': doc.call_direction,", + " 'classifier': classifier,", + " 'domain': domain,", + " 'billable_seconds': parseInt(doc.billing_seconds),", + " 'rate_name': doc.custom_channel_vars.rate_name", + " });", + " } else {", + " emit([doc.pvt_created, doc._id], {", + " 'direction': doc.call_direction,", + " 'classifier': classifier,", + " 'domain': domain,", + " 'billable_seconds': parseInt(doc.billing_seconds)", + " });", + " }", "}" ] } diff --git a/core/kazoo_modb/priv/couchdb/views/clicktocall.json b/core/kazoo_modb/priv/couchdb/views/clicktocall.json index bd6374a9bb2..d2af9890eef 100644 --- a/core/kazoo_modb/priv/couchdb/views/clicktocall.json +++ b/core/kazoo_modb/priv/couchdb/views/clicktocall.json @@ -10,7 +10,12 @@ "language": "javascript", "views": { "history_listing": { - "map": "function(doc) { if(doc.pvt_type != 'c2c_history' || doc.pvt_deleted) return; emit([doc.pvt_clicktocall_id, doc.pvt_created], null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'c2c_history' || doc.pvt_deleted) return;", + " emit([doc.pvt_clicktocall_id, doc.pvt_created], null);", + "}" + ] } } } diff --git a/core/kazoo_modb/priv/couchdb/views/faxes.json b/core/kazoo_modb/priv/couchdb/views/faxes.json index 758c6a75631..57c7cecbf04 100644 --- a/core/kazoo_modb/priv/couchdb/views/faxes.json +++ b/core/kazoo_modb/priv/couchdb/views/faxes.json @@ -10,19 +10,79 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'fax' || doc.pvt_deleted) return; F = doc.folder ? doc.folder : 'inbox'; emit([doc.pvt_created, doc._id], {'id': doc._id, 'folder' : F, 'status': doc.pvt_job_status, 'to': doc.to_number, 'from': doc.from_number, 'created': doc.pvt_created}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted) return;", + " F = doc.folder ? doc.folder : 'inbox';", + " emit([doc.pvt_created, doc._id], {", + " 'id': doc._id,", + " 'folder': F,", + " 'status': doc.pvt_job_status,", + " 'to': doc.to_number,", + " 'from': doc.from_number,", + " 'created': doc.pvt_created", + " });", + "}" + ] }, "list_by_faxbox": { - "map": "function(doc) { if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.faxbox_id) return; F = doc.folder ? doc.folder : 'inbox'; emit([doc.faxbox_id, F, doc.pvt_created], {'id': doc._id, 'status': doc.pvt_job_status, 'to': doc.to_number, 'from': doc.from_number, 'created': doc.pvt_created}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.faxbox_id) return;", + " F = doc.folder ? doc.folder : 'inbox';", + " emit([doc.faxbox_id, F, doc.pvt_created], {", + " 'id': doc._id,", + " 'status': doc.pvt_job_status,", + " 'to': doc.to_number,", + " 'from': doc.from_number,", + " 'created': doc.pvt_created", + " });", + "}" + ] }, "list_by_folder": { - "map": "function(doc) { if (doc.pvt_type != 'fax' || doc.pvt_deleted) return; F = doc.folder ? doc.folder : 'inbox'; emit([F, doc.pvt_created, doc._id], {'id': doc._id, 'status': doc.pvt_job_status, 'to': doc.to_number, 'from': doc.from_number, 'created': doc.pvt_created}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted) return;", + " F = doc.folder ? doc.folder : 'inbox';", + " emit([F, doc.pvt_created, doc._id], {", + " 'id': doc._id,", + " 'status': doc.pvt_job_status,", + " 'to': doc.to_number,", + " 'from': doc.from_number,", + " 'created': doc.pvt_created", + " });", + "}" + ] }, "list_by_ownerid": { - "map": "function(doc) { if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.owner_id) return; F = doc.folder ? doc.folder : 'inbox'; emit([doc.owner_id, F, doc.pvt_created], {'id': doc._id, 'status': doc.pvt_job_status, 'to': doc.to_number, 'from': doc.from_number, 'created': doc.pvt_created}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'fax' || doc.pvt_deleted || !doc.owner_id) return;", + " F = doc.folder ? doc.folder : 'inbox';", + " emit([doc.owner_id, F, doc.pvt_created], {", + " 'id': doc._id,", + " 'status': doc.pvt_job_status,", + " 'to': doc.to_number,", + " 'from': doc.from_number,", + " 'created': doc.pvt_created", + " });", + "}" + ] }, "smtp_log": { - "map": "function(doc) { if (doc.pvt_deleted || doc.pvt_type != 'fax_smtp_log') return; emit(doc.pvt_created, {'id': doc._id, 'from': doc.from, 'to': doc.to, 'error': doc.errors[0], 'created': doc.pvt_created}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || doc.pvt_type != 'fax_smtp_log') return;", + " emit(doc.pvt_created, {", + " 'id': doc._id,", + " 'from': doc.from,", + " 'to': doc.to,", + " 'error': doc.errors[0],", + " 'created': doc.pvt_created", + " });", + "}" + ] } } } diff --git a/core/kazoo_modb/priv/couchdb/views/functions.json b/core/kazoo_modb/priv/couchdb/views/functions.json index 637ea6d5337..31226e475ce 100644 --- a/core/kazoo_modb/priv/couchdb/views/functions.json +++ b/core/kazoo_modb/priv/couchdb/views/functions.json @@ -10,7 +10,12 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if(doc.pvt_type != 'functions' || doc.pvt_deleted) return; emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'functions' || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_modb/priv/couchdb/views/interactions.json b/core/kazoo_modb/priv/couchdb/views/interactions.json index e6ba2b86d62..d429b2a99d9 100644 --- a/core/kazoo_modb/priv/couchdb/views/interactions.json +++ b/core/kazoo_modb/priv/couchdb/views/interactions.json @@ -61,24 +61,14 @@ "function(keys, values, rereduce) {", " if (rereduce) {", " return values.reduce(function(a, b) {", - " return a == null ? b", - " : b == null ? a", - " : a.channel_time < b.channel_time ? a", - " : a.channel_time > b.channel_time ? b", - " : a.leg < b.leg ? a", - " : b", + " return a == null ? b : b == null ? a : a.channel_time < b.channel_time ? a : a.channel_time > b.channel_time ? b : a.leg < b.leg ? a : b", " })", " } else {", " v = values.reduce(function(a, b) {", - " return a == null ? b", - " : b == null ? a", - " : a.channel_time < b.channel_time ? a", - " : a.channel_time > b.channel_time ? b", - " : a.leg < b.leg ? a", - " : b", + " return a == null ? b : b == null ? a : a.channel_time < b.channel_time ? a : a.channel_time > b.channel_time ? b : a.leg < b.leg ? a : b", " });", " return v;", - "}", + " }", "}" ] } diff --git a/core/kazoo_modb/priv/couchdb/views/ledgers.json b/core/kazoo_modb/priv/couchdb/views/ledgers.json index 4f719d556b9..21ff66c4588 100644 --- a/core/kazoo_modb/priv/couchdb/views/ledgers.json +++ b/core/kazoo_modb/priv/couchdb/views/ledgers.json @@ -12,12 +12,16 @@ "list_by_source": { "map": [ "function(doc) {", - " if (doc.pvt_deleted || doc.pvt_type !== 'ledger')", - " return;", + " if (doc.pvt_deleted || doc.pvt_type !== 'ledger') return;", " var amount = doc.amount || 0;", - " if (doc.pvt_ledger_type === 'debit')", - " amount *= -1;", - " var result = {'amount': amount, 'source': doc.source, 'usage': doc.usage, 'metadata': doc.metadata || {}, 'executor': doc.executor || {}};", + " if (doc.pvt_ledger_type === 'debit') amount *= -1;", + " var result = {", + " 'amount': amount,", + " 'source': doc.source,", + " 'usage': doc.usage,", + " 'metadata': doc.metadata || {},", + " 'executor': doc.executor || {}", + " };", " emit([doc.source.service, doc.pvt_created, doc._id], result);", "}" ] @@ -25,20 +29,21 @@ "list_by_timestamp": { "map": [ "function(doc) {", - " if (doc.pvt_deleted || doc.pvt_type !== 'ledger')", - " return;", + " if (doc.pvt_deleted || doc.pvt_type !== 'ledger') return;", " var amount = doc.amount || 0;", - " var usage = doc.usage || {};", + " var usage = doc.usage || {};", " var service = doc.source.service;", - " if (doc.pvt_ledger_type === 'debit')", - " amount *= -1;", + " if (doc.pvt_ledger_type === 'debit') amount *= -1;", " var o = {};", - " o[service] = {amount:amount, usage:usage};", + " o[service] = {", + " amount: amount,", + " usage: usage", + " };", " emit(doc.pvt_created, o);", "}" ], "reduce": [ - "function (keys, values, rereduce) {", + "function(keys, values, rereduce) {", " return values.reduce(function(reduceObj, obj) {", " for (var service in obj) {", " if (!obj.hasOwnProperty(service)) continue;", @@ -115,11 +120,9 @@ "total_by_source": { "map": [ "function(doc) {", - " if (doc.pvt_deleted || doc.pvt_type !== 'ledger')", - " return;", + " if (doc.pvt_deleted || doc.pvt_type !== 'ledger') return;", " var amount = doc.amount || 0;", - " if (doc.pvt_ledger_type === 'debit')", - " amount *= -1;", + " if (doc.pvt_ledger_type === 'debit') amount *= -1;", " emit([doc.source.service, doc.pvt_created], amount);", "}" ], diff --git a/core/kazoo_modb/priv/couchdb/views/mailbox_messages.json b/core/kazoo_modb/priv/couchdb/views/mailbox_messages.json index f9f28ffbab3..569a926e5f2 100644 --- a/core/kazoo_modb/priv/couchdb/views/mailbox_messages.json +++ b/core/kazoo_modb/priv/couchdb/views/mailbox_messages.json @@ -12,8 +12,7 @@ "count_per_box_folder": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted) return;", " emit([doc.source_id, doc.metadata.folder, doc.metadata.timestamp]);", "}" ] @@ -21,8 +20,7 @@ "count_per_folder": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted) return;", " emit([doc.metadata.folder, doc.metadata.timestamp, doc.source_id]);", "}" ] @@ -30,8 +28,7 @@ "listing_by_mailbox": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted) return;", " emit([doc.source_id, doc.metadata.timestamp], {", " 'timestamp': doc.metadata.timestamp,", " 'from': doc.metadata.from,", @@ -43,15 +40,14 @@ " 'length': doc.metadata.length,", " 'media_id': doc.metadata.media_id,", " 'transcribed': doc.transcription && doc.transcription.result && doc.transcription.result === 'success'", - " });", + " });", "}" ] }, "listing_by_timestamp": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted)", - " return;", + " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted) return;", " emit([doc.metadata.timestamp, doc.source_id], {", " 'timestamp': doc.metadata.timestamp,", " 'from': doc.metadata.from,", @@ -63,15 +59,14 @@ " 'length': doc.metadata.length,", " 'media_id': doc.metadata.media_id,", " 'transcribed': doc.transcription && doc.transcription.result && doc.transcription.result === 'success'", - " });", + " });", "}" ] }, "missing_metadata": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted || doc.metadata)", - " return;", + " if (doc.pvt_type != 'mailbox_message' || doc.pvt_deleted || doc.metadata) return;", " emit(doc._id);", "}" ] diff --git a/core/kazoo_modb/priv/couchdb/views/notifications.json b/core/kazoo_modb/priv/couchdb/views/notifications.json index 7e7b399c9d1..f435e9e803a 100644 --- a/core/kazoo_modb/priv/couchdb/views/notifications.json +++ b/core/kazoo_modb/priv/couchdb/views/notifications.json @@ -10,7 +10,21 @@ "language": "javascript", "views": { "smtp_log": { - "map": "function(doc) { if (doc.pvt_deleted || doc.pvt_type != 'notify_smtp_log') return; emit(doc.pvt_created, {'id': doc._id, 'template_id' : doc.template_id, 'from': doc.emails.from, 'to': doc.emails.to[0], 'error': doc.error, 'subject' : doc.subject, 'created': doc.pvt_created, 'receipt' : doc.receipt}); }" + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || doc.pvt_type != 'notify_smtp_log') return;", + " emit(doc.pvt_created, {", + " 'id': doc._id,", + " 'template_id': doc.template_id,", + " 'from': doc.emails.from,", + " 'to': doc.emails.to[0],", + " 'error': doc.error,", + " 'subject': doc.subject,", + " 'created': doc.pvt_created,", + " 'receipt': doc.receipt", + " });", + "}" + ] } } } diff --git a/core/kazoo_modb/priv/couchdb/views/pivot.json b/core/kazoo_modb/priv/couchdb/views/pivot.json index 8046ecad579..f53b20348a2 100644 --- a/core/kazoo_modb/priv/couchdb/views/pivot.json +++ b/core/kazoo_modb/priv/couchdb/views/pivot.json @@ -10,13 +10,37 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if(doc.pvt_type != 'pivot' || doc.pvt_deleted) return; emit(doc._id, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'pivot' || doc.pvt_deleted) return;", + " emit(doc._id, null);", + "}" + ] }, "debug_listing": { - "map": "function(doc) {if (doc.pvt_type != 'pivot_debug' || doc.pvt_deleted) return; emit([doc.call_id, doc.pvt_created], null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'pivot_debug' || doc.pvt_deleted) return;", + " emit([doc.call_id, doc.pvt_created], null);", + "}" + ] }, "first_iteration": { - "map": "function(doc) {if (doc.pvt_type != 'pivot_debug' || doc.pvt_deleted || doc.iteration != 1) return;emit(doc.call_id, {'call_id': doc.call_id,'created': doc.pvt_created,'uri': doc.uri,'status_code': doc.resp_status_code,'node': doc.pvt_node,'iteration': doc.iteration,'has_schema_errors': (typeof doc.schema_errors != 'undefined'),'has_json_errors': (typeof doc.json_errors != 'undefined')});}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'pivot_debug' || doc.pvt_deleted || doc.iteration != 1) return;", + " emit(doc.call_id, {", + " 'call_id': doc.call_id,", + " 'created': doc.pvt_created,", + " 'uri': doc.uri,", + " 'status_code': doc.resp_status_code,", + " 'node': doc.pvt_node,", + " 'iteration': doc.iteration,", + " 'has_schema_errors': (typeof doc.schema_errors != 'undefined'),", + " 'has_json_errors': (typeof doc.json_errors != 'undefined')", + " });", + "}" + ] } } } diff --git a/core/kazoo_modb/priv/couchdb/views/recordings.json b/core/kazoo_modb/priv/couchdb/views/recordings.json index 7ee78cb6585..0cb0c41786e 100644 --- a/core/kazoo_modb/priv/couchdb/views/recordings.json +++ b/core/kazoo_modb/priv/couchdb/views/recordings.json @@ -10,10 +10,20 @@ "language": "javascript", "views": { "crossbar_listing": { - "map": "function(doc) { if (doc.pvt_type != 'call_recording' || doc.pvt_deleted) return; emit([doc.pvt_created, doc._id], null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'call_recording' || doc.pvt_deleted) return;", + " emit([doc.pvt_created, doc._id], null);", + "}" + ] }, "listing_by_user": { - "map": "function(doc) { if (doc.pvt_type != 'call_recording' || doc.pvt_deleted || !doc.owner_id) return; emit([doc.owner_id, doc.pvt_created, doc._id], null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'call_recording' || doc.pvt_deleted || !doc.owner_id) return;", + " emit([doc.owner_id, doc.pvt_created, doc._id], null);", + "}" + ] } } } diff --git a/core/kazoo_modb/priv/couchdb/views/resources.json b/core/kazoo_modb/priv/couchdb/views/resources.json index 89189f2fc65..9a1cf6e3026 100644 --- a/core/kazoo_modb/priv/couchdb/views/resources.json +++ b/core/kazoo_modb/priv/couchdb/views/resources.json @@ -13,14 +13,14 @@ "map": [ "function(doc) {", " if (doc.pvt_type != 'resource_job' || doc.pvt_deleted) return;", - " var failures = 0, o = doc.errors || {};", + " var failures = 0,", + " o = doc.errors || {};", " for (var p in o)", - " if (o.hasOwnProperty(p))", - " failures++;", - " var successes = 0, o = doc.success || {};", + " if (o.hasOwnProperty(p)) failures++;", + " var successes = 0,", + " o = doc.success || {};", " for (var p in o)", - " if (o.hasOwnProperty(p))", - " successes++;", + " if (o.hasOwnProperty(p)) successes++;", " emit(doc.pvt_created, {", " 'id': doc._id,", " 'timestamp': doc.pvt_modified,", @@ -34,7 +34,12 @@ ] }, "status_listing": { - "map": "function(doc) { if (doc.pvt_type != 'resource_job' || doc.pvt_deleted) return; emit(doc.pvt_status, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'resource_job' || doc.pvt_deleted) return;", + " emit(doc.pvt_status, null);", + "}" + ] } } } diff --git a/core/kazoo_modb/priv/couchdb/views/services.json b/core/kazoo_modb/priv/couchdb/views/services.json index 5ea411859a7..5d1102351e9 100644 --- a/core/kazoo_modb/priv/couchdb/views/services.json +++ b/core/kazoo_modb/priv/couchdb/views/services.json @@ -12,7 +12,7 @@ "audit_logs_by_creation": { "map": [ "function(doc) {", - " if ( doc.pvt_deleted || doc.pvt_type != 'audit_log') return;", + " if (doc.pvt_deleted || doc.pvt_type != 'audit_log') return;", " emit([doc.pvt_created, doc._id], {", " 'id': doc._id,", " 'status': doc.status,", @@ -35,7 +35,7 @@ " var items = invoice.items || [];", " for (var index = 0; index < items.length; index++) {", " var item = items[index];", - " if (item.changes && (item.changes.difference.billable || 0 ) !== 0) {", + " if (item.changes && (item.changes.difference.billable || 0) !== 0) {", " var changedBillable = item.changes.difference.billable;", " emit([day, item.item], {", " 'addition': changedBillable > 0 ? changedBillable : 0,", @@ -57,7 +57,7 @@ "}" ], "reduce": [ - "function (keys, values, rereduce) {", + "function(keys, values, rereduce) {", " return values.reduce(function(reduceObj, obj) {", " var isLateChange = (obj.last_timestamp || 0) >= (reduceObj.last_timestamp || 0);", " if (obj.sum_quantity) {", @@ -91,7 +91,7 @@ " var items = invoice.items || [];", " for (var index = 0; index < items.length; index++) {", " var item = items[index];", - " if (item.changes && (item.changes.difference.billable || 0 ) !== 0) {", + " if (item.changes && (item.changes.difference.billable || 0) !== 0) {", " var changedBillable = item.changes.difference.billable;", " emit([item.item, day], {", " 'addition': changedBillable > 0 ? changedBillable : 0,", @@ -113,7 +113,7 @@ "}" ], "reduce": [ - "function (keys, values, rereduce) {", + "function(keys, values, rereduce) {", " return values.reduce(function(reduceObj, obj) {", " var isLateChange = (obj.last_timestamp || 0) >= (reduceObj.last_timestamp || 0);", " if (obj.sum_quantity) {", diff --git a/core/kazoo_modb/priv/couchdb/views/storage.json b/core/kazoo_modb/priv/couchdb/views/storage.json index 23d07718258..8e09bff139e 100644 --- a/core/kazoo_modb/priv/couchdb/views/storage.json +++ b/core/kazoo_modb/priv/couchdb/views/storage.json @@ -10,19 +10,47 @@ "language": "javascript", "views": { "list_by_content_type": { - "map": "function(doc) {if (doc.pvt_deleted || (!doc._attachments && !doc.pvt_attachments)) return; for (var i in doc._attachments) emit([doc._attachments[i].content_type, 'database'], doc._attachments[i].length); for (var i in doc.pvt_attachments) for (var h in doc.pvt_attachments[i].handler) emit([doc.pvt_attachments[i].content_type, h], doc.pvt_attachments[i].length); }", + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || (!doc._attachments && !doc.pvt_attachments)) return;", + " for (var i in doc._attachments) emit([doc._attachments[i].content_type, 'database'], doc._attachments[i].length);", + " for (var i in doc.pvt_attachments)", + " for (var h in doc.pvt_attachments[i].handler) emit([doc.pvt_attachments[i].content_type, h], doc.pvt_attachments[i].length);", + "}" + ], "reduce": "_sum" }, "list_by_doc_type": { - "map": "function(doc) {if (doc.pvt_deleted || (!doc._attachments && !doc.pvt_attachments)) return; for (var i in doc._attachments) emit([doc.pvt_type, doc._attachments[i].content_type, 'database' ], doc._attachments[i].length); for (var i in doc.pvt_attachments) for (var h in doc.pvt_attachments[i].handler) emit([doc.pvt_type, doc.pvt_attachments[i].content_type, h], doc.pvt_attachments[i].length); }", + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || (!doc._attachments && !doc.pvt_attachments)) return;", + " for (var i in doc._attachments) emit([doc.pvt_type, doc._attachments[i].content_type, 'database'], doc._attachments[i].length);", + " for (var i in doc.pvt_attachments)", + " for (var h in doc.pvt_attachments[i].handler) emit([doc.pvt_type, doc.pvt_attachments[i].content_type, h], doc.pvt_attachments[i].length);", + "}" + ], "reduce": "_sum" }, "list_by_storage_content_type": { - "map": "function(doc) {if (doc.pvt_deleted || (!doc._attachments && !doc.pvt_attachments)) return; for (var i in doc._attachments) emit(['database', doc._attachments[i].content_type ], doc._attachments[i].length); for (var i in doc.pvt_attachments) for (var h in doc.pvt_attachments[i].handler) emit([h, doc.pvt_attachments[i].content_type], doc.pvt_attachments[i].length); }", + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || (!doc._attachments && !doc.pvt_attachments)) return;", + " for (var i in doc._attachments) emit(['database', doc._attachments[i].content_type], doc._attachments[i].length);", + " for (var i in doc.pvt_attachments)", + " for (var h in doc.pvt_attachments[i].handler) emit([h, doc.pvt_attachments[i].content_type], doc.pvt_attachments[i].length);", + "}" + ], "reduce": "_sum" }, "list_by_storage_doc_type": { - "map": "function(doc) {if (doc.pvt_deleted || (!doc._attachments && !doc.pvt_attachments)) return; for (var i in doc._attachments) emit(['database', doc.pvt_type, doc._attachments[i].content_type ], doc._attachments[i].length); for (var i in doc.pvt_attachments) for (var h in doc.pvt_attachments[i].handler) emit([h, doc.pvt_type, doc.pvt_attachments[i].content_type], doc.pvt_attachments[i].length); }", + "map": [ + "function(doc) {", + " if (doc.pvt_deleted || (!doc._attachments && !doc.pvt_attachments)) return;", + " for (var i in doc._attachments) emit(['database', doc.pvt_type, doc._attachments[i].content_type], doc._attachments[i].length);", + " for (var i in doc.pvt_attachments)", + " for (var h in doc.pvt_attachments[i].handler) emit([h, doc.pvt_type, doc.pvt_attachments[i].content_type], doc.pvt_attachments[i].length);", + "}" + ], "reduce": "_sum" } } diff --git a/core/kazoo_modb/priv/couchdb/views/transactions.json b/core/kazoo_modb/priv/couchdb/views/transactions.json index a2c4f4f8c3a..2ce1f47c7f4 100644 --- a/core/kazoo_modb/priv/couchdb/views/transactions.json +++ b/core/kazoo_modb/priv/couchdb/views/transactions.json @@ -12,10 +12,9 @@ "legacy_total": { "map": [ "function(doc) {", - " if (doc.pvt_deleted || (doc.pvt_type !== 'credit' && doc.pvt_type !== 'debit'))", - " return;", + " if (doc.pvt_deleted || (doc.pvt_type !== 'credit' && doc.pvt_type !== 'debit')) return;", " var is_credit = doc.pvt_type === 'credit';", - " var is_debit = doc.pvt_type === 'debit';", + " var is_debit = doc.pvt_type === 'debit';", " var modifier = is_credit ? 1 : is_debit ? -1 : 0;", " var amount = doc.pvt_amount || 0;", " emit(null, amount * modifier);", @@ -26,16 +25,35 @@ "list_by_timestamp": { "map": [ "function(doc) {", - " if (doc.pvt_deleted || doc.pvt_type !== 'transaction')", - " return;", + " if (doc.pvt_deleted || doc.pvt_type !== 'transaction') return;", " var amount = doc.amount || 0;", - " if (doc.pvt_transaction_type === 'refund')", - " amount *= -1;", + " if (doc.pvt_transaction_type === 'refund') amount *= -1;", " if (doc.bookkeeper && doc.bookkeeper.results) {", - " var bookkeeper = {status: doc.bookkeeper.results.status, reason: doc.bookkeeper.results.reason, message: doc.bookkeeper.results.message};", - " emit(doc.pvt_created, {id:doc._id, amount:amount, status: doc.status, executor:doc.executor, description: doc.description, metadata: doc.metadata, bookkeeper: bookkeeper, created: doc.pvt_created});", + " var bookkeeper = {", + " status: doc.bookkeeper.results.status,", + " reason: doc.bookkeeper.results.reason,", + " message: doc.bookkeeper.results.message", + " };", + " emit(doc.pvt_created, {", + " id: doc._id,", + " amount: amount,", + " status: doc.status,", + " executor: doc.executor,", + " description: doc.description,", + " metadata: doc.metadata,", + " bookkeeper: bookkeeper,", + " created: doc.pvt_created", + " });", " } else {", - " emit(doc.pvt_created, {id:doc._id, amount:amount, status: doc.status, executor:doc.executor, description: doc.description, metadata: doc.metadata, created: doc.pvt_created});", + " emit(doc.pvt_created, {", + " id: doc._id,", + " amount: amount,", + " status: doc.status,", + " executor: doc.executor,", + " description: doc.description,", + " metadata: doc.metadata,", + " created: doc.pvt_created", + " });", " }", "}" ] diff --git a/core/kazoo_modb/priv/couchdb/views/webhooks.json b/core/kazoo_modb/priv/couchdb/views/webhooks.json index c77a3d23a8d..fe4c52c1222 100644 --- a/core/kazoo_modb/priv/couchdb/views/webhooks.json +++ b/core/kazoo_modb/priv/couchdb/views/webhooks.json @@ -10,10 +10,20 @@ "language": "javascript", "views": { "attempts_by_hook_listing": { - "map": "function(doc) { if (doc.pvt_type != 'webhook_attempt' || doc.pvt_deleted) return; emit([doc.hook_id, doc.pvt_created], null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'webhook_attempt' || doc.pvt_deleted) return;", + " emit([doc.hook_id, doc.pvt_created], null);", + "}" + ] }, "attempts_by_time_listing": { - "map": "function(doc) { if (doc.pvt_type != 'webhook_attempt' || doc.pvt_deleted) return; emit(doc.pvt_created, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'webhook_attempt' || doc.pvt_deleted) return;", + " emit(doc.pvt_created, null);", + "}" + ] } } } diff --git a/core/kazoo_numbers/priv/couchdb/views/numbers.json b/core/kazoo_numbers/priv/couchdb/views/numbers.json index e141b25d955..dc36a01ba4b 100644 --- a/core/kazoo_numbers/priv/couchdb/views/numbers.json +++ b/core/kazoo_numbers/priv/couchdb/views/numbers.json @@ -10,7 +10,12 @@ "language": "javascript", "views": { "assigned_to": { - "map": "function(doc) { if (!doc.pvt_assigned_to) return; emit([doc.pvt_assigned_to, doc._id], null); }" + "map": [ + "function(doc) {", + " if (!doc.pvt_assigned_to) return;", + " emit([doc.pvt_assigned_to, doc._id], null);", + "}" + ] }, "list_assigned_and_app": { "map": [ @@ -21,14 +26,27 @@ ] }, "module_name": { - "map": "function(doc) { emit(doc.pvt_module_name, 1); }", + "map": [ + "function(doc) {", + " emit(doc.pvt_module_name, 1);", + "}" + ], "reduce": "_sum" }, "status": { - "map": "function(doc) { emit([doc.pvt_state, doc.pvt_module_name, doc._id], null); }" + "map": [ + "function(doc) {", + " emit([doc.pvt_state, doc.pvt_module_name, doc._id], null);", + "}" + ] }, "unassigned": { - "map": "function(doc) { if (doc.pvt_assigned_to || doc.pvt_state == 'discovery' || doc.pvt_number_state == 'discovery') return; emit(doc._id, null); }" + "map": [ + "function(doc) {", + " if (doc.pvt_assigned_to || doc.pvt_state == 'discovery' || doc.pvt_number_state == 'discovery') return;", + " emit(doc._id, null);", + "}" + ] } } } diff --git a/core/kazoo_numbers/priv/couchdb/views/numbers_inum.json b/core/kazoo_numbers/priv/couchdb/views/numbers_inum.json index 7b198515422..698a0781fab 100644 --- a/core/kazoo_numbers/priv/couchdb/views/numbers_inum.json +++ b/core/kazoo_numbers/priv/couchdb/views/numbers_inum.json @@ -10,7 +10,11 @@ "language": "javascript", "views": { "status": { - "map": "function(doc) { emit([doc.pvt_account_id, doc.pvt_state, doc._id], null); }" + "map": [ + "function(doc) {", + " emit([doc.pvt_account_id, doc.pvt_state, doc._id], null);", + "}" + ] } } } diff --git a/core/kazoo_numbers/priv/couchdb/views/numbers_managed.json b/core/kazoo_numbers/priv/couchdb/views/numbers_managed.json index e8e58e6bac1..fb8f48b07f0 100644 --- a/core/kazoo_numbers/priv/couchdb/views/numbers_managed.json +++ b/core/kazoo_numbers/priv/couchdb/views/numbers_managed.json @@ -10,7 +10,11 @@ "language": "javascript", "views": { "status": { - "map": "function(doc) { emit([doc.pvt_account_id, doc.pvt_state, doc._id], null); }" + "map": [ + "function(doc) {", + " emit([doc.pvt_account_id, doc.pvt_state, doc._id], null);", + "}" + ] } } } diff --git a/core/kazoo_numbers/priv/couchdb/views/port_requests.json b/core/kazoo_numbers/priv/couchdb/views/port_requests.json index ddebf13befa..300a93951a7 100644 --- a/core/kazoo_numbers/priv/couchdb/views/port_requests.json +++ b/core/kazoo_numbers/priv/couchdb/views/port_requests.json @@ -20,8 +20,8 @@ "agent_listing_by_state": { "map": [ "function(doc) {", - " if (doc.pvt_type != 'port_request' || doc.pvt_deleted) return;", - " emit([doc.pvt_port_authority, doc.pvt_port_state, doc.pvt_modified], null);", + " if (doc.pvt_type != 'port_request' || doc.pvt_deleted) return;", + " emit([doc.pvt_port_authority, doc.pvt_port_state, doc.pvt_modified], null);", "}" ] }, @@ -104,8 +104,7 @@ "map": [ "function(doc) {", " if (doc.pvt_type !== 'port_request' || doc.pvt_deleted) return;", - " if (doc.pvt_port_state === 'unconfirmed' || doc.pvt_port_state === 'canceled' || doc.pvt_port_state == 'completed')", - " return;", + " if (doc.pvt_port_state === 'unconfirmed' || doc.pvt_port_state === 'canceled' || doc.pvt_port_state == 'completed') return;", " for (var i in doc.numbers) {", " var number = doc.numbers[i];", " emit([doc.pvt_account_id, i], {", diff --git a/core/kazoo_services/priv/couchdb/views/services.json b/core/kazoo_services/priv/couchdb/views/services.json index bf91f28672b..8e8111e1bcc 100644 --- a/core/kazoo_services/priv/couchdb/views/services.json +++ b/core/kazoo_services/priv/couchdb/views/services.json @@ -11,10 +11,10 @@ "views": { "by_plan": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type != 'service' || doc.pvt_deleted) return;", " for (var key in doc.plans) {", - " emit(key, doc.plans[key]);", + " emit(key, doc.plans[key]);", " }", "}" ], @@ -22,7 +22,7 @@ }, "by_tree_length": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type != 'service' || doc.pvt_deleted) return;", " emit(doc.pvt_tree.length, null);", "}" @@ -30,20 +30,20 @@ }, "by_tree_length_with_plans": { "map": [ - "function (doc) {", - " if (doc.pvt_type != 'service' || doc.pvt_deleted || !doc.plans ) return;", - " for (var key in doc.plans) {", - " if(doc.plans.hasOwnProperty(key)) {", - " emit(doc.pvt_tree.length, null);", - " return;", - " }", + "function(doc) {", + " if (doc.pvt_type != 'service' || doc.pvt_deleted || !doc.plans) return;", + " for (var key in doc.plans) {", + " if (doc.plans.hasOwnProperty(key)) {", + " emit(doc.pvt_tree.length, null);", + " return;", " }", + " }", "}" ] }, "cascade_quantities": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type != 'service' || doc.pvt_deleted || !doc.quantities || !doc.quantities.account) return;", " for (var key in doc.quantities.account) {", " var obj = doc.quantities.account[key];", @@ -60,7 +60,7 @@ }, "totals": { "map": [ - "function (doc) {", + "function(doc) {", " if (doc.pvt_type != 'service' || doc.pvt_deleted || !doc.quantities || !doc.quantities.account) return;", " for (var key in doc.quantities.account) {", " var obj = doc.quantities.account[key];", diff --git a/core/webseq/priv/couchdb/views/webseq.json b/core/webseq/priv/couchdb/views/webseq.json index fb46e8729d0..8b5bd121251 100644 --- a/core/webseq/priv/couchdb/views/webseq.json +++ b/core/webseq/priv/couchdb/views/webseq.json @@ -3,7 +3,12 @@ "language": "javascript", "views": { "listing_by_name": { - "map": "function(doc){if(doc.pvt_type!='webseq'||doc.pvt_deleted)return;emit(doc.name, null);}" + "map": [ + "function(doc) {", + " if (doc.pvt_type != 'webseq' || doc.pvt_deleted) return;", + " emit(doc.name, null);", + "}" + ] } } } diff --git a/make/fmt.mk b/make/fmt.mk index 81187dfe8eb..cefcde95f67 100644 --- a/make/fmt.mk +++ b/make/fmt.mk @@ -1,7 +1,7 @@ FMT = $(ROOT)/make/erlang-formatter/fmt.sh FMT_SHA = 4e9b3379952e0cb3319308d7bdef832eb305f816 -.PHONY: fmt fmt-all clean-fmt clean-$(FMT) +.PHONY: fmt fmt-all fmt-views fmt-views-all clean-fmt clean-$(FMT) $(FMT): @wget -qO - 'https://codeload.github.com/fenollp/erlang-formatter/tar.gz/$(FMT_SHA)' | tar -vxz -C $(ROOT)/make/ @@ -14,6 +14,14 @@ fmt: TO_FMT ?= $(shell git --no-pager diff --name-only HEAD $(BASE_BRANCH) -- "* fmt: $(FMT) @$(if $(TO_FMT), @$(FMT) $(TO_FMT)) +fmt-views-all: + @$(ROOT)/scripts/format-couchdb-views.py core/kazoo_apps/priv/couchdb/account + @$(ROOT)/scripts/format-couchdb-views.py $(shell find applications core -wholename '*/couchdb/views/*.json') + +fmt-views: TO_FMT_VIEWS ?= $(shell git --no-pager diff --name-only HEAD $(BASE_BRANCH) -- "*/couchdb/views/*.json" "*/couchdb/account/*.json") +fmt-views: + @$(if $(TO_FMT_VIEWS), @$(ROOT)/scripts/format-couchdb-views.py $(TO_FMT_VIEWS)) + clean-fmt: clean-$(FMT) clean: clean-$(FMT) diff --git a/scripts/README.md b/scripts/README.md index c760f72cd11..66b6fe5cf58 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -458,6 +458,16 @@ Python script to format JSON files (like CouchDB views, JSON schemas) and write ``` +## format-couchdb-views.py + +Python script to make JavaScript codes in CouchDB view files beautify and multi-line so they are more readable to developers and also makes keep tracking changes in PR reviews easy. +'make apis' runs this as part of its instructions. + +```shell +./scripts/format-couchdb-views.py path/to/file.json [path/to/other/file.json,...] +``` + + ## generate-api-endpoints.escript Builds the Crossbar reference docs in 'applications/crossbar/doc/ref'. Helps detect when Crossbar endpoints have changes to their functionality that is client-facing. diff --git a/scripts/format-couchdb-views.py b/scripts/format-couchdb-views.py new file mode 100755 index 00000000000..79a638c87ed --- /dev/null +++ b/scripts/format-couchdb-views.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys +import json +from subprocess import call +import os +import shutil +import re +import jsbeautifier + +if len(sys.argv) < 2: + print('Usage: ' + sys.argv[0] + ' file.json+') + exit(0) + +design_pattern = re.compile('^_design/') + +def multiline_view(js): + opts = jsbeautifier.default_options() + opts.indent_size = 2 + + js = jsbeautifier.beautify(''.join(js), opts) + multiLine = [] + for line in js.split('\n'): + if not line: + continue + multiLine.append(line) + return multiLine + +def dict_map(data): + for key, value in data.items(): + if isinstance(value, str): + if value.startswith('function'): + data[key] = multiline_view(value) + elif isinstance(value, list) and len(value) > 0 \ + and isinstance(value[0], str) and value[0].startswith('function'): + data[key] = multiline_view(value) + else: + data[key] = value + return data + +def process_couchdb_view(data): + for key, value in data.items(): + if key in ['filters', 'lists', 'shows', 'updates']: + data[key] = dict_map(value) + elif key == 'views': + views = {} + for view, view_funs in value.items(): + views[view] = dict_map(view_funs) + data[key] = views + elif key == "rewrites" and isinstance(value, str): + data[key] = multiline_view(value) + elif key == "validate_doc_update": + data[key] = multiline_view(value) + else: + data[key] = value + return data + +exit_code = 0 + +def main(): + json.encoder.FLOAT_REPR = str + for fn in sys.argv[1:]: + if not os.path.isfile(fn): + print('not a file: {}'.format(fn)); + continue + if not fn.endswith('.json'): + print('not a JSON file: {}'.format(fn)); + continue + fn2 = fn + '~' + with open(fn) as rd: + data = json.load(rd) + if not design_pattern.match(data['_id']): + print('not a CouchDB view file: {}'.format(fn)) + continue + try: + data2 = json.dumps(process_couchdb_view(data), sort_keys=True, indent=4, separators=(",", ": ")) + with open(fn2, 'w') as fd2: + fd2.write(data2 + '\n') + shutil.move(fn2, fn) + except Exception as e: + print('failed to process {}'.format(fn)) + print(e) + global exit_code + exit_code=1 + +main() +exit(exit_code)