Skip to content

Commit

Permalink
Kazoo 5582 master - add a migrations API and add a migration to disab…
Browse files Browse the repository at this point in the history
…le notify and move to teletype (2600hz#3912)

* KAZOO-5582: add migrations api, add notify_to_teletype migration

* formatting and docs

* actual docs

* make some api's

* dialyze the things

* changes per code review

* :(

* add account name and user name to the migration tracking

* formatting again, switch types
  • Loading branch information
mark2600 authored and fenollp committed Jul 6, 2017
1 parent bfad83c commit d0ce1da
Show file tree
Hide file tree
Showing 6 changed files with 472 additions and 0 deletions.
48 changes: 48 additions & 0 deletions applications/crossbar/doc/migrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
### Migrations

#### About Migrations

The migrations API allows you to perform various account based migrations on an account, or an account and its sub-accounts.

#### List

Lists all available migrations.

> GET /v2/accounts/{ACCOUNT_ID}/migrations
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations
```

#### Summary

Provides a summary of a migration, including information on if it was performed and by whom and when.

> GET /v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID}
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID}
```

#### Perform Migration

Allows you to perform a migration, with the following potential parameters:

Name|Values|Description
----|------|-----------
perform_migration|now|Performs the migration now (now is the only currently supported option)
include_descendants|true / false (default: false)|If true the migration is performed on the account and sub-accounts
include_resellers|true / false (default: false)|If true the migration is performed on reseller sub-accounts

> POST /v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID}
```shell
curl -v -X POST \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID}
```

38 changes: 38 additions & 0 deletions applications/crossbar/doc/ref/migrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
### Migrations

#### About Migrations

#### Schema



#### Fetch

> GET /v2/accounts/{ACCOUNT_ID}/migrations
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations
```

#### Fetch

> GET /v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID}
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID}
```

#### Change

> POST /v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID}
```shell
curl -v -X POST \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID}
```

64 changes: 64 additions & 0 deletions applications/crossbar/priv/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -14063,6 +14063,15 @@
"required": true,
"type": "string"
},
"MIGRATION_ID": {
"in": "path",
"maxLength": 32,
"minLength": 32,
"name": "MIGRATION_ID",
"pattern": "^[0-9a-f]+$",
"required": true,
"type": "string"
},
"MODULE": {
"in": "path",
"name": "MODULE",
Expand Down Expand Up @@ -19092,6 +19101,61 @@
}
}
},
"/accounts/{ACCOUNT_ID}/migrations": {
"get": {
"parameters": [
{
"$ref": "#/parameters/auth_token_header"
},
{
"$ref": "#/parameters/ACCOUNT_ID"
}
],
"responses": {
"200": {
"description": "request succeeded"
}
}
}
},
"/accounts/{ACCOUNT_ID}/migrations/{MIGRATION_ID}": {
"get": {
"parameters": [
{
"$ref": "#/parameters/auth_token_header"
},
{
"$ref": "#/parameters/MIGRATION_ID"
},
{
"$ref": "#/parameters/ACCOUNT_ID"
}
],
"responses": {
"200": {
"description": "request succeeded"
}
}
},
"post": {
"parameters": [
{
"$ref": "#/parameters/auth_token_header"
},
{
"$ref": "#/parameters/MIGRATION_ID"
},
{
"$ref": "#/parameters/ACCOUNT_ID"
}
],
"responses": {
"200": {
"description": "request succeeded"
}
}
}
},
"/accounts/{ACCOUNT_ID}/move": {
"post": {
"parameters": [
Expand Down
37 changes: 37 additions & 0 deletions applications/crossbar/src/modules/cb_migration_disable_notify.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%%%-------------------------------------------------------------------
%%% @copyright (C) 2011-2017, 2600Hz INC
%%% @doc
%%% Crawl accounts and disable notify settings so that we use Teletype instead
%%%
%%% @end
%%% @contributors
%%% Mark Magnusson
%%%-------------------------------------------------------------------
-module(cb_migration_disable_notify).

-export([perform_migration/2]).

-include("crossbar.hrl").

-spec perform_migration(binary(), cb_context:context()) -> cb_context:context().
perform_migration(Account, Context) ->
lager:info("migrating account ~p from notify to teletype...", [Account]),

AccountDb = kz_util:format_account_id(Account, 'encoded'),

{'ok', BaseDoc} = kz_datamgr:open_cache_doc(AccountDb, Account),
NewDoc = lists:foldl(fun(X, A) -> X(A) end, BaseDoc, [
fun remove_vm_to_email/1
,fun remove_fax_to_email/1
]),

kz_datamgr:ensure_saved(AccountDb, NewDoc),
cb_context:set_resp_status(Context, 'success').

-spec remove_vm_to_email(kz_json:object()) -> kz_json:object().
remove_vm_to_email(Doc) ->
kz_json:delete_key([<<"notifications">>, <<"voicemail_to_email">>], Doc).

-spec remove_fax_to_email(kz_json:object()) -> kz_json:object().
remove_fax_to_email(Doc) ->
kz_json:delete_key([<<"notifications">>, <<"fax_to_email">>], Doc).
Loading

0 comments on commit d0ce1da

Please sign in to comment.