json_voorhees 1.0.0 → 1.3.0

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -48
  3. data/lib/generators/json_voorhees/app_environment/USAGE +8 -0
  4. data/lib/generators/json_voorhees/app_environment/app_environment_generator.rb +93 -0
  5. data/lib/generators/json_voorhees/app_make_admin/app_make_admin_generator.rb +19 -34
  6. data/lib/generators/json_voorhees/app_make_tests/app_make_tests_generator.rb +5 -19
  7. data/lib/generators/json_voorhees/app_make_user/app_make_user_generator.rb +13 -73
  8. data/lib/generators/json_voorhees/app_scaffold/app_scaffold_generator.rb +2 -12
  9. data/lib/generators/json_voorhees/engine_create_controller/engine_create_controller_generator.rb +1 -6
  10. data/lib/generators/json_voorhees/engine_scaffold/engine_scaffold_generator.rb +3 -12
  11. data/lib/generators/json_voorhees/massive_scaffold/massive_scaffold_generator.rb +12 -28
  12. data/lib/generators/json_voorhees/setup_app/setup_app_generator.rb +32 -97
  13. data/lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb +8 -23
  14. data/lib/generators/json_voorhees/setup_engine/setup_engine_generator.rb +0 -3
  15. data/lib/json_voorhees/version.rb +1 -1
  16. data/test/fresh_copy/test_app/Gemfile +12 -17
  17. data/test/fresh_copy/test_app/Gemfile.lock +56 -61
  18. data/test/fresh_copy/test_app/Rakefile +1 -1
  19. data/test/fresh_copy/test_app/app/assets/stylesheets/application.css +5 -3
  20. data/test/fresh_copy/test_app/app/views/layouts/application.html.erb +2 -2
  21. data/test/fresh_copy/test_app/bin/rails +4 -0
  22. data/test/fresh_copy/test_app/bin/rake +4 -0
  23. data/test/fresh_copy/test_app/bin/spring +18 -0
  24. data/test/fresh_copy/test_app/config/database.yml +8 -8
  25. data/test/fresh_copy/test_app/config/environment.rb +1 -1
  26. data/test/fresh_copy/test_app/config/environments/development.rb +10 -2
  27. data/test/fresh_copy/test_app/config/environments/production.rb +7 -9
  28. data/test/fresh_copy/test_app/config/environments/test.rb +5 -2
  29. data/test/fresh_copy/test_app/config/initializers/assets.rb +8 -0
  30. data/test/fresh_copy/test_app/config/initializers/cookies_serializer.rb +3 -0
  31. data/test/fresh_copy/test_app/config/initializers/mime_types.rb +0 -1
  32. data/test/fresh_copy/test_app/config/initializers/session_store.rb +1 -1
  33. data/test/fresh_copy/test_app/config/routes.rb +1 -1
  34. data/test/fresh_copy/test_app/config/secrets.yml +22 -0
  35. data/test/fresh_copy/test_app/public/404.html +20 -11
  36. data/test/fresh_copy/test_app/public/422.html +20 -11
  37. data/test/fresh_copy/test_app/public/500.html +19 -10
  38. data/test/fresh_copy/test_app/test/test_helper.rb +1 -6
  39. data/test/lib/generators/json_voorhees/app_environment_generator_test.rb +16 -0
  40. metadata +15 -21
  41. data/lib/generators/json_voorhees/app_make_admin/templates/views/admin_home_no_user +0 -1
  42. data/lib/generators/json_voorhees/app_make_tests/templates/no_auth_request.rb.erb +0 -114
  43. data/lib/generators/json_voorhees/app_make_user/templates/active_admin_register.rb.erb +0 -83
  44. data/lib/generators/json_voorhees/app_make_user/templates/user/include_authorization.rb +0 -4
  45. data/lib/generators/json_voorhees/app_make_user/templates/user/specs/factory_girl.rb +0 -14
  46. data/lib/generators/json_voorhees/app_make_user/templates/user/specs/model_specs.rb +0 -61
  47. data/lib/generators/json_voorhees/app_make_user/templates/user/specs/no_arcadex_request_specs.rb +0 -85
  48. data/lib/generators/json_voorhees/app_make_user/templates/user/specs/request_specs.rb +0 -244
  49. data/lib/generators/json_voorhees/app_make_user/templates/user/specs/route_specs.rb +0 -91
  50. data/lib/generators/json_voorhees/app_make_user/templates/user/user_authorizations.rb +0 -92
  51. data/lib/generators/json_voorhees/app_make_user/templates/user/user_controller.rb +0 -169
  52. data/lib/generators/json_voorhees/app_make_user/templates/user/user_model.rb +0 -35
  53. data/lib/generators/json_voorhees/app_make_user/templates/user/user_routes.rb +0 -32
  54. data/lib/generators/json_voorhees/app_make_user/templates/user/user_serializer.rb +0 -43
  55. data/lib/generators/json_voorhees/engine_create_controller/templates/no_auth_controller_template.rb.erb +0 -61
  56. data/lib/generators/json_voorhees/setup_app/templates/api_controller_no_arcadex.rb +0 -33
  57. data/test/fresh_copy/test_app/config/initializers/secret_token.rb +0 -12
@@ -1,169 +0,0 @@
1
- require_dependency "people/api/v1/application_controller"
2
- require 'authorization'
3
-
4
- module People
5
- class Api::V1::UsersController < Api::V1::ApplicationController
6
- <% if options.arcadex? %>
7
- skip_before_filter :authenticate_user, :only => [:register, :login]
8
- <% end %>
9
- before_action :set_user, only: [:show, :edit, :update, :authenticate]
10
- before_action :register_authorize, only: [:register]
11
- before_action :login_authorize, only: [:login]
12
- before_action :logout_authorize, only: [:logout]
13
- before_action :index_authorize, only: [:index]
14
- before_action :show_authorize, only: [:show]
15
- before_action :update_authorize, only: [:update]
16
-
17
- <% if options.arcadex? %>
18
- # POST /api/1/users/register
19
- def register
20
- #Create a new user
21
- user = ::People::V1::User.new(user_params)
22
- if user.save
23
- #If the user is saved, return a token
24
- token = user.tokens[0]
25
- ::Arcadex::Create.set_token(token,360,request)
26
- userHash = {id: user.id, username: user.username, email: user.email}
27
- tokenHash = {auth_token: token.auth_token}
28
- render :json => {user: userHash,token: tokenHash}
29
- else
30
- #Return an error if not saved
31
- render :json => {errors: user.errors.full_messages}, status: :unprocessable_entity
32
- end
33
- end
34
-
35
- # POST /api/1/users/login
36
- def login
37
- #Should I delete the current token or ignore it?
38
- #Find user from email and password. Create and return a new token
39
- user = ::People::V1::User.find_by(email: get_email)
40
- if user && user.authenticate(params[:user][:password])
41
- token = user.tokens.create
42
- ::Arcadex::Create.set_token(token,360,request)
43
- userHash = {id: user.id, username: user.username, email: user.email}
44
- tokenHash = {auth_token: token.auth_token}
45
- render :json => {user: userHash,token: tokenHash}
46
- else
47
- render :json => {errors: "Email and/or Password is incorrect"}, status: :unauthorized
48
- end
49
- end
50
-
51
- # POST /api/1/users/logout
52
- def logout
53
- #Destroy the current token
54
- token = current_token
55
- token.destroy
56
- render json: {}
57
- end
58
-
59
- # GET /api/1/users/login_status
60
- def login_status
61
- # Will give an unauthorized if not logged in
62
- render json: {}
63
- end
64
- <% end %>
65
-
66
- # POST /api/1/users/authenticate
67
- def authenticate
68
- if user_authenticate_password
69
- return
70
- end
71
- render json: {}
72
- end
73
-
74
- # GET /api/1/users
75
- def index
76
- @users = ::People::V1::User.all
77
- render json: @users
78
- end
79
-
80
- # GET /api/1/users/1
81
- def show
82
- render json: @user
83
- end
84
-
85
- # PATCH/PUT /api/1/users/1
86
- def update
87
- if user_authenticate_password
88
- return
89
- end
90
- if @user.update(user_params)
91
- render json: @user
92
- else
93
- render :json => {errors: @user.errors.full_messages}, status: :unprocessable_entity
94
- end
95
- end
96
-
97
- private
98
- # Use callbacks to share common setup or constraints between actions.
99
-
100
- def user_authenticate_password
101
- if authenticate_password
102
- render :json => {errors: "Email and/or Password is incorrect"}, status: :unauthorized
103
- return true
104
- end
105
- return false
106
- end
107
-
108
- def get_email
109
- if !params[:user][:email].nil?
110
- return params[:user][:email].downcase
111
- else
112
- return nil
113
- end
114
- end
115
-
116
- def set_user
117
- @user = ::People::V1::User.find_by_id(params[:id])
118
- if @user.nil?
119
- render :json => {errors: "User was not found"}, status: :not_found
120
- end
121
- end
122
-
123
- # Only allow a trusted parameter "white list" through.
124
-
125
- def user_params
126
- params.require(:user).permit(:username, :email, :password, :password_confirmation)
127
- end
128
-
129
- # Authorizations below here
130
-
131
- <% if options.arcadex? %>
132
- def register_authorize
133
- if !::Authorization::People::V1::User.register?
134
- render :json => {errors: "User is not authorized for this action"}, status: :forbidden
135
- end
136
- end
137
-
138
- def login_authorize
139
- if !::Authorization::People::V1::User.login?
140
- render :json => {errors: "User is not authorized for this action"}, status: :forbidden
141
- end
142
- end
143
-
144
- def logout_authorize
145
- if !::Authorization::People::V1::User.logout?(current_user)
146
- render :json => {errors: "User is not authorized for this action"}, status: :forbidden
147
- end
148
- end
149
- <% end %>
150
-
151
- def index_authorize
152
- if !::Authorization::People::V1::User.index?(current_user)
153
- render :json => {errors: "User is not authorized for this action"}, status: :forbidden
154
- end
155
- end
156
-
157
- def show_authorize
158
- if !::Authorization::People::V1::User.show?(@user,current_user)
159
- render :json => {errors: "User is not authorized for this action"}, status: :forbidden
160
- end
161
- end
162
-
163
- def update_authorize
164
- if !::Authorization::People::V1::User.update?(@user,current_user)
165
- render :json => {errors: "User is not authorized for this action"}, status: :forbidden
166
- end
167
- end
168
- end
169
- end
@@ -1,35 +0,0 @@
1
- require 'type_cartographer'
2
-
3
- module People
4
- class V1::User < ActiveRecord::Base
5
- self.table_name = 'people_users'
6
-
7
- before_save { self.email = email.downcase }
8
- before_save { self.username = username.downcase }
9
-
10
- <% if options.arcadex? %>
11
- has_many :tokens, :as => :imageable, :class_name => "::Arcadex::Token"
12
- <% end %>
13
- has_secure_password
14
-
15
- after_create :setup_user
16
-
17
- validates :username, presence: true, :uniqueness => { :case_sensitive => false }
18
- #validates_format_of :username, :with => /\A[A-Za-z0-9\d]+\Z/i
19
- validates :email, presence: true, :uniqueness => { :case_sensitive => false }
20
- #Might need a regex for emails, or just rather confirm them
21
-
22
- <% if options.arcadex? %>
23
- def setup_user
24
- create_token
25
- end
26
-
27
- def create_token
28
- self.tokens.create!
29
- end
30
- <% else %>
31
- def setup_user
32
- end
33
- <% end %>
34
- end
35
- end
@@ -1,32 +0,0 @@
1
- People::Engine.routes.draw do
2
-
3
- root to: "users#index"
4
-
5
- <% if !options.active_admin? %>
6
- scope 'admin' do
7
- resources :users
8
- end
9
- <% end %>
10
-
11
- scope 'api' do
12
- scope '1' do
13
- resources :users, controller: 'api/v1/users' do
14
- <% if options.arcadex? %>
15
- collection do
16
- # /api/1/users/register
17
- post 'register', to: "api/v1/users#register"
18
- # /api/1/users/login
19
- post 'login', to: "api/v1/users#login"
20
- # /api/1/users/logout
21
- post 'logout', to: "api/v1/users#logout"
22
- # /api/1/users/logout
23
- post 'authenticate/:id', to: "api/v1/users#authenticate"
24
- # /api/1/users/login_status
25
- get 'login_status', to: "api/v1/users#login_status"
26
- end
27
- <% end %>
28
- end
29
- end
30
- end
31
-
32
- end
@@ -1,43 +0,0 @@
1
- require 'authorization'
2
-
3
- module People
4
- class V1::UserSerializer < ActiveModel::Serializer
5
- embed :ids, include: true
6
-
7
- attributes :id
8
- attributes :username
9
- attributes :email
10
- attributes :created_at
11
- attributes :updated_at
12
- <% if options.arcadex? %>
13
- has_many :tokens
14
- <% end %>
15
-
16
- def include_id?
17
- return ::Authorization::People::V1::User.include_id?(current_user,object,@options)
18
- end
19
-
20
- def include_email?
21
- return ::Authorization::People::V1::User.include_email?(current_user,object,@options)
22
- end
23
-
24
- def include_username?
25
- return ::Authorization::People::V1::User.include_username?(current_user,object,@options)
26
- end
27
-
28
- def include_created_at?
29
- return ::Authorization::People::V1::User.include_created_at?(current_user,object,@options)
30
- end
31
-
32
- def include_updated_at?
33
- return ::Authorization::People::V1::User.include_updated_at?(current_user,object,@options)
34
- end
35
-
36
- def include_associations!
37
- <% if options.arcadex? %>
38
- include! :tokens if ::Authorization::People::V1::User.include_tokens?(current_user,object,@options)
39
- <% end %>
40
- end
41
-
42
- end
43
- end
@@ -1,61 +0,0 @@
1
- require_dependency "<%= module_snake %>/api/v<%= api_version %>/application_controller"
2
- require 'authorization'
3
-
4
- module <%= module_camel %>
5
- class Api::V<%= api_version %>::<%= resource_camel.pluralize %>Controller < Api::V<%= api_version %>::ApplicationController
6
- before_action :set_<%= resource_singular %>, only: [:show, :update, :destroy]
7
-
8
- # GET /api/<%= api_version %>/<%= resource_plural %>
9
- def index
10
- @<%= resource_plural %> = ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.all
11
- render json: @<%= resource_plural %>
12
- end
13
-
14
- # GET /api/<%= api_version %>/<%= resource_plural %>/1
15
- def show
16
- render json: @<%= resource_singular %>
17
- end
18
-
19
- # POST /api/<%= api_version %>/<%= resource_plural %>
20
- def create
21
- @<%= resource_singular %> = ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.new(<%= resource_singular %>_params)
22
- if @<%= resource_singular %>.save
23
- render json: @<%= resource_singular %>
24
- else
25
- render :json => {errors: @<%= resource_singular %>.errors.full_messages}, status: :unprocessable_entity
26
- end
27
- end
28
-
29
- # PATCH/PUT /api/<%= api_version %>/<%= resource_plural %>/1
30
- def update
31
- if @<%= resource_singular %>.update(<%= resource_singular %>_params)
32
- render json: @<%= resource_singular %>
33
- else
34
- render :json => {errors: @<%= resource_singular %>.errors.full_messages}, status: :unprocessable_entity
35
- end
36
- end
37
-
38
- # DELETE /api/<%= api_version %>/<%= resource_plural %>/1
39
- def destroy
40
- @<%= resource_singular %>.destroy
41
- render json: {}
42
- end
43
-
44
- private
45
-
46
- # Use callbacks to share common setup or constraints between actions.
47
-
48
- def set_<%= resource_singular %>
49
- @<%= resource_singular %> = ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.find_by_id(params[:id])
50
- if @<%= resource_singular %>.nil?
51
- render :json => {errors: "<%= resource_camel %> was not found"}, status: :not_found
52
- end
53
- end
54
-
55
- # Only allow a trusted parameter "white list" through.
56
-
57
- def <%= resource_singular %>_params
58
- params.require(:<%= resource_singular %>).permit(<%= params_list %>)
59
- end
60
- end
61
- end
@@ -1,33 +0,0 @@
1
- class Api::V1::ApiController < ::ActionController::API
2
-
3
- after_filter :cors_set_access_control_headers
4
-
5
- def route_options
6
- cors_preflight_check
7
- end
8
-
9
- private
10
-
11
- def current_user
12
- nil
13
- end
14
-
15
- def cors_set_access_control_headers
16
- response.headers['Access-Control-Allow-Origin'] = '*'
17
- response.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
18
- response.headers['Access-Control-Allow-Headers'] = '*, Origin, Content-Type, Accept, Authorization, Token, Auth-Token, Email'
19
- response.headers['Access-Control-Expose-Headers'] = '*'
20
- response.headers['Access-Control-Max-Age'] = "1728000"
21
- end
22
-
23
- def cors_preflight_check
24
- #if request.method == 'OPTIONS'
25
- request.headers['Access-Control-Allow-Origin'] = '*'
26
- request.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
27
- request.headers['Access-Control-Allow-Headers'] = '*, X-Requested-With, X-Prototype-Version, Token, Auth-Token, Email'
28
- request.headers['Access-Control-Max-Age'] = '1728000'
29
- render :text => '', :content_type => 'text/plain'
30
- #end
31
- end
32
-
33
- end
@@ -1,12 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key is used for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
-
6
- # Make sure the secret is at least 30 characters and all random,
7
- # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rake secret` to generate a secure secret key.
9
-
10
- # Make sure your secret_key_base is kept private
11
- # if you're sharing your code publicly.
12
- TestApp::Application.config.secret_key_base = '29f232ab8efec1789f4c5ba430c4777d3ca3740e1e3c3f5da22191b3348a837767e0c216252d73f5ff5cf61e47d153be0c8d08cf4b96146c4d818d9d4612c477'