pixelforce_recipes 3.9.1 → 4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +31 -9
  4. data/app/controllers/admin/api/admin_base_controller.rb +97 -0
  5. data/app/controllers/admin/api/v1/app_versions_controller.rb +28 -0
  6. data/app/controllers/admin/api/v1/available_modules_controller.rb +22 -0
  7. data/app/controllers/admin/api/v1/users_controller.rb +66 -0
  8. data/app/controllers/api/base_controller.rb +74 -0
  9. data/app/controllers/api/v1/health_check_controller.rb +11 -0
  10. data/app/controllers/application_controller.rb +10 -0
  11. data/app/controllers/auth/passwords_controller.rb +7 -0
  12. data/app/controllers/concerns/.keep +0 -0
  13. data/app/controllers/concerns/exception_handler.rb +54 -0
  14. data/app/controllers/concerns/request_header_handler.rb +35 -0
  15. data/app/controllers/concerns/response_handler.rb +31 -0
  16. data/app/controllers/pages_controller.rb +36 -0
  17. data/app/controllers/users_controller.rb +3 -0
  18. data/lib/pixelforce_recipes/engine.rb +5 -0
  19. data/lib/pixelforce_recipes/railtie.rb +4 -0
  20. data/lib/pixelforce_recipes/version.rb +1 -1
  21. data/lib/pixelforce_recipes.rb +7 -9
  22. data/lib/{pixelforce_recipes/capistrano_3_recipes → recipes/capistrano_recipes}/elbas.rb +1 -1
  23. data/lib/{pixelforce_recipes/capistrano_3_recipes → recipes/capistrano_recipes}/logrotate.rb +1 -1
  24. data/lib/{pixelforce_recipes/capistrano_3_recipes → recipes/capistrano_recipes}/sidekiq.rb +3 -3
  25. data/pixelforce_recipes.gemspec +3 -2
  26. data/recipes.rb +4 -0
  27. metadata +62 -38
  28. data/lib/pixelforce_recipes/legacy_recipes/base.rb +0 -24
  29. data/lib/pixelforce_recipes/legacy_recipes/logrotate.rb +0 -14
  30. data/lib/pixelforce_recipes/legacy_recipes/puma.rb +0 -26
  31. data/lib/pixelforce_recipes/legacy_recipes/resque.rb +0 -22
  32. data/lib/pixelforce_recipes/legacy_recipes/resque_scheduler.rb +0 -22
  33. data/lib/pixelforce_recipes/legacy_recipes/sidekiq.rb +0 -23
  34. data/lib/pixelforce_recipes/legacy_recipes/unicorn.rb +0 -29
  35. /data/lib/{pixelforce_recipes/capistrano_3_recipes → recipes/capistrano_recipes}/base.rb +0 -0
  36. /data/lib/{pixelforce_recipes/capistrano_3_recipes → recipes/capistrano_recipes}/puma.rb +0 -0
  37. /data/lib/{pixelforce_recipes/capistrano_3_recipes → recipes/capistrano_recipes}/resque.rb +0 -0
  38. /data/lib/{pixelforce_recipes/capistrano_3_recipes → recipes/capistrano_recipes}/resque_scheduler.rb +0 -0
  39. /data/lib/{pixelforce_recipes/capistrano_3_recipes → recipes/capistrano_recipes}/supervisor.rb +0 -0
  40. /data/lib/{pixelforce_recipes/capistrano_3_recipes → recipes/capistrano_recipes}/unicorn.rb +0 -0
  41. /data/lib/{pixelforce_recipes → recipes}/templates/logrotate.erb +0 -0
  42. /data/lib/{pixelforce_recipes → recipes}/templates/nginx_config.erb +0 -0
  43. /data/lib/{pixelforce_recipes → recipes}/templates/nginx_puma_config.erb +0 -0
  44. /data/lib/{pixelforce_recipes → recipes}/templates/puma.rb.erb +0 -0
  45. /data/lib/{pixelforce_recipes → recipes}/templates/puma_systemd.erb +0 -0
  46. /data/lib/{pixelforce_recipes → recipes}/templates/resque_init.erb +0 -0
  47. /data/lib/{pixelforce_recipes → recipes}/templates/resque_scheduler_init.erb +0 -0
  48. /data/lib/{pixelforce_recipes → recipes}/templates/resque_scheduler_supervisor.erb +0 -0
  49. /data/lib/{pixelforce_recipes → recipes}/templates/resque_supervisor.erb +0 -0
  50. /data/lib/{pixelforce_recipes → recipes}/templates/sidekiq_init.erb +0 -0
  51. /data/lib/{pixelforce_recipes → recipes}/templates/sidekiq_supervisor.erb +0 -0
  52. /data/lib/{pixelforce_recipes → recipes}/templates/sidekiq_systemd.erb +0 -0
  53. /data/lib/{pixelforce_recipes → recipes}/templates/supervisor.erb +0 -0
  54. /data/lib/{pixelforce_recipes → recipes}/templates/unicorn_init.erb +0 -0
  55. /data/lib/{pixelforce_recipes → recipes}/templates/unicorn_supervisor.erb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9cff0056ec04564614b530821cea115401163b92f708e8c32525605eb31aa3c
4
- data.tar.gz: 2086b47b48f2d442fd18bce9479fa5e0420cb264eb348718c7358ba732544890
3
+ metadata.gz: fdb07c77204b3a75b2c73d4322c0d27fdfc2937cafe090283d190645d7616346
4
+ data.tar.gz: b28395f2db9c1a2e049cb666a6fb54c4e5e099f15fcbdb81399c98c22678ac42
5
5
  SHA512:
6
- metadata.gz: 05d6c378fd77b36c56a3de97e53572e6f2e836576ce288e0ec3f921a3fb99f3eda86df0dbcd6007f2cbdeae49784f9459ddc94686d388422504edeeedf857525
7
- data.tar.gz: 50098a0e50ce607ea5d5feaecf939e1695b3311090bb048cd8f1d2946c217bb430cb580b71306dcf7afbaacd9f53e6c2e161acbb8a1498444bdcda08b6baae6f
6
+ metadata.gz: c126f24f3eeec6f4426a21ae7cb0808607c6e37d5044e305ead5cf358232c4c024dbdc6edd70248f24ee7a66d4d1722cccc7b43086487edfd6b0c1a05175dc22
7
+ data.tar.gz: e93d0a39728da785197ef83ebe7937061e5b35ac5f4b5e3df76ce5dffc44682b406587de2afe9541e24fcffdc85fd2218657c33fe068424b3735ab7323739386
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  /pkg
2
+ .DS_Store
data/Gemfile.lock CHANGED
@@ -1,26 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pixelforce_recipes (3.1)
4
+ pixelforce_recipes (3.9.2)
5
5
  capistrano (> 2.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- airbrussh (1.4.0)
10
+ airbrussh (1.4.1)
11
11
  sshkit (>= 1.6.1, != 1.7.0)
12
- capistrano (3.16.0)
12
+ aws-eventstream (1.2.0)
13
+ aws-partitions (1.628.0)
14
+ aws-sdk-autoscaling (1.80.0)
15
+ aws-sdk-core (~> 3, >= 3.127.0)
16
+ aws-sigv4 (~> 1.1)
17
+ aws-sdk-core (3.145.0)
18
+ aws-eventstream (~> 1, >= 1.0.2)
19
+ aws-partitions (~> 1, >= 1.525.0)
20
+ aws-sigv4 (~> 1.1)
21
+ jmespath (~> 1, >= 1.6.1)
22
+ aws-sdk-ec2 (1.331.0)
23
+ aws-sdk-core (~> 3, >= 3.127.0)
24
+ aws-sigv4 (~> 1.1)
25
+ aws-sigv4 (1.5.1)
26
+ aws-eventstream (~> 1, >= 1.0.2)
27
+ capistrano (3.17.1)
13
28
  airbrussh (>= 1.0.0)
14
29
  i18n
15
30
  rake (>= 10.0.0)
16
31
  sshkit (>= 1.9.0)
17
- concurrent-ruby (1.1.9)
32
+ concurrent-ruby (1.1.10)
18
33
  diff-lcs (1.2.5)
19
- i18n (1.8.11)
34
+ elbas (3.0.4)
35
+ aws-sdk-autoscaling (~> 1)
36
+ aws-sdk-ec2 (~> 1)
37
+ capistrano (> 3)
38
+ i18n (1.12.0)
20
39
  concurrent-ruby (~> 1.0)
21
- net-scp (3.0.0)
22
- net-ssh (>= 2.6.5, < 7.0.0)
23
- net-ssh (6.1.0)
40
+ jmespath (1.6.1)
41
+ net-scp (1.2.1)
42
+ net-ssh (>= 2.6.5)
43
+ net-ssh (7.0.1)
24
44
  rake (13.0.1)
25
45
  rspec (3.5.0)
26
46
  rspec-core (~> 3.5.0)
@@ -35,7 +55,7 @@ GEM
35
55
  diff-lcs (>= 1.2.0, < 2.0)
36
56
  rspec-support (~> 3.5.0)
37
57
  rspec-support (3.5.0)
38
- sshkit (1.21.2)
58
+ sshkit (1.21.3)
39
59
  net-scp (>= 1.1.2)
40
60
  net-ssh (>= 2.8.0)
41
61
 
@@ -43,6 +63,8 @@ PLATFORMS
43
63
  ruby
44
64
 
45
65
  DEPENDENCIES
66
+ bundler (~> 2.1)
67
+ elbas
46
68
  pixelforce_recipes!
47
69
  rake (~> 13.0)
48
70
  rspec (~> 3.0)
@@ -0,0 +1,97 @@
1
+ module Admin
2
+ module Api
3
+ class AdminBaseController < ApplicationController
4
+ include DeviseTokenAuth::Concerns::SetUserByToken
5
+ include ResponseHandler
6
+ include RequestHeaderHandler
7
+ include ExceptionHandler
8
+
9
+ before_action :authenticate_admin_user!
10
+ before_action :format_params
11
+ before_action :prepare_pagination_params
12
+
13
+ def authenticate_admin_user!
14
+ authenticate_admin_api_v1_admin_user!
15
+ end
16
+
17
+ private
18
+
19
+ def render_error(status, message, validation_errors = nil)
20
+ errors = {}
21
+ errors['root'] = { 'serverError': message } if message.present?
22
+ if validation_errors.is_a?(ActiveModel::Errors)
23
+ data = {}
24
+ validation_errors.to_hash.each do |key, value|
25
+ data[key] = value.join(', ')
26
+ end
27
+
28
+ errors.merge!(data) if data.present?
29
+ end
30
+
31
+ response = {
32
+ errors:
33
+ }
34
+ render status:, json: response
35
+ end
36
+
37
+ def set_response_format
38
+ if request.format.to_s != 'text/csv'
39
+ request.format = :json
40
+ self.content_type = 'application/json'
41
+ end
42
+ end
43
+
44
+ def pagination_headers(collection, item_name)
45
+ headers['Content-Range'] = "#{item_name} #{collection.offset_value}-#{collection.offset_value + collection.limit_value - 1}/#{collection.total_count}"
46
+ headers['Access-Control-Expose-Headers'] = 'Content-Range'
47
+ end
48
+
49
+ def pagination_headers_for_dropdown(item_name)
50
+ headers['Content-Range'] = "#{item_name} 0-999/1000"
51
+ headers['Access-Control-Expose-Headers'] = 'Content-Range'
52
+ end
53
+
54
+ def default_per_page
55
+ 10
56
+ end
57
+
58
+ def keywords
59
+ keyword = params[:filter].try(:[], :keyword)
60
+ if keyword.present?
61
+ @keywords = keyword.split(/,| */).reject(&:blank?).map { |value| "%#{value.strip}%" }
62
+ else
63
+ []
64
+ end
65
+ end
66
+
67
+ def export_resource_csv(resources, headers)
68
+ resources = resources.except(:limit, :offset)
69
+ table_name = resources.table_name
70
+ csv_data = CSV.generate(headers: true) do |csv|
71
+ csv << headers.map(&:titleize)
72
+ resources.find_each do |resource|
73
+ csv << headers.map { |header| resource.send(header.parameterize.to_sym) }
74
+ end
75
+ end
76
+ send_data csv_data, filename: "#{table_name}-#{Date.today}.csv"
77
+ end
78
+
79
+ def prepare_pagination_params
80
+ if params[:range].present? && params[:range].is_a?(Array) && params[:range].length == 2
81
+ beginning_offset = params[:range][0].to_i
82
+ end_offset = params[:range][1].to_i
83
+ per_page = end_offset - beginning_offset + 1
84
+ params[:perPage] = per_page
85
+ params[:page] = (beginning_offset / per_page) + 1
86
+ end
87
+ end
88
+
89
+ def format_params
90
+ if request.method_symbol == :get
91
+ params[:filter] = ActionController::Parameters.new(JSON.parse(params[:filter])) if params[:filter].present? && params[:filter].is_a?(String)
92
+ params[:range] = JSON.parse(params[:range]) if params[:range].present? && params[:range].is_a?(String)
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,28 @@
1
+ module Admin
2
+ module Api
3
+ module V1
4
+ class AppVersionsController < Admin::Api::AdminBaseController
5
+ def show
6
+ app_version = AppVersion.last
7
+ app_version ||= AppVersion.create!
8
+ render json: app_version.as_json(only: %i[id ios_minimum_version_number android_minimum_version_number])
9
+ end
10
+
11
+ def update
12
+ app_version = AppVersion.find(params[:id])
13
+ if app_version.update(app_version_params)
14
+ render json: app_version.as_json(only: %i[id ios_minimum_version_number android_minimum_version_number])
15
+ else
16
+ render_error(400, nil, app_version.errors)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def app_version_params
23
+ params.permit(:ios_minimum_version_number, :android_minimum_version_number)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ module Admin
2
+ module Api
3
+ module V1
4
+ class AvailableModulesController < AdminBaseController
5
+ def index
6
+ render json: [
7
+ {
8
+ "id": 1,
9
+ "name": 'Dashboard',
10
+ "path": '/dashboard'
11
+ },
12
+ {
13
+ "id": 2,
14
+ "name": 'Users',
15
+ "path": '/users'
16
+ }
17
+ ]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,66 @@
1
+ module Admin
2
+ module Api
3
+ module V1
4
+ class UsersController < Admin::Api::AdminBaseController
5
+ def index
6
+ users = User.all.order(id: :desc).page(params[:page]).per(params[:perPage] || default_per_page)
7
+ if keywords.present?
8
+ users = users.where('first_name ILIKE ANY ( array[?] ) OR last_name ILIKE ANY ( array[?] ) OR email ILIKE ANY ( array[?] ) or id = ?', @keywords, @keywords, @keywords, @keywords.first.delete('%').to_i)
9
+ end
10
+ pagination_headers(users, 'users')
11
+
12
+ respond_to do |format|
13
+ format.json do
14
+ render json: users.as_json(only: %i[id first_name last_name email], methods: :status, for_admin: true)
15
+ end
16
+ format.csv do
17
+ export_resource_csv(users, %w[id first_name last_name status email])
18
+ end
19
+ end
20
+ end
21
+
22
+ def create
23
+ user = User.new user_params
24
+ if user.save
25
+ render json: user.as_json(only: %i[id first_name last_name email dob gender])
26
+ else
27
+ render_error(400, nil, user.errors)
28
+ end
29
+ end
30
+
31
+ def show
32
+ @user = User.find(params[:id])
33
+ render json: @user.as_json(only: %i[id first_name last_name email dob gender])
34
+ end
35
+
36
+ def update
37
+ user = User.find(params[:id])
38
+ if user.update(user_params)
39
+ render json: user.as_json(only: %i[id], for_admin: true)
40
+ else
41
+ render_error(400, nil, user.errors)
42
+ end
43
+ end
44
+
45
+ def destroy
46
+ user = User.find(params[:id])
47
+ user.destroy
48
+
49
+ render_success
50
+ end
51
+
52
+ def genders
53
+ pagination_headers_for_dropdown('genders')
54
+ render json: User.genders.keys.map { |k| { id: k, name: k } }
55
+ end
56
+
57
+ private
58
+
59
+ def user_params
60
+ permitted = params.permit(:first_name, :last_name, :dob, :email, :gender, :password)
61
+ permitted.presence || raise(ActionController::ParameterMissing, 'Parameters missing')
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,74 @@
1
+ module Api
2
+ class BaseController < ApplicationController
3
+ include DeviseTokenAuth::Concerns::SetUserByToken
4
+ include ResponseHandler
5
+ include RequestHeaderHandler
6
+ include ExceptionHandler
7
+
8
+ protect_from_forgery with: :null_session
9
+
10
+ before_action :authenticate_user!
11
+ before_action :minimum_version_check!
12
+ before_action :set_user_timezone
13
+ before_action :create_user_devices!
14
+
15
+ after_action :track_request
16
+
17
+ private
18
+
19
+ def create_user_devices!
20
+ if current_user.present? && device_headers[:device_token].present?
21
+ user_device = UserDevice.find_or_initialize_by(device_token: device_headers[:device_token])
22
+
23
+ if user_device.persisted? && user_device.user_id != current_user.id
24
+ user_device.destroy!
25
+ user_device = UserDevice.new(device_token: device_headers[:device_token])
26
+ end
27
+
28
+ user_device.user_id = current_user.id
29
+ user_device.app_version = device_headers[:app_version]
30
+ user_device.platform = device_headers[:platform]
31
+ user_device.device_model = device_headers[:device_model]
32
+ user_device.os_version = device_headers[:os_version]
33
+ user_device.app_build_version = device_headers[:app_build_version]
34
+ user_device.save!
35
+ end
36
+ end
37
+
38
+ def set_user_timezone
39
+ if user_timezone && current_user && current_user.timezone != user_timezone
40
+ current_user.update(timezone: user_timezone)
41
+ end
42
+ end
43
+
44
+ def user_timezone
45
+ @user_timezone ||= device_headers[:user_timezone]
46
+ end
47
+
48
+ def minimum_version_check!
49
+ app_version = device_headers[:app_version]
50
+ platform = device_headers[:platform]
51
+
52
+ if app_version.present? && platform.present?
53
+ current_app_version = AppVersion.order(id: :desc).first
54
+
55
+ if current_app_version.present?
56
+ minimum_version = current_app_version.minimum_version(platform)
57
+
58
+ if minimum_version.present? && Gem::Version.new(app_version) < Gem::Version.new(minimum_version)
59
+ render_error(426, I18n.t('api.errors.upgrade_app_version'))
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ def track_request
66
+ api_version = request.path.split('/')[2]
67
+ ahoy.track "ApiRequest::#{api_version}", {
68
+ params: request.filtered_parameters,
69
+ url: request.original_url,
70
+ response: response.status
71
+ }
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,11 @@
1
+ module Api
2
+ module V1
3
+ class HealthCheckController < Api::BaseController
4
+ skip_before_action :authenticate_user!
5
+
6
+ def index
7
+ render_success
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :null_session
3
+ skip_before_action :verify_authenticity_token, if: :json_request?
4
+
5
+ private
6
+
7
+ def json_request?
8
+ request.format.json?
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ class Auth::PasswordsController < Devise::PasswordsController
2
+ protected
3
+
4
+ def after_resetting_password_path_for(_resource)
5
+ reset_password_success_path
6
+ end
7
+ end
File without changes
@@ -0,0 +1,54 @@
1
+ module ExceptionHandler
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ rescue_from StandardError do |e|
6
+ notify_error(e, airbrake_notify: true)
7
+ render_error(500, I18n.t('errors.server_error'))
8
+ end
9
+
10
+ rescue_from ActiveRecord::RecordNotFound do |e|
11
+ notify_error(e)
12
+ render_error(404, I18n.t('errors.record_not_found'))
13
+ end
14
+
15
+ rescue_from ActiveRecord::RecordInvalid do |e|
16
+ notify_error(e)
17
+ render_error(422, I18n.t('errors.record_invalid'))
18
+ end
19
+
20
+ rescue_from ActionController::ParameterMissing do |e|
21
+ notify_error(e)
22
+ render_error(404, I18n.t('errors.record_invalid'))
23
+ end
24
+
25
+ rescue_from JSON::ParserError do |e|
26
+ notify_error(e)
27
+ render_error(404, I18n.t('errors.record_invalid'))
28
+ end
29
+
30
+ rescue_from ActiveRecord::RecordNotUnique do |e|
31
+ notify_error(e)
32
+ render_error(404, I18n.t('errors.record_not_unique'))
33
+ end
34
+
35
+ private
36
+
37
+ def notify_error(error, airbrake_notify: false)
38
+ airbrake_notify(error) if airbrake_notify
39
+ raise_error(error)
40
+ end
41
+
42
+ def raise_error(error)
43
+ if Rails.env.test? || Rails.env.development?
44
+ raise error
45
+ end
46
+ end
47
+
48
+ def airbrake_notify(error)
49
+ if Rails.env.production? || Rails.env.staging?
50
+ Airbrake.notify(error)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+ module RequestHeaderHandler
2
+ extend ActiveSupport::Concern
3
+
4
+ def cloudfront_headers
5
+ @cloudfront_headers ||= {
6
+ cloudfront_viewer_address: request.headers['CloudFront-Viewer-Address'],
7
+ cloudfront_viewer_country: request.headers['CloudFront-Viewer-Country'],
8
+ cloudfront_is_ios_viewer: request.headers['CloudFront-Is-Ios-Viewer'],
9
+ cloudfront_is_tablet_viewer: request.headers['CloudFront-Is-Tablet-Viewer'],
10
+ cloudfront_viewer_country_name: request.headers['CloudFront-Viewer-Country-Name'],
11
+ cloudfront_is_mobile_viewer: request.headers['CloudFront-Is-Mobile-Viewer'],
12
+ cloudfront_is_smarttv_viewer: request.headers['CloudFront-Is-Smarttv-Viewer'],
13
+ cloudfront_viewer_country_region: request.headers['CloudFront-Viewer-Country-Region'],
14
+ cloudfront_is_android_viewer: request.headers['CloudFront-Is-Android-Viewer'],
15
+ cloudfront_viewer_country_region_name: request.headers['CloudFront-Viewer-Country-Region-Name'],
16
+ cloudfront_viewer_city: request.headers['CloudFront-Viewer-City'],
17
+ cloudfront_viewer_latitude: request.headers['CloudFront-Viewer-Latitude'],
18
+ cloudfront_viewer_longitude: request.headers['CloudFront-Viewer-Longitude'],
19
+ cloudfront_viewer_postal_code: request.headers['CloudFront-Viewer-Postal-Code'],
20
+ cloudfront_is_desktop_viewer: request.headers['CloudFront-Is-Desktop-Viewer']
21
+ }
22
+ end
23
+
24
+ def device_headers
25
+ @device_headers ||= {
26
+ app_version: request.headers['HTTP_X_APP_VERSION'],
27
+ platform: request.headers['HTTP_X_PLATFORM'],
28
+ device_model: request.headers['HTTP_X_DEVICE_MODEL'],
29
+ os_version: request.headers['HTTP_X_OS_VERSION'],
30
+ app_build_version: request.headers['HTTP_X_APP_BUILD_VERSION'],
31
+ device_token: request.headers['HTTP_X_DEVICE_TOKEN'],
32
+ user_timezone: request.headers['HTTP_X_USER_TIMEZONE']
33
+ }
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ module ResponseHandler
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_action :config_default_response_settings
6
+ end
7
+
8
+ def config_default_response_settings
9
+ set_response_format
10
+ end
11
+
12
+ def set_response_format
13
+ self.content_type = 'application/json'
14
+ end
15
+
16
+ def render_success
17
+ render json: {}, status: :ok
18
+ end
19
+
20
+ def render_no_content
21
+ render json: {}, status: :no_content
22
+ end
23
+
24
+ def render_error(status, message, data = nil)
25
+ response = {
26
+ errors: [message]
27
+ }
28
+ response = response.merge(data) if data
29
+ render json: response, status: status
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ class PagesController < ApplicationController
2
+ layout 'rails_template'
3
+
4
+ def index; end
5
+
6
+ def fonts_page; end
7
+
8
+ def spinners_page; end
9
+
10
+ def animations_page; end
11
+
12
+ def global_notice_page
13
+ flash.now[:notice] = 'Here is a notice flash message!'
14
+ flash.now[:success] = 'Here is a success flash message!'
15
+ flash.now[:warning] = 'Here is a warning flash message!'
16
+ flash.now[:error] = 'Here is an error flash message!'
17
+ end
18
+
19
+ def new
20
+ @template_model = TemplateModel.new
21
+ end
22
+
23
+ def create
24
+ @template_model = TemplateModel.new(template_model_params)
25
+ if @template_model.save
26
+ flash[:success] = 'Template has been created successfully.'
27
+ redirect_to new_template_model_path
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ def template_model_params
34
+ params.require(:template_model).permit(:first_name, :last_name, :email, :dob, :gender, :message, :level, :active)
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ class UsersController < ApplicationController
2
+ def reset_password_success; end
3
+ end
@@ -0,0 +1,5 @@
1
+ module PixelforceRecipes
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace PixelforceRecipes
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module PixelforceRecipes
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module PixelforceRecipes
2
- VERSION = '3.9.1'
2
+ VERSION = '4.0'
3
3
  end
@@ -1,10 +1,8 @@
1
- require "pixelforce_recipes/version"
2
- require "capistrano"
1
+ require 'rails'
2
+ require_relative 'pixelforce_recipes/railtie'
3
+ require_relative 'pixelforce_recipes/engine'
4
+ require_relative 'pixelforce_recipes/version'
3
5
 
4
- if defined?(Capistrano::VERSION)
5
- if Capistrano::VERSION.to_s.split('.').first.to_i >= 3
6
- Dir[File.expand_path("#{File.dirname(__FILE__)}/pixelforce_recipes/capistrano_3_recipes/*.rb")].each {|file| require file }
7
- else
8
- Dir[File.expand_path("#{File.dirname(__FILE__)}/pixelforce_recipes/legacy_recipes/*.rb")].each {|file| require file }
9
- end
10
- end
6
+ module PixelforceRecipes
7
+
8
+ end
@@ -1,7 +1,7 @@
1
1
  namespace :elbas do
2
2
  desc 'Sync files before creating AMI'
3
3
  task :sync do
4
- on roles(:web) do
4
+ on roles(:app) do
5
5
  execute "sync"
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  namespace :logrotate do
2
2
  desc "Setup logrotate configuration for this application"
3
3
  task :setup do
4
- on roles(:web) do
4
+ on roles(:app) do
5
5
  template "logrotate.erb", "/tmp/logrotate"
6
6
  sudo "mv /tmp/logrotate /etc/logrotate.d/#{fetch(:application)}"
7
7
  sudo "chown root:root /etc/logrotate.d/#{fetch(:application)}"
@@ -3,7 +3,7 @@ namespace :sidekiq do
3
3
 
4
4
  namespace :systemd do
5
5
  task :setup do
6
- on roles(:web) do
6
+ on roles(:app) do
7
7
  template 'sidekiq_systemd.erb', '/tmp/sidekiq.service'
8
8
  sudo 'mv /tmp/sidekiq.service /etc/systemd/system/sidekiq.service'
9
9
  sudo 'systemctl daemon-reload'
@@ -13,13 +13,13 @@ namespace :sidekiq do
13
13
  end
14
14
 
15
15
  task :unload do
16
- on roles(:web) do
16
+ on roles(:app) do
17
17
  sudo 'systemctl kill -s TSTP sidekiq'
18
18
  end
19
19
  end
20
20
 
21
21
  task :restart do
22
- on roles(:web) do
22
+ on roles(:app) do
23
23
  sudo 'systemctl restart sidekiq'
24
24
  end
25
25
  end
@@ -19,8 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "bundler", "~> 2.1"
23
23
  spec.add_development_dependency "rake", "~> 13.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
- spec.add_dependency(%q<capistrano>, ["> 2.0.0"])
25
+ spec.add_development_dependency "elbas"
26
+ spec.add_dependency(%q<capistrano>, ["> 3.0.0"])
26
27
  end
data/recipes.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "pixelforce_recipes/version"
2
+ require "capistrano"
3
+
4
+ Dir[File.expand_path("#{File.dirname(__FILE__)}/recipes/capistrano_recipes/*.rb")].each {|file| require file }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixelforce_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.1
4
+ version: '4.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Zhang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-25 00:00:00.000000000 Z
11
+ date: 2024-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.12'
19
+ version: '2.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.12'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: elbas
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: capistrano
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">"
60
74
  - !ruby/object:Gem::Version
61
- version: 2.0.0
75
+ version: 3.0.0
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ">"
67
81
  - !ruby/object:Gem::Version
68
- version: 2.0.0
82
+ version: 3.0.0
69
83
  description: Write a longer description or delete this line.
70
84
  email:
71
85
  - bzbnhang@gmail.com
@@ -80,42 +94,52 @@ files:
80
94
  - LICENSE.txt
81
95
  - README.md
82
96
  - Rakefile
97
+ - app/controllers/admin/api/admin_base_controller.rb
98
+ - app/controllers/admin/api/v1/app_versions_controller.rb
99
+ - app/controllers/admin/api/v1/available_modules_controller.rb
100
+ - app/controllers/admin/api/v1/users_controller.rb
101
+ - app/controllers/api/base_controller.rb
102
+ - app/controllers/api/v1/health_check_controller.rb
103
+ - app/controllers/application_controller.rb
104
+ - app/controllers/auth/passwords_controller.rb
105
+ - app/controllers/concerns/.keep
106
+ - app/controllers/concerns/exception_handler.rb
107
+ - app/controllers/concerns/request_header_handler.rb
108
+ - app/controllers/concerns/response_handler.rb
109
+ - app/controllers/pages_controller.rb
110
+ - app/controllers/users_controller.rb
83
111
  - bin/console
84
112
  - bin/setup
85
113
  - lib/pixelforce_recipes.rb
86
- - lib/pixelforce_recipes/capistrano_3_recipes/base.rb
87
- - lib/pixelforce_recipes/capistrano_3_recipes/elbas.rb
88
- - lib/pixelforce_recipes/capistrano_3_recipes/logrotate.rb
89
- - lib/pixelforce_recipes/capistrano_3_recipes/puma.rb
90
- - lib/pixelforce_recipes/capistrano_3_recipes/resque.rb
91
- - lib/pixelforce_recipes/capistrano_3_recipes/resque_scheduler.rb
92
- - lib/pixelforce_recipes/capistrano_3_recipes/sidekiq.rb
93
- - lib/pixelforce_recipes/capistrano_3_recipes/supervisor.rb
94
- - lib/pixelforce_recipes/capistrano_3_recipes/unicorn.rb
95
- - lib/pixelforce_recipes/legacy_recipes/base.rb
96
- - lib/pixelforce_recipes/legacy_recipes/logrotate.rb
97
- - lib/pixelforce_recipes/legacy_recipes/puma.rb
98
- - lib/pixelforce_recipes/legacy_recipes/resque.rb
99
- - lib/pixelforce_recipes/legacy_recipes/resque_scheduler.rb
100
- - lib/pixelforce_recipes/legacy_recipes/sidekiq.rb
101
- - lib/pixelforce_recipes/legacy_recipes/unicorn.rb
102
- - lib/pixelforce_recipes/templates/logrotate.erb
103
- - lib/pixelforce_recipes/templates/nginx_config.erb
104
- - lib/pixelforce_recipes/templates/nginx_puma_config.erb
105
- - lib/pixelforce_recipes/templates/puma.rb.erb
106
- - lib/pixelforce_recipes/templates/puma_systemd.erb
107
- - lib/pixelforce_recipes/templates/resque_init.erb
108
- - lib/pixelforce_recipes/templates/resque_scheduler_init.erb
109
- - lib/pixelforce_recipes/templates/resque_scheduler_supervisor.erb
110
- - lib/pixelforce_recipes/templates/resque_supervisor.erb
111
- - lib/pixelforce_recipes/templates/sidekiq_init.erb
112
- - lib/pixelforce_recipes/templates/sidekiq_supervisor.erb
113
- - lib/pixelforce_recipes/templates/sidekiq_systemd.erb
114
- - lib/pixelforce_recipes/templates/supervisor.erb
115
- - lib/pixelforce_recipes/templates/unicorn_init.erb
116
- - lib/pixelforce_recipes/templates/unicorn_supervisor.erb
114
+ - lib/pixelforce_recipes/engine.rb
115
+ - lib/pixelforce_recipes/railtie.rb
117
116
  - lib/pixelforce_recipes/version.rb
117
+ - lib/recipes/capistrano_recipes/base.rb
118
+ - lib/recipes/capistrano_recipes/elbas.rb
119
+ - lib/recipes/capistrano_recipes/logrotate.rb
120
+ - lib/recipes/capistrano_recipes/puma.rb
121
+ - lib/recipes/capistrano_recipes/resque.rb
122
+ - lib/recipes/capistrano_recipes/resque_scheduler.rb
123
+ - lib/recipes/capistrano_recipes/sidekiq.rb
124
+ - lib/recipes/capistrano_recipes/supervisor.rb
125
+ - lib/recipes/capistrano_recipes/unicorn.rb
126
+ - lib/recipes/templates/logrotate.erb
127
+ - lib/recipes/templates/nginx_config.erb
128
+ - lib/recipes/templates/nginx_puma_config.erb
129
+ - lib/recipes/templates/puma.rb.erb
130
+ - lib/recipes/templates/puma_systemd.erb
131
+ - lib/recipes/templates/resque_init.erb
132
+ - lib/recipes/templates/resque_scheduler_init.erb
133
+ - lib/recipes/templates/resque_scheduler_supervisor.erb
134
+ - lib/recipes/templates/resque_supervisor.erb
135
+ - lib/recipes/templates/sidekiq_init.erb
136
+ - lib/recipes/templates/sidekiq_supervisor.erb
137
+ - lib/recipes/templates/sidekiq_systemd.erb
138
+ - lib/recipes/templates/supervisor.erb
139
+ - lib/recipes/templates/unicorn_init.erb
140
+ - lib/recipes/templates/unicorn_supervisor.erb
118
141
  - pixelforce_recipes.gemspec
142
+ - recipes.rb
119
143
  homepage: https://github.com/BenZhang/pixelforce_recipes
120
144
  licenses:
121
145
  - MIT
@@ -135,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
159
  - !ruby/object:Gem::Version
136
160
  version: '0'
137
161
  requirements: []
138
- rubygems_version: 3.0.6
162
+ rubygems_version: 3.2.33
139
163
  signing_key:
140
164
  specification_version: 4
141
165
  summary: Write a short summary, because Rubygems requires one.
@@ -1,24 +0,0 @@
1
- if Capistrano::Configuration.instance(false)
2
-
3
- Capistrano::Configuration.instance(true).load do |instance|
4
-
5
- def template(from, to)
6
- erb = File.read(File.expand_path("../../templates/#{from}", __FILE__))
7
- put ERB.new(erb).result(binding), to
8
- end
9
-
10
- def set_default(name, *args, &block)
11
- set(name, *args, &block) unless exists?(name)
12
- end
13
-
14
- namespace :deploy do
15
- desc "Install everything onto the server"
16
- task :install do
17
- run "#{sudo} apt-get -y update"
18
- run "#{sudo} apt-get -y install curl git-core python-software-properties build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion"
19
- end
20
- end
21
-
22
- end
23
-
24
- end
@@ -1,14 +0,0 @@
1
- if Capistrano::Configuration.instance(false)
2
-
3
- Capistrano::Configuration.instance(true).load do |instance|
4
-
5
- namespace :logrotate do
6
-
7
- desc "Setup logrotate configuration for this application"
8
- task :setup, roles: :app do
9
- template "logrotate.erb", "/tmp/logrotate"
10
- run "#{sudo} mv /tmp/logrotate /etc/logrotate.d/#{application}"
11
- end
12
- end
13
- end
14
- end
@@ -1,26 +0,0 @@
1
- if Capistrano::Configuration.instance(false)
2
-
3
- Capistrano::Configuration.instance(true).load do |instance|
4
-
5
- namespace :puma do
6
-
7
- desc "Setup puma configuration for this application"
8
- task :setup, roles: :web do
9
- template "puma_init.erb", "/tmp/puma"
10
- run "#{sudo} mv /tmp/puma /etc/init.d/#{application}"
11
- run "#{sudo} chmod +x /etc/init.d/#{application}"
12
- run "#{sudo} update-rc.d #{application} defaults"
13
- template "nginx_puma_config.erb", "/tmp/nginx_puma_config"
14
- run "#{sudo} mv /tmp/nginx_puma_config /etc/nginx/sites-enabled/#{application}"
15
- end
16
- # after "deploy:setup", "nginx:setup"
17
-
18
- %w[start stop restart].each do |command|
19
- desc "#{command} puma"
20
- task command, roles: :web do
21
- run "/etc/init.d/#{application} #{command}"
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,22 +0,0 @@
1
- if Capistrano::Configuration.instance(false)
2
- Capistrano::Configuration.instance(true).load do |instance|
3
- namespace :resque do
4
- desc "Install resque"
5
-
6
- desc "Setup resque configuration for this application"
7
- task :setup, roles: :resque do
8
- template "resque_init.erb", "/tmp/resque"
9
- run "#{sudo} mv /tmp/resque /etc/init.d/resque"
10
- run "#{sudo} chmod +x /etc/init.d/resque"
11
- run "#{sudo} update-rc.d resque defaults"
12
- end
13
-
14
- %w[start stop restart].each do |command|
15
- desc "#{command} resque"
16
- task command do
17
- run "/etc/init.d/resque #{command}"
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- if Capistrano::Configuration.instance(false)
2
- Capistrano::Configuration.instance(true).load do |instance|
3
- namespace :resque_scheduler do
4
- desc "Install resque scheduler"
5
-
6
- desc "Setup resque scheduler configuration for this application"
7
- task :setup, roles: :resque do
8
- template "resque_scheduler_init.erb", "/tmp/resque_scheduler"
9
- run "#{sudo} mv /tmp/resque_scheduler /etc/init.d/resque_scheduler"
10
- run "#{sudo} chmod +x /etc/init.d/resque_scheduler"
11
- run "#{sudo} update-rc.d resque_scheduler defaults"
12
- end
13
-
14
- %w[start stop restart].each do |command|
15
- desc "#{command} resque scheduler"
16
- task command do
17
- run "/etc/init.d/resque_scheduler #{command}"
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,23 +0,0 @@
1
- if Capistrano::Configuration.instance(false)
2
- Capistrano::Configuration.instance(true).load do |instance|
3
- namespace :sidekiq do
4
- desc "Install sidekiq"
5
-
6
- desc "Setup sidekiq configuration for this application"
7
- task :setup, roles: :sidekiq do
8
- template "sidekiq_init.erb", "/tmp/sidekiq"
9
- run "#{sudo} mv /tmp/sidekiq /etc/init.d/sidekiq"
10
- run "#{sudo} chmod +x /etc/init.d/sidekiq"
11
- run "#{sudo} update-rc.d sidekiq defaults"
12
- end
13
- # after "deploy:setup", "nginx:setup"
14
-
15
- %w[start stop restart].each do |command|
16
- desc "#{command} sidekiq"
17
- task command do
18
- run "/etc/init.d/sidekiq #{command}"
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,29 +0,0 @@
1
- if Capistrano::Configuration.instance(false)
2
-
3
- Capistrano::Configuration.instance(true).load do |instance|
4
-
5
- namespace :unicorn do
6
- desc "Install unicorn"
7
-
8
- desc "Setup unicorn configuration for this application"
9
- task :setup, roles: :web do
10
- template "unicorn_init.erb", "/tmp/unicorn"
11
- run "#{sudo} mv /tmp/unicorn /etc/init.d/#{application}"
12
- run "#{sudo} chmod +x /etc/init.d/#{application}"
13
- run "#{sudo} update-rc.d #{application} defaults"
14
- template "nginx_config.erb", "/tmp/nginx_config"
15
- run "#{sudo} mv /tmp/nginx_config /etc/nginx/sites-enabled/#{application}"
16
- end
17
- # after "deploy:setup", "nginx:setup"
18
-
19
- %w[start stop restart].each do |command|
20
- desc "#{command} unicorn"
21
- task command, roles: :web do
22
- run "/etc/init.d/#{application} #{command}"
23
- end
24
- end
25
- end
26
-
27
- end
28
-
29
- end