weixin_pam 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +165 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/jquery-sortable.js +699 -0
  6. data/app/assets/javascripts/weixin_pam/application.js +30 -0
  7. data/app/assets/javascripts/weixin_pam/diymenus.js +90 -0
  8. data/app/assets/javascripts/weixin_pam/public_accounts.js +2 -0
  9. data/app/assets/javascripts/weixin_pam/user_accounts.js +23 -0
  10. data/app/assets/stylesheets/weixin_pam/application.scss +31 -0
  11. data/app/assets/stylesheets/weixin_pam/diymenus.scss +52 -0
  12. data/app/assets/stylesheets/weixin_pam/jquery-dragable.scss +26 -0
  13. data/app/assets/stylesheets/weixin_pam/public_accounts.css +4 -0
  14. data/app/assets/stylesheets/weixin_pam/user_accounts.css +4 -0
  15. data/app/controllers/weixin_pam/application_controller.rb +4 -0
  16. data/app/controllers/weixin_pam/diymenus_controller.rb +100 -0
  17. data/app/controllers/weixin_pam/public_accounts_controller.rb +62 -0
  18. data/app/controllers/weixin_pam/user_accounts_controller.rb +76 -0
  19. data/app/decorators/controllers/weixin_rails_middleware/weixin_controller_decorator.rb +31 -0
  20. data/app/helpers/weixin_pam/application_helper.rb +18 -0
  21. data/app/helpers/weixin_pam/diymenus_helper.rb +4 -0
  22. data/app/helpers/weixin_pam/public_accounts_helper.rb +4 -0
  23. data/app/helpers/weixin_pam/user_accounts_helper.rb +4 -0
  24. data/app/models/weixin_pam/diymenu.rb +58 -0
  25. data/app/models/weixin_pam/public_account.rb +87 -0
  26. data/app/models/weixin_pam/user_account.rb +67 -0
  27. data/app/views/layouts/weixin_pam/_nav_bar.html.erb +37 -0
  28. data/app/views/layouts/weixin_pam/application.html.erb +26 -0
  29. data/app/views/weixin_pam/diymenus/_form.html.erb +18 -0
  30. data/app/views/weixin_pam/diymenus/edit.html.erb +3 -0
  31. data/app/views/weixin_pam/diymenus/index.html.slim +32 -0
  32. data/app/views/weixin_pam/diymenus/new.html.erb +3 -0
  33. data/app/views/weixin_pam/public_accounts/_form.html.erb +12 -0
  34. data/app/views/weixin_pam/public_accounts/edit.html.erb +3 -0
  35. data/app/views/weixin_pam/public_accounts/index.html.erb +30 -0
  36. data/app/views/weixin_pam/public_accounts/new.html.erb +3 -0
  37. data/app/views/weixin_pam/public_accounts/show.html.erb +17 -0
  38. data/app/views/weixin_pam/user_accounts/_form.html.erb +37 -0
  39. data/app/views/weixin_pam/user_accounts/edit.html.erb +6 -0
  40. data/app/views/weixin_pam/user_accounts/index.html.slim +25 -0
  41. data/app/views/weixin_pam/user_accounts/new.html.erb +5 -0
  42. data/app/views/weixin_pam/user_accounts/show.html.erb +29 -0
  43. data/config/initializers/simple_form.rb +165 -0
  44. data/config/initializers/simple_form_bootstrap.rb +149 -0
  45. data/config/initializers/weixin_rails_middleware.rb +27 -0
  46. data/config/locales/diymenu.zh-CN.yml +9 -0
  47. data/config/locales/public_account.zh-CN.yml +16 -0
  48. data/config/locales/simple_form.en.yml +31 -0
  49. data/config/locales/user_account.zh-CN.yml +13 -0
  50. data/config/routes.rb +17 -0
  51. data/db/migrate/20151211153307_create_weixin_pam_public_accounts.rb +14 -0
  52. data/db/migrate/20151211153353_create_weixin_pam_user_accounts.rb +19 -0
  53. data/db/migrate/20151212152624_create_weixin_pam_diymenus.rb +18 -0
  54. data/db/migrate/20151215140830_add_weixin_secret_key_and_weixin_token_to_public_accounts.rb +13 -0
  55. data/db/migrate/20151218053505_add_host_to_weixin_pam_public_account.rb +6 -0
  56. data/lib/tasks/weixin_pam_tasks.rake +4 -0
  57. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  58. data/lib/weixin_pam.rb +3 -0
  59. data/lib/weixin_pam/api_error.rb +3 -0
  60. data/lib/weixin_pam/api_error/failed_result.rb +11 -0
  61. data/lib/weixin_pam/engine.rb +24 -0
  62. data/lib/weixin_pam/public_account_reply.rb +222 -0
  63. data/lib/weixin_pam/version.rb +3 -0
  64. data/test/controllers/weixin_pam/diymenus_controller_test.rb +52 -0
  65. data/test/controllers/weixin_pam/public_accounts_controller_test.rb +52 -0
  66. data/test/controllers/weixin_pam/user_accounts_controller_test.rb +52 -0
  67. data/test/dummy/README.rdoc +28 -0
  68. data/test/dummy/Rakefile +6 -0
  69. data/test/dummy/app/assets/javascripts/application.js +13 -0
  70. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  71. data/test/dummy/app/controllers/application_controller.rb +5 -0
  72. data/test/dummy/app/helpers/application_helper.rb +2 -0
  73. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  74. data/test/dummy/bin/bundle +3 -0
  75. data/test/dummy/bin/rails +4 -0
  76. data/test/dummy/bin/rake +4 -0
  77. data/test/dummy/bin/setup +29 -0
  78. data/test/dummy/config.ru +4 -0
  79. data/test/dummy/config/application.rb +26 -0
  80. data/test/dummy/config/boot.rb +5 -0
  81. data/test/dummy/config/database.yml +25 -0
  82. data/test/dummy/config/environment.rb +5 -0
  83. data/test/dummy/config/environments/development.rb +41 -0
  84. data/test/dummy/config/environments/production.rb +79 -0
  85. data/test/dummy/config/environments/test.rb +42 -0
  86. data/test/dummy/config/initializers/assets.rb +11 -0
  87. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  88. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  89. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  90. data/test/dummy/config/initializers/inflections.rb +16 -0
  91. data/test/dummy/config/initializers/mime_types.rb +4 -0
  92. data/test/dummy/config/initializers/session_store.rb +3 -0
  93. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  94. data/test/dummy/config/locales/en.yml +23 -0
  95. data/test/dummy/config/routes.rb +4 -0
  96. data/test/dummy/config/secrets.yml +22 -0
  97. data/test/dummy/db/development.sqlite3 +0 -0
  98. data/test/dummy/db/schema.rb +60 -0
  99. data/test/dummy/db/test.sqlite3 +0 -0
  100. data/test/dummy/log/development.log +594 -0
  101. data/test/dummy/public/404.html +67 -0
  102. data/test/dummy/public/422.html +67 -0
  103. data/test/dummy/public/500.html +66 -0
  104. data/test/dummy/public/favicon.ico +0 -0
  105. data/test/fixtures/weixin_pam/diymenus.yml +19 -0
  106. data/test/fixtures/weixin_pam/public_accounts.yml +17 -0
  107. data/test/fixtures/weixin_pam/user_accounts.yml +15 -0
  108. data/test/integration/navigation_test.rb +8 -0
  109. data/test/models/weixin_pam/diymenu_test.rb +9 -0
  110. data/test/models/weixin_pam/public_account_test.rb +9 -0
  111. data/test/models/weixin_pam/user_account_test.rb +9 -0
  112. data/test/test_helper.rb +21 -0
  113. data/test/weixin_pam_test.rb +7 -0
  114. metadata +374 -0
@@ -0,0 +1,30 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+
14
+ //= require jquery
15
+ //= require jquery_ujs
16
+ //= require jquery.turbolinks
17
+ //= require turbolinks
18
+ //= require bootstrap-sprockets
19
+ //= require ../jquery-sortable.js
20
+ //= require_tree .
21
+
22
+ function appendFlashMessage(type, message){
23
+ var el = $('<div class="alert alert-' + type + '"></div>');
24
+ el.append("<button class='close' data-dismiss='alert'>x</button>")
25
+ el.append(message);
26
+ el.prependTo('div#flash-message-box');
27
+ setTimeout(function(){
28
+ el.fadeOut(2000, function(){ $(this).remove() });
29
+ }, 5000);
30
+ }
@@ -0,0 +1,90 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+
4
+ $(document).ready(function(){
5
+ if($('body[data-page="diymenus_index"]')[0]) {
6
+ var formEle, sortMenuEle, sortGroup;
7
+ formEle = $('form#form-sort-diymenu');
8
+ formEle.on('ajax:success', function(data, status, xhr){
9
+ switch(status.action){
10
+ case 'upload':
11
+ if(status.ok)
12
+ appendFlashMessage('success', '上传成功');
13
+ else
14
+ appendFlashMessage('danger', '上传失败,失败原因:' + status.msg);
15
+ break;
16
+ case 'sort':
17
+ appendFlashMessage('success', '微信菜单保存成功');
18
+ break;
19
+ case 'download':
20
+ if(status.error)
21
+ appendFlashMessage('danger', '下载失败,失败原因:' + status.error);
22
+ break;
23
+ default:
24
+ appendFlashMessage('success', '请求成功');
25
+ break;
26
+ }
27
+ }).on('ajax:error', function(xhr, status, error){
28
+ appendFlashMessage('danger', '请求失败');
29
+ });
30
+
31
+ function setSubMenusMargin() {
32
+ $('ol.sub-menus').css('margin-top', '0px');
33
+ $('ol.sub-menus:has("li")').css('margin-top', '10px');
34
+ }
35
+
36
+ function olTag() {
37
+ var tag = $('<ol></ol>');
38
+ tag.addClass('sub-menus');
39
+ return tag;
40
+ }
41
+
42
+ function addOrRemoveOl(li) {
43
+ if (li.find('li').length > 0) return;
44
+ var parent = li.parents('ol').first();
45
+ var hasOl = li.find('ol').length > 0;
46
+ if (parent.hasClass('parent-menus')) {
47
+ if (!hasOl) li.append(olTag());
48
+ li.removeData('subContainers');
49
+ } else if (parent.hasClass('sub-menus')) {
50
+ li.find('ol').remove();
51
+ }
52
+ }
53
+
54
+ sortMenuEle = $('ol.sortMenu');
55
+ sortGroup = sortMenuEle.sortable({
56
+ clear: true,
57
+ group: 'menu',
58
+ delay: 100,
59
+ handle: 'i.fa.fa-arrows',
60
+ onDrop: function ($item, container, _super) {
61
+ addOrRemoveOl($item);
62
+ setSubMenusMargin();
63
+
64
+ var data = sortGroup.sortable("serialize").get();
65
+ var jsonString = JSON.stringify(data, null, ' ');
66
+
67
+ formEle.find('input[name="state"]').val(jsonString);
68
+ formEle.submit();
69
+
70
+ _super($item, container);
71
+ },
72
+ isValidTarget: function ($item, container) {
73
+ // 有3个主菜单,就不能再添加了
74
+ if (container.el.hasClass('parent-menus') && container.items.length >= 3)
75
+ return false;
76
+ var hasChild = $item.find('li').length > 0;
77
+
78
+ if (container.el.hasClass('sub-menus')) {
79
+ // 如果菜单含有子菜单,就不能移动到其他子菜单里面
80
+ if (hasChild) return false;
81
+ // 子菜单最多只能 有五个
82
+ if (container.items.length >= 5) return false;
83
+ }
84
+
85
+ return true;
86
+ }
87
+ });
88
+ setSubMenusMargin();
89
+ }
90
+ })
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,23 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+ $(document).ready(function(){
4
+ if($('body[data-page="user_accounts_index"]')[0]) {
5
+ console.log('user_accounts_index')
6
+ $(document).on('ajax:success', function(data, status, xhr){
7
+ console.log(status)
8
+ switch(status.action){
9
+ case 'sync_users':
10
+ if(status.success){
11
+ Turbolinks.enableTransitionCache(true);
12
+ Turbolinks.visit(location.href);
13
+ Turbolinks.enableTransitionCache(false);
14
+ }
15
+ else
16
+ appendFlashMessage('danger', '同步失败,失败原因:' + status.msg);
17
+ break;
18
+ }
19
+ }).on('ajax:error', function(xhr, status, error){
20
+ appendFlashMessage('danger', '请求失败');
21
+ });
22
+ }
23
+ })
@@ -0,0 +1,31 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
16
+ @import "bootstrap-sprockets";
17
+ @import "bootstrap";
18
+ @import "font-awesome";
19
+
20
+ body { padding-top: 20px; padding-bottom: 20px; }
21
+ div#flash-message-box{
22
+ position: fixed;
23
+ top: 10px;
24
+ right: 10px;
25
+ z-index: 99999;
26
+ button.close[data-dismiss='alert']{
27
+ margin-left: 5px;
28
+ padding: 0px;
29
+ height: 1em;
30
+ }
31
+ }
@@ -0,0 +1,52 @@
1
+ // Place all the styles related to the Diymenus controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
4
+
5
+ ol.parent-menus{
6
+ list-style-type: none;
7
+ border: 2px solid #bebebe;
8
+ padding: 10px;
9
+ > li{
10
+ display: block;
11
+ border-style: solid;
12
+ border-width: 1px;
13
+ border-color: green;
14
+ border-bottom-style: none;
15
+ background-color: #fcfff4;
16
+ padding: 10px;
17
+ i.glyphicon{
18
+ margin-right: 10px;
19
+ }
20
+ &.dragged {
21
+ border-bottom-style: solid;
22
+ }
23
+ }
24
+ li:last-child{
25
+ border-bottom-style: solid;
26
+ }
27
+ }
28
+
29
+ ol.sub-menus{
30
+ list-style-type: none;
31
+ border: 2px solid #bebebe;
32
+ padding: 10px;
33
+ margin-left: 22px;
34
+ > li{
35
+ display: block;
36
+ border-style: solid;
37
+ border-width: 1px;
38
+ border-color: #747474;
39
+ border-bottom-style: none;
40
+ background-color: #f6f6f6;
41
+ padding: 10px;
42
+ i.glyphicon{
43
+ margin-right: 10px;
44
+ }
45
+ &.dragged {
46
+ border-bottom-style: solid;
47
+ }
48
+ }
49
+ li:last-child{
50
+ border-bottom-style: solid;
51
+ }
52
+ }
@@ -0,0 +1,26 @@
1
+ body.dragging, body.dragging * {
2
+ cursor: move !important;
3
+ }
4
+
5
+ .dragged {
6
+ position: absolute;
7
+ opacity: 0.5;
8
+ z-index: 2000;
9
+ }
10
+
11
+ ol li.placeholder {
12
+ position: relative;
13
+ /** More li styles **/
14
+ }
15
+ ol li.placeholder:before {
16
+ position: absolute;
17
+ content: "";
18
+ width: 0;
19
+ height: 0;
20
+ margin-top: -5px;
21
+ left: -5px;
22
+ top: -4px;
23
+ border: 5px solid transparent;
24
+ border-left-color: red;
25
+ border-right: none;
26
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ module WeixinPam
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,100 @@
1
+ require_dependency "weixin_pam/application_controller"
2
+
3
+ module WeixinPam
4
+ class DiymenusController < ApplicationController
5
+ before_action :set_public_account
6
+ before_action :set_diymenu, only: [:show, :edit, :update, :destroy]
7
+
8
+ # GET /diymenus
9
+ def index
10
+ @page_name = 'diymenus_index'
11
+ @diymenus = @public_account.diymenus
12
+ end
13
+
14
+ # GET /diymenus/new
15
+ def new
16
+ @diymenu = @public_account.diymenus.new
17
+ end
18
+
19
+ # GET /diymenus/1/edit
20
+ def edit
21
+ end
22
+
23
+ # POST /diymenus
24
+ def create
25
+ @diymenu = @public_account.diymenus.new(diymenu_params)
26
+
27
+ if @diymenu.save
28
+ redirect_to public_account_diymenus_path(@public_account), notice: '菜单创建成功.'
29
+ else
30
+ render :new
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /diymenus/1
35
+ def update
36
+ if @diymenu.update(diymenu_params)
37
+ flash[:notice] = '修改成功.'
38
+ end
39
+ render :edit
40
+ end
41
+
42
+ # DELETE /diymenus/1
43
+ def destroy
44
+ @diymenu.destroy
45
+ redirect_to public_account_diymenus_path(@public_account), notice: '删除菜单成功.'
46
+ end
47
+
48
+ def sort
49
+ state = JSON.parse(params[:state])
50
+ enabled_menus, disabled_menus = state
51
+
52
+ save_sorted_menus enabled_menus, true
53
+ save_sorted_menus disabled_menus, false
54
+ render json: { action: :sort }
55
+ end
56
+
57
+ def upload
58
+ result = @public_account.upload_menu
59
+ render json: {
60
+ action: :upload,
61
+ ok: result.ok?,
62
+ msg: result.cn_msg
63
+ }
64
+ end
65
+
66
+ def download
67
+ @public_account.download_menu!
68
+ flash[:notice] = '下载成功.'
69
+ render js: "Turbolinks.visit('#{public_account_diymenus_path(@public_account)}');"
70
+ rescue ApiError::FailedResult => ex
71
+ render json: { action: :download, error: "#{ex.message} - #{ex.result.cn_msg}" }
72
+ end
73
+
74
+ private
75
+
76
+ def save_sorted_menus(state, enabled)
77
+ Array(state).each_with_index do |parent_menu, i|
78
+ parent_id = parent_menu['id']
79
+ @public_account.diymenus.where(id: parent_id).update_all(parent_id: nil, is_show: enabled, sort: i)
80
+ Array(parent_menu['children']).flatten.each_with_index do |sub_menu, j|
81
+ @public_account.diymenus.where(id: sub_menu['id']).update_all(parent_id: parent_id, is_show: enabled, sort: j)
82
+ end
83
+ end
84
+ end
85
+
86
+ def set_public_account
87
+ @public_account = PublicAccount.find(params[:public_account_id])
88
+ end
89
+
90
+ # Use callbacks to share common setup or constraints between actions.
91
+ def set_diymenu
92
+ @diymenu = @public_account.diymenus.find(params[:id])
93
+ end
94
+
95
+ # Only allow a trusted parameter "white list" through.
96
+ def diymenu_params
97
+ params.require(:diymenu).permit(:button_type, :name, :key, :url, :is_show, :sort)
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,62 @@
1
+ require_dependency "weixin_pam/application_controller"
2
+
3
+ module WeixinPam
4
+ class PublicAccountsController < ApplicationController
5
+ before_action :set_public_account, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /public_accounts
8
+ def index
9
+ @public_accounts = PublicAccount.all
10
+ end
11
+
12
+ # GET /public_accounts/1
13
+ def show
14
+ end
15
+
16
+ # GET /public_accounts/new
17
+ def new
18
+ @public_account = PublicAccount.new
19
+ end
20
+
21
+ # GET /public_accounts/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /public_accounts
26
+ def create
27
+ @public_account = PublicAccount.new(public_account_params)
28
+
29
+ if @public_account.save
30
+ redirect_to @public_account, notice: '公众号创建成功.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /public_accounts/1
37
+ def update
38
+ if @public_account.update(public_account_params)
39
+ redirect_to @public_account, notice: '公众号修改成功.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /public_accounts/1
46
+ def destroy
47
+ @public_account.destroy
48
+ redirect_to public_accounts_url, notice: '成功删除公众号.'
49
+ end
50
+
51
+ private
52
+ # Use callbacks to share common setup or constraints between actions.
53
+ def set_public_account
54
+ @public_account = PublicAccount.find(params[:id])
55
+ end
56
+
57
+ # Only allow a trusted parameter "white list" through.
58
+ def public_account_params
59
+ params.require(:public_account).permit(:name, :app_id, :app_secret, :api_url, :api_token, :enabled, :host, :reply_class)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,76 @@
1
+ require_dependency "weixin_pam/application_controller"
2
+
3
+ module WeixinPam
4
+ class UserAccountsController < ApplicationController
5
+ before_action :set_public_account
6
+ before_action :set_user_account, only: [:show, :edit, :update, :destroy]
7
+
8
+ # GET /user_accounts
9
+ def index
10
+ @page_name = 'user_accounts_index'
11
+ @user_accounts = @public_account.user_accounts
12
+ end
13
+
14
+ # GET /user_accounts/1
15
+ def show
16
+ end
17
+
18
+ # GET /user_accounts/new
19
+ def new
20
+ @user_account = @public_account.user_accounts.new
21
+ end
22
+
23
+ # GET /user_accounts/1/edit
24
+ def edit
25
+ end
26
+
27
+ # POST /user_accounts
28
+ def create
29
+ @user_account = @public_account.user_accounts.new(user_account_params)
30
+
31
+ if @user_account.save
32
+ redirect_to @user_account, notice: 'User account was successfully created.'
33
+ else
34
+ render :new
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT /user_accounts/1
39
+ def update
40
+ if @user_account.update(user_account_params)
41
+ redirect_to @user_account, notice: 'User account was successfully updated.'
42
+ else
43
+ render :edit
44
+ end
45
+ end
46
+
47
+ # DELETE /user_accounts/1
48
+ def destroy
49
+ @user_account.destroy
50
+ redirect_to user_accounts_url, notice: 'User account was successfully destroyed.'
51
+ end
52
+
53
+ def sync
54
+ UserAccount.sync_from_server(@public_account)
55
+ render json: { action: 'sync_users', success: true }
56
+ rescue
57
+ render json: { action: 'sync_users', success: false, error: $!.message }
58
+ end
59
+
60
+ private
61
+
62
+ def set_public_account
63
+ @public_account = PublicAccount.find(params[:public_account_id])
64
+ end
65
+
66
+ # Use callbacks to share common setup or constraints between actions.
67
+ def set_user_account
68
+ @user_account = @public_account.user_accounts.find(params[:id])
69
+ end
70
+
71
+ # Only allow a trusted parameter "white list" through.
72
+ def user_account_params
73
+ params.require(:user_account).permit(:public_account_id, :uid, :nickname, :headshot, :subscribed)
74
+ end
75
+ end
76
+ end