json_voorhees 0.3.9 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +24 -2
- data/lib/generators/json_voorhees/app_make_admin/app_make_admin_generator.rb +23 -9
- data/lib/generators/json_voorhees/app_make_admin/templates/dashboard.rb.erb +69 -0
- data/lib/generators/json_voorhees/app_make_admin/templates/defcon_admin_register.rb.erb +98 -0
- data/lib/generators/json_voorhees/app_make_user/app_make_user_generator.rb +20 -2
- data/lib/generators/json_voorhees/app_make_user/templates/active_admin_register.rb.erb +82 -0
- data/lib/generators/json_voorhees/app_make_user/templates/user/user_controller.rb +2 -2
- data/lib/generators/json_voorhees/app_make_user/templates/user/user_model.rb +2 -2
- data/lib/generators/json_voorhees/engine_create_controller/templates/controller_template.rb.erb +2 -2
- data/lib/generators/json_voorhees/engine_create_controller/templates/no_auth_controller_template.rb.erb +5 -5
- data/lib/generators/json_voorhees/massive_scaffold/massive_scaffold_generator.rb +36 -1
- data/lib/generators/json_voorhees/massive_scaffold/templates/active_admin_register.rb.erb +96 -0
- data/lib/generators/json_voorhees/setup_app/setup_app_generator.rb +34 -2
- data/lib/generators/json_voorhees/setup_app/templates/active_admin_token_register.rb.erb +93 -0
- data/lib/generators/json_voorhees/setup_app/templates/api_controller_no_arcadex.rb +27 -3
- data/lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb +24 -0
- data/lib/json_voorhees/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f85f4f709a200d564ef318e66a78ba4a472fa5d9
|
4
|
+
data.tar.gz: 54eb225d14d43ebd4a1645337f1a886fdd8d256e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1ff8bc5c94a283e6a35b8bbb77f8a6a94fc5bdf2b27baddb185005fb1b096a333f9335fb618f12d97be146c17481b9e9861ec8cf87e9f5a359be3f91b03caf4
|
7
|
+
data.tar.gz: 6aeeabf8ba46aa58186a5024f8f27cb550d7aad2b88a7650988b434a6fe453bf5d9f29c5b3436db17829718d2f0e6dfc23ac3e264d88b6019405098cbd205336
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# JsonVoorhees 0.
|
1
|
+
# JsonVoorhees 0.4.0
|
2
2
|
|
3
3
|
## Introduction
|
4
4
|
|
@@ -40,6 +40,10 @@ top of rails scaffold and in the process creates the api counterpart. You have
|
|
40
40
|
the option of skipping the normal rails scaffold.
|
41
41
|
```bash
|
42
42
|
rails g json_voorhees:massive_scaffold [engine name] [resource name] [api_version] [scaffold parameters]
|
43
|
+
|
44
|
+
example
|
45
|
+
|
46
|
+
rails g json_voorhees:massive_scaffold chat message 1 user_id:integer message:text
|
43
47
|
```
|
44
48
|
Make sure the resource is in the correct scoping in the Engines routing file. Then
|
45
49
|
copy over the engines migrations and migrate the main app. Check if everything is fine by
|
@@ -80,9 +84,27 @@ the gem and the options. They each have a multitude of arguments and options.
|
|
80
84
|
11. rails g json_voorhees:setup_app
|
81
85
|
12. rails g json_voorhees:setup_engine
|
82
86
|
|
87
|
+
## Versioning
|
88
|
+
|
89
|
+
This generator is strongly tied in with versioning. As so every
|
90
|
+
model, controller, serializer, test and factory created with this tool are
|
91
|
+
versioned. The main app hosts the application controllers and test suite. Everything
|
92
|
+
else resides in engines for good modularity.
|
93
|
+
|
83
94
|
## To Do
|
84
95
|
|
85
96
|
1. Figure out a better way to test this thing
|
86
97
|
2. Use option for namespaced engine or no engine
|
87
98
|
3. Maybe give an option to include pagination?
|
88
|
-
4. Option for websockets and paperclip?
|
99
|
+
4. Option for websockets and paperclip?
|
100
|
+
5. Make the non defaults easier to user
|
101
|
+
|
102
|
+
## Reminder
|
103
|
+
|
104
|
+
For more granular control over tokens and the admin user,
|
105
|
+
clone the github repos into the engines folder and point your
|
106
|
+
gem file to that. Edit what you want.
|
107
|
+
|
108
|
+
To setup admin restrictions, use the attributes for the admin
|
109
|
+
class and put before_filters before all of the CRUD actions.
|
110
|
+
Make sure the current_user has the correct permissions.
|
@@ -8,6 +8,7 @@ module JsonVoorhees
|
|
8
8
|
def sprint
|
9
9
|
if options.active_admin?
|
10
10
|
make_active_admin
|
11
|
+
make_dashboard
|
11
12
|
else
|
12
13
|
make_admin
|
13
14
|
end
|
@@ -15,19 +16,30 @@ module JsonVoorhees
|
|
15
16
|
|
16
17
|
private
|
17
18
|
|
19
|
+
def make_dashboard
|
20
|
+
run "rm -f app/admin/dashboard.rb"
|
21
|
+
copy_file "dashboard.rb.erb", "app/admin/dashboard.rb"
|
22
|
+
end
|
23
|
+
|
18
24
|
def make_active_admin
|
19
25
|
run "rails g active_admin:install --skip-users"
|
26
|
+
template "defcon_admin_register.rb.erb", "app/admin/defcon_admin_user.rb"
|
20
27
|
inject_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery with: :exception\n" do <<-'RUBY'
|
21
28
|
|
22
|
-
#This needs to be put inside a config file. but this is good for now
|
23
|
-
#This only requires the password for the admin section of the website
|
24
29
|
protected
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
def authenticate_admin_user!
|
32
|
+
if ::Defcon.authenticate_admin_user!(session)
|
33
|
+
return true
|
34
|
+
else
|
35
|
+
redirect_to defcon.defcon_login_path, alert: "Login!"
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def current_admin_user
|
41
|
+
return ::Defcon.current_admin_user(session)
|
29
42
|
end
|
30
|
-
end
|
31
43
|
|
32
44
|
RUBY
|
33
45
|
end
|
@@ -47,10 +59,12 @@ module JsonVoorhees
|
|
47
59
|
inject_into_file 'config/initializers/active_admin.rb', after: "ActiveAdmin.setup do |config|\n" do <<-'RUBY'
|
48
60
|
|
49
61
|
# http auth for admin area
|
50
|
-
config.
|
51
|
-
config.
|
52
|
-
config.
|
62
|
+
config.authentication_method = :authenticate_admin_user!
|
63
|
+
config.current_user_method = :current_admin_user
|
64
|
+
config.logout_link_path = "/sessions/destroy"
|
65
|
+
config.logout_link_method = :post
|
53
66
|
config.allow_comments = false
|
67
|
+
config.site_title_link = "/"
|
54
68
|
|
55
69
|
RUBY
|
56
70
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
ActiveAdmin.register_page "Dashboard" do
|
2
|
+
|
3
|
+
menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") }
|
4
|
+
|
5
|
+
content title: proc{ I18n.t("active_admin.dashboard") } do
|
6
|
+
|
7
|
+
columns do
|
8
|
+
|
9
|
+
column do
|
10
|
+
panel "Recent Signups" do
|
11
|
+
table_for ::People::User.order("created_at desc").limit(30) do
|
12
|
+
column :username do |user|
|
13
|
+
link_to user.username, admin_people_user_path(user)
|
14
|
+
end
|
15
|
+
column :email
|
16
|
+
column :created_at
|
17
|
+
end
|
18
|
+
strong { link_to "View All Users", admin_people_users_path }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
=begin
|
28
|
+
columns do
|
29
|
+
column do
|
30
|
+
panel "Recent Signups" do
|
31
|
+
ul do
|
32
|
+
::People::User.recent(30).map do |user|
|
33
|
+
li link_to(user.username, resource_path(user))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
=end
|
40
|
+
|
41
|
+
=begin
|
42
|
+
|
43
|
+
div class: "blank_slate_container", id: "dashboard_default_message" do
|
44
|
+
span class: "blank_slate" do
|
45
|
+
span I18n.t("active_admin.dashboard_welcome.welcome")
|
46
|
+
small I18n.t("active_admin.dashboard_welcome.call_to_action")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
=end
|
50
|
+
# Here is an example of a simple dashboard with columns and panels.
|
51
|
+
#
|
52
|
+
# columns do
|
53
|
+
# column do
|
54
|
+
# panel "Recent Posts" do
|
55
|
+
# ul do
|
56
|
+
# Post.recent(5).map do |post|
|
57
|
+
# li link_to(post.title, admin_post_path(post))
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
# end
|
62
|
+
|
63
|
+
# column do
|
64
|
+
# panel "Info" do
|
65
|
+
# para "Welcome to ActiveAdmin."
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
# content
|
@@ -0,0 +1,98 @@
|
|
1
|
+
ActiveAdmin.register Defcon::AdminUser do
|
2
|
+
|
3
|
+
config.per_page = 30
|
4
|
+
|
5
|
+
form do |f|
|
6
|
+
f.semantic_errors # shows errors on :base
|
7
|
+
#f.inputs # builds an input field for every attribute
|
8
|
+
f.inputs do
|
9
|
+
f.input :id
|
10
|
+
f.input :username
|
11
|
+
f.input :password
|
12
|
+
f.input :password_confirmation
|
13
|
+
f.input :email
|
14
|
+
f.input :read_only
|
15
|
+
f.input :attempts
|
16
|
+
f.input :max_attempts
|
17
|
+
f.input :master
|
18
|
+
f.input :updated_at
|
19
|
+
f.input :created_at
|
20
|
+
end
|
21
|
+
f.actions # adds the 'Submit' and 'Cancel' buttons
|
22
|
+
end
|
23
|
+
|
24
|
+
controller do
|
25
|
+
def create
|
26
|
+
@admin_user = ::Defcon::AdminUser.new(admin_user_params)
|
27
|
+
if @admin_user.save
|
28
|
+
flash[:notice] = "Created Successfully!"
|
29
|
+
redirect_to resource_path @admin_user
|
30
|
+
else
|
31
|
+
flash[:notice] = "#{@admin_user.errors.full_messages}"
|
32
|
+
redirect_to new_resource_path @admin_user
|
33
|
+
#super
|
34
|
+
#render :new
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def update
|
39
|
+
@admin_user = ::Defcon::AdminUser.find(params[:id])
|
40
|
+
if @admin_user.update(admin_user_params)
|
41
|
+
flash[:notice] = "Updated Successfully!"
|
42
|
+
redirect_to resource_path @admin_user
|
43
|
+
else
|
44
|
+
flash.now[:notice] = "#{@admin_user.errors.full_messages}"
|
45
|
+
render :edit
|
46
|
+
#super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def destroy
|
51
|
+
=begin
|
52
|
+
@admin_user = ::Defcon::AdminUser.find(params[:id])
|
53
|
+
@admin_user.destroy
|
54
|
+
flash.now[:notice] = "Deleted Successfully!"
|
55
|
+
render :index
|
56
|
+
=end
|
57
|
+
flash.now[:notice] = "Deleting an Admin is serious business, update your policy first"
|
58
|
+
render :index
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def admin_user_params
|
64
|
+
params.require(:admin_user).permit(:username,:email,:password,:password_confirmation,:read_only,:attempts,:max_attempts,:master)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
index do
|
69
|
+
column :id
|
70
|
+
column :username
|
71
|
+
column :email
|
72
|
+
column :password_digest
|
73
|
+
column :read_only
|
74
|
+
column :attempts
|
75
|
+
column :max_attempts
|
76
|
+
column :master
|
77
|
+
column :updated_at
|
78
|
+
column :created_at
|
79
|
+
actions
|
80
|
+
end
|
81
|
+
|
82
|
+
show do
|
83
|
+
attributes_table do
|
84
|
+
row :id
|
85
|
+
row :username
|
86
|
+
row :email
|
87
|
+
row :password_digest
|
88
|
+
row :read_only
|
89
|
+
row :attempts
|
90
|
+
row :max_attempts
|
91
|
+
row :master
|
92
|
+
row :updated_at
|
93
|
+
row :created_at
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
end
|
@@ -7,12 +7,17 @@ module JsonVoorhees
|
|
7
7
|
def sprint
|
8
8
|
people
|
9
9
|
if options.active_admin?
|
10
|
-
run "rails g active_admin:resource people::user"
|
10
|
+
#run "rails g active_admin:resource people::user"
|
11
|
+
custom_active_admin
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
15
16
|
|
17
|
+
def custom_active_admin
|
18
|
+
template "active_admin_register.rb.erb", "app/admin/people_user.rb"
|
19
|
+
end
|
20
|
+
|
16
21
|
def people
|
17
22
|
run "rails plugin new engines/people --mountable"
|
18
23
|
inside('engines/people') do
|
@@ -20,8 +25,9 @@ module JsonVoorhees
|
|
20
25
|
run "rails g json_voorhees:setup_engine people"
|
21
26
|
add_generator
|
22
27
|
#Now it needs to create the user class
|
23
|
-
|
28
|
+
run "rails g scaffold user username:string:uniq email:string:uniq password_digest:string"
|
24
29
|
#Add this to the routes and gemfile
|
30
|
+
add_ordering
|
25
31
|
end
|
26
32
|
#Need to add the engine to the main_apps gemfile
|
27
33
|
route "mount People::Engine, at: \'/\'"
|
@@ -32,6 +38,18 @@ module JsonVoorhees
|
|
32
38
|
insert_people_engine
|
33
39
|
end
|
34
40
|
|
41
|
+
def add_ordering
|
42
|
+
#app/models/people/user.rb
|
43
|
+
inject_into_file "app/models/people/user.rb", after: "class User < ActiveRecord::Base\n" do <<-'RUBY'
|
44
|
+
|
45
|
+
def self.recent(num)
|
46
|
+
::People::User.order("created_at DESC").limit(num)
|
47
|
+
end
|
48
|
+
|
49
|
+
RUBY
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
35
53
|
def add_generator
|
36
54
|
inject_into_file "people.gemspec", after: "s.test_files = Dir[\"test/**/*\"]\n" do <<-'RUBY'
|
37
55
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
ActiveAdmin.register People::User do
|
2
|
+
|
3
|
+
config.per_page = 30
|
4
|
+
|
5
|
+
form do |f|
|
6
|
+
f.semantic_errors # shows errors on :base
|
7
|
+
#f.inputs # builds an input field for every attribute
|
8
|
+
f.inputs do
|
9
|
+
f.input :id
|
10
|
+
f.input :username
|
11
|
+
f.input :email
|
12
|
+
f.input :password
|
13
|
+
f.input :password_confirmation
|
14
|
+
f.input :updated_at
|
15
|
+
f.input :created_at
|
16
|
+
end
|
17
|
+
f.actions # adds the 'Submit' and 'Cancel' buttons
|
18
|
+
end
|
19
|
+
|
20
|
+
controller do
|
21
|
+
def create
|
22
|
+
@user = ::People::V1::User.new(user_params)
|
23
|
+
if @user.save
|
24
|
+
flash[:notice] = "Created Successfully!"
|
25
|
+
redirect_to resource_path @user
|
26
|
+
else
|
27
|
+
flash[:notice] = "#{@user.errors.full_messages}"
|
28
|
+
redirect_to new_resource_path @user
|
29
|
+
#super
|
30
|
+
#render :new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
@user = ::People::V1::User.find(params[:id])
|
36
|
+
if @user.update(user_params)
|
37
|
+
flash[:notice] = "Updated Successfully!"
|
38
|
+
redirect_to resource_path @user
|
39
|
+
else
|
40
|
+
flash.now[:notice] = "#{@user.errors.full_messages}"
|
41
|
+
render :edit
|
42
|
+
#super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def destroy
|
47
|
+
@user = ::People::V1::User.find(params[:id])
|
48
|
+
@token.destroy
|
49
|
+
flash.now[:notice] = "Deleted Successfully!"
|
50
|
+
render :index
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def user_params
|
56
|
+
params.require(:user).permit(:username,:email,:password,:password_confirmation)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
index do
|
61
|
+
column :id
|
62
|
+
column :username
|
63
|
+
column :email
|
64
|
+
column :password_digest
|
65
|
+
column :updated_at
|
66
|
+
column :created_at
|
67
|
+
actions
|
68
|
+
end
|
69
|
+
|
70
|
+
show do
|
71
|
+
attributes_table do
|
72
|
+
row :id
|
73
|
+
row :username
|
74
|
+
row :email
|
75
|
+
row :password_digest
|
76
|
+
row :updated_at
|
77
|
+
row :created_at
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
@@ -28,7 +28,7 @@ module People
|
|
28
28
|
render :json => {user: userHash,token: tokenHash}
|
29
29
|
else
|
30
30
|
#Return an error if not saved
|
31
|
-
render :json => {errors: user.errors}, status: :unprocessable_entity
|
31
|
+
render :json => {errors: user.errors.full_messages}, status: :unprocessable_entity
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -73,7 +73,7 @@ module People
|
|
73
73
|
if @user.update(user_params)
|
74
74
|
render json: @user
|
75
75
|
else
|
76
|
-
render :json => {errors: @user.errors}, status: :unprocessable_entity
|
76
|
+
render :json => {errors: @user.errors.full_messages}, status: :unprocessable_entity
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -11,9 +11,9 @@ module People
|
|
11
11
|
|
12
12
|
after_create :setup_user
|
13
13
|
|
14
|
-
validates :username, presence: true
|
14
|
+
validates :username, presence: true, :uniqueness => { :case_sensitive => false }
|
15
15
|
#validates_format_of :username, :with => /\A[A-Za-z0-9\d]+\Z/i
|
16
|
-
validates :email, presence: true
|
16
|
+
validates :email, presence: true, :uniqueness => { :case_sensitive => false }
|
17
17
|
#Might need a regex for emails, or just rather confirm them
|
18
18
|
|
19
19
|
<% if options.arcadex? %>
|
data/lib/generators/json_voorhees/engine_create_controller/templates/controller_template.rb.erb
CHANGED
@@ -27,7 +27,7 @@ module <%= module_camel %>
|
|
27
27
|
if @<%= resource_singular %>.save
|
28
28
|
render json: @<%= resource_singular %>
|
29
29
|
else
|
30
|
-
render :json => {errors: @<%= resource_singular %>.errors}, status: :unprocessable_entity
|
30
|
+
render :json => {errors: @<%= resource_singular %>.errors.full_messages}, status: :unprocessable_entity
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -36,7 +36,7 @@ module <%= module_camel %>
|
|
36
36
|
if @<%= resource_singular %>.update(<%= resource_singular %>_params)
|
37
37
|
render json: @<%= resource_singular %>
|
38
38
|
else
|
39
|
-
render :json => {errors: @<%= resource_singular %>.errors}, status: :unprocessable_entity
|
39
|
+
render :json => {errors: @<%= resource_singular %>.errors.full_messages}, status: :unprocessable_entity
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -7,7 +7,7 @@ module <%= module_camel %>
|
|
7
7
|
|
8
8
|
# GET /api/<%= api_version %>/<%= resource_plural %>
|
9
9
|
def index
|
10
|
-
@<%= resource_plural %> = ::<%= module_camel %>::<%= resource_camel %>.all
|
10
|
+
@<%= resource_plural %> = ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.all
|
11
11
|
render json: @<%= resource_plural %>
|
12
12
|
end
|
13
13
|
|
@@ -18,11 +18,11 @@ module <%= module_camel %>
|
|
18
18
|
|
19
19
|
# POST /api/<%= api_version %>/<%= resource_plural %>
|
20
20
|
def create
|
21
|
-
@<%= resource_singular %> = ::<%= module_camel %>::<%= resource_camel %>.new(<%= resource_singular %>_params)
|
21
|
+
@<%= resource_singular %> = ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.new(<%= resource_singular %>_params)
|
22
22
|
if @<%= resource_singular %>.save
|
23
23
|
render json: @<%= resource_singular %>
|
24
24
|
else
|
25
|
-
render :json => {errors: @<%= resource_singular %>.errors}, status: :unprocessable_entity
|
25
|
+
render :json => {errors: @<%= resource_singular %>.errors.full_messages}, status: :unprocessable_entity
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -31,7 +31,7 @@ module <%= module_camel %>
|
|
31
31
|
if @<%= resource_singular %>.update(<%= resource_singular %>_params)
|
32
32
|
render json: @<%= resource_singular %>
|
33
33
|
else
|
34
|
-
render :json => {errors: @<%= resource_singular %>.errors}, status: :unprocessable_entity
|
34
|
+
render :json => {errors: @<%= resource_singular %>.errors.full_messages}, status: :unprocessable_entity
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -46,7 +46,7 @@ module <%= module_camel %>
|
|
46
46
|
# Use callbacks to share common setup or constraints between actions.
|
47
47
|
|
48
48
|
def set_<%= resource_singular %>
|
49
|
-
@<%= resource_singular %> = ::<%= module_camel %>::<%= resource_camel %>.find_by_id(params[:id])
|
49
|
+
@<%= resource_singular %> = ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.find_by_id(params[:id])
|
50
50
|
if @<%= resource_singular %>.nil?
|
51
51
|
render :json => {errors: "<%= resource_camel %> was not found"}, status: :not_found
|
52
52
|
end
|
@@ -34,11 +34,46 @@ module JsonVoorhees
|
|
34
34
|
run "rails g json_voorhees:app_scaffold #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")} --skip-arcadex"
|
35
35
|
end
|
36
36
|
if options.active_admin?
|
37
|
-
run "rails generate active_admin:resource #{module_name.underscore.downcase}::#{resource_name.singularize.underscore.downcase}"
|
37
|
+
#run "rails generate active_admin:resource #{module_name.underscore.downcase}::#{resource_name.singularize.underscore.downcase}"
|
38
|
+
make_custom_active_admin
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
42
|
private
|
42
43
|
|
44
|
+
def make_custom_active_admin
|
45
|
+
template "active_admin_register.rb.erb", "app/admin/#{module_name.underscore}_#{resource_singular}.rb"
|
46
|
+
end
|
47
|
+
|
48
|
+
def params_list
|
49
|
+
params = []
|
50
|
+
attributes.each do |pair|
|
51
|
+
elem = pair.split(/:/)[0]
|
52
|
+
field = ":#{elem}"
|
53
|
+
params << field
|
54
|
+
end
|
55
|
+
return params.join(",")
|
56
|
+
end
|
57
|
+
|
58
|
+
def resource_singular
|
59
|
+
resource_name.underscore.singularize
|
60
|
+
end
|
61
|
+
|
62
|
+
def resource_plural
|
63
|
+
resource_name.underscore.pluralize
|
64
|
+
end
|
65
|
+
|
66
|
+
def resource_camel
|
67
|
+
resource_name.camelize.singularize
|
68
|
+
end
|
69
|
+
|
70
|
+
def module_camel
|
71
|
+
module_name.camelize
|
72
|
+
end
|
73
|
+
|
74
|
+
def module_snake
|
75
|
+
module_name.underscore.downcase
|
76
|
+
end
|
77
|
+
|
43
78
|
end
|
44
79
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
ActiveAdmin.register <%= module_camel %>::<%= resource_camel %> do
|
2
|
+
|
3
|
+
config.per_page = 30
|
4
|
+
|
5
|
+
form do |f|
|
6
|
+
f.semantic_errors # shows errors on :base
|
7
|
+
#f.inputs # builds an input field for every attribute
|
8
|
+
f.inputs do
|
9
|
+
f.input :id
|
10
|
+
<% attributes.each do |pair| %><% field = pair.split(":")[0] %>
|
11
|
+
f.input :<%= field %>
|
12
|
+
<% end %>
|
13
|
+
f.input :updated_at
|
14
|
+
f.input :created_at
|
15
|
+
end
|
16
|
+
f.actions # adds the 'Submit' and 'Cancel' buttons
|
17
|
+
end
|
18
|
+
|
19
|
+
controller do
|
20
|
+
def create
|
21
|
+
@<%= resource_singular %> = ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.new(<%= resource_singular %>_params)
|
22
|
+
if @<%= resource_singular %>.save
|
23
|
+
flash[:notice] = "Created Successfully!"
|
24
|
+
redirect_to resource_path @<%= resource_singular %>
|
25
|
+
else
|
26
|
+
flash[:notice] = "#{@<%= resource_singular %>.errors.full_messages}"
|
27
|
+
redirect_to new_resource_path @<%= resource_singular %>
|
28
|
+
#super
|
29
|
+
#render :new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def update
|
35
|
+
@<%= resource_singular %> = ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.find(params[:id])
|
36
|
+
if @<%= resource_singular %>.update(<%= resource_singular %>_params)
|
37
|
+
flash[:notice] = "Updated Successfully!"
|
38
|
+
redirect_to resource_path @<%= resource_singular %>
|
39
|
+
else
|
40
|
+
flash.now[:notice] = "#{@<%= resource_singular %>.errors.full_messages}"
|
41
|
+
render :edit
|
42
|
+
#super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def destroy
|
47
|
+
@<%= resource_singular %> = ::<%= module_camel %>::V<%= api_version %>::<%= resource_camel %>.find(params[:id])
|
48
|
+
@<%= resource_singular %>.destroy
|
49
|
+
flash.now[:notice] = "Deleted Successfully!"
|
50
|
+
render :index
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def <%= resource_singular %>_params
|
56
|
+
params.require(:<%= resource_singular %>).permit(<%= params_list %>)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
index do
|
62
|
+
column :id
|
63
|
+
<% attributes.each do |pair| %><% field = pair.split(":")[0] %>
|
64
|
+
column :<%= field %>
|
65
|
+
<% end %>
|
66
|
+
column :updated_at
|
67
|
+
column :created_at
|
68
|
+
actions
|
69
|
+
end
|
70
|
+
|
71
|
+
show do
|
72
|
+
attributes_table do
|
73
|
+
row :id
|
74
|
+
<% attributes.each do |pair| %><% field = pair.split(":")[0] %>
|
75
|
+
row :<%= field %>
|
76
|
+
<% end %>
|
77
|
+
row :updated_at
|
78
|
+
row :created_at
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# See permitted parameters documentation:
|
83
|
+
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
|
84
|
+
#
|
85
|
+
# permit_params :list, :of, :attributes, :on, :model
|
86
|
+
#
|
87
|
+
# or
|
88
|
+
#
|
89
|
+
# permit_params do
|
90
|
+
# permitted = [:permitted, :attributes]
|
91
|
+
# permitted << :other if resource.something?
|
92
|
+
# permitted
|
93
|
+
# end
|
94
|
+
|
95
|
+
|
96
|
+
end
|
@@ -16,6 +16,7 @@ module JsonVoorhees
|
|
16
16
|
rspec
|
17
17
|
api_controller
|
18
18
|
include_middleware
|
19
|
+
cors_route
|
19
20
|
if options.admin?
|
20
21
|
make_admin
|
21
22
|
end
|
@@ -27,13 +28,33 @@ module JsonVoorhees
|
|
27
28
|
routes
|
28
29
|
make_controllers
|
29
30
|
if options.arcadex? && options.active_admin?
|
30
|
-
run "rails generate active_admin:resource arcadex::token"
|
31
|
+
#run "rails generate active_admin:resource arcadex::token"
|
32
|
+
custom_active_admin
|
31
33
|
end
|
34
|
+
if options.active_admin?
|
35
|
+
seed_database
|
36
|
+
end
|
37
|
+
run "wheneverize"
|
32
38
|
run_git
|
33
39
|
end
|
34
40
|
|
35
41
|
private
|
36
42
|
|
43
|
+
def seed_database
|
44
|
+
#db/seeds.rb
|
45
|
+
inject_into_file "db/seeds.rb", after: "# Mayor.create(name: 'Emanuel', city: cities.first)\n" do <<-'RUBY'
|
46
|
+
|
47
|
+
::Defcon::AdminUser.create({username: "admin", password: "password", password_confirmation: "password"})
|
48
|
+
|
49
|
+
RUBY
|
50
|
+
end
|
51
|
+
run "rake db:seed"
|
52
|
+
end
|
53
|
+
|
54
|
+
def custom_active_admin
|
55
|
+
template "active_admin_token_register.rb.erb", "app/admin/arcadex_token.rb"
|
56
|
+
end
|
57
|
+
|
37
58
|
def make_admin
|
38
59
|
if !options.active_admin?
|
39
60
|
if !options.arcadex? && !options.user?
|
@@ -92,12 +113,20 @@ module JsonVoorhees
|
|
92
113
|
end
|
93
114
|
|
94
115
|
def routes
|
116
|
+
route "mount Defcon::Engine, at: \'/\'"
|
95
117
|
route "root to: \"app_index#app\""
|
96
118
|
if !options.active_admin? && options.admin?
|
97
119
|
route "get \'admin\' => \'main#admin\', as: \"admin\" #admin_path"
|
98
120
|
end
|
99
121
|
end
|
100
122
|
|
123
|
+
def cors_route
|
124
|
+
route "#This is to handle the CORS preflight request, it only catches the options action.
|
125
|
+
controller \'api/v1/api\' do
|
126
|
+
match \'*unmatched_route\', :to => \'api/v1/api#route_options\', via: [:options]
|
127
|
+
end"
|
128
|
+
end
|
129
|
+
|
101
130
|
def make_controllers
|
102
131
|
generate "controller", "app_index app"
|
103
132
|
run "rm -f app/controllers/app_index_controller.rb"
|
@@ -159,7 +188,7 @@ module JsonVoorhees
|
|
159
188
|
gem 'type_cartographer'
|
160
189
|
gem 'devise', "~> 3.2.4"
|
161
190
|
if options.arcadex?
|
162
|
-
gem 'arcadex', '~> 1.1.
|
191
|
+
gem 'arcadex', '~> 1.1.3'
|
163
192
|
end
|
164
193
|
if options.admin?
|
165
194
|
gem 'autoprefixer-rails'
|
@@ -167,8 +196,11 @@ module JsonVoorhees
|
|
167
196
|
end
|
168
197
|
if options.active_admin?
|
169
198
|
gem 'activeadmin', :git => 'https://github.com/activeadmin/activeadmin.git', :branch => "master"
|
199
|
+
gem 'defcon', '~> 1.2.3'
|
170
200
|
end
|
171
201
|
gem 'authorization', :path => "gems/authorization"
|
202
|
+
gem 'whenever', :require => false
|
203
|
+
#gem 'websocket-rails'
|
172
204
|
end
|
173
205
|
|
174
206
|
def create_file_structure
|
@@ -0,0 +1,93 @@
|
|
1
|
+
ActiveAdmin.register Arcadex::Token do
|
2
|
+
|
3
|
+
config.per_page = 30
|
4
|
+
|
5
|
+
form do |f|
|
6
|
+
f.semantic_errors # shows errors on :base
|
7
|
+
#f.inputs # builds an input field for every attribute
|
8
|
+
f.inputs do
|
9
|
+
f.input :id
|
10
|
+
f.input :imageable_id
|
11
|
+
f.input :imageable_type
|
12
|
+
f.input :times_used
|
13
|
+
f.input :first_ip_address
|
14
|
+
f.input :current_ip_address
|
15
|
+
f.input :auth_token
|
16
|
+
f.input :expiration_minutes
|
17
|
+
f.input :updated_at
|
18
|
+
f.input :created_at
|
19
|
+
end
|
20
|
+
f.actions # adds the 'Submit' and 'Cancel' buttons
|
21
|
+
end
|
22
|
+
|
23
|
+
controller do
|
24
|
+
def create
|
25
|
+
@token = ::Arcadex::Token.new(token_params)
|
26
|
+
if @token.save
|
27
|
+
flash[:notice] = "Created Successfully!"
|
28
|
+
redirect_to resource_path @token
|
29
|
+
else
|
30
|
+
flash[:notice] = "#{@token.errors.full_messages}"
|
31
|
+
redirect_to new_resource_path @token
|
32
|
+
#super
|
33
|
+
#render :new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def update
|
38
|
+
@token = ::Arcadex::Token.find(params[:id])
|
39
|
+
if @token.update(token_params)
|
40
|
+
flash[:notice] = "Updated Successfully!"
|
41
|
+
redirect_to resource_path @token
|
42
|
+
else
|
43
|
+
flash.now[:notice] = "#{@token.errors.full_messages}"
|
44
|
+
render :edit
|
45
|
+
#super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy
|
50
|
+
@token = ::Arcadex::Token.find(params[:id])
|
51
|
+
@token.destroy
|
52
|
+
flash.now[:notice] = "Deleted Successfully!"
|
53
|
+
render :index
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def token_params
|
59
|
+
params.require(:token).permit(:times_used,:imageable_id,:imageable_type,:password_confirmation,:first_ip_address,:current_ip_address,:auth_token,:expiration_minutes)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
index do
|
64
|
+
column :id
|
65
|
+
column :imageable_id
|
66
|
+
column :imageable_type
|
67
|
+
column :times_used
|
68
|
+
column :first_ip_address
|
69
|
+
column :current_ip_address
|
70
|
+
column :auth_token
|
71
|
+
column :expiration_minutes
|
72
|
+
column :updated_at
|
73
|
+
column :created_at
|
74
|
+
actions
|
75
|
+
end
|
76
|
+
|
77
|
+
show do
|
78
|
+
attributes_table do
|
79
|
+
row :id
|
80
|
+
row :imageable_id
|
81
|
+
row :imageable_type
|
82
|
+
row :times_used
|
83
|
+
row :first_ip_address
|
84
|
+
row :current_ip_address
|
85
|
+
row :auth_token
|
86
|
+
row :expiration_minutes
|
87
|
+
row :updated_at
|
88
|
+
row :created_at
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
end
|
@@ -1,8 +1,32 @@
|
|
1
1
|
class Api::V1::ApiController < ::ActionController::API
|
2
2
|
|
3
|
+
after_filter :cors_set_access_control_headers
|
4
|
+
|
5
|
+
def route_options
|
6
|
+
cors_preflight_check
|
7
|
+
end
|
8
|
+
|
3
9
|
private
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
|
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-Max-Age'] = "1728000"
|
20
|
+
end
|
21
|
+
|
22
|
+
def cors_preflight_check
|
23
|
+
if request.method == 'OPTIONS'
|
24
|
+
request.headers['Access-Control-Allow-Origin'] = '*'
|
25
|
+
request.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
|
26
|
+
request.headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version, Token, Auth-Token, Email'
|
27
|
+
request.headers['Access-Control-Max-Age'] = '1728000'
|
28
|
+
render :text => '', :content_type => 'text/plain'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
8
32
|
end
|
@@ -1,6 +1,12 @@
|
|
1
1
|
class Api::V1::ApiController < ::ActionController::API
|
2
2
|
|
3
3
|
before_action :authenticate_user
|
4
|
+
after_filter :cors_set_access_control_headers
|
5
|
+
skip_before_filter :authenticate_user, :only => [:route_options]
|
6
|
+
|
7
|
+
def route_options
|
8
|
+
cors_preflight_check
|
9
|
+
end
|
4
10
|
|
5
11
|
private
|
6
12
|
|
@@ -23,4 +29,22 @@ class Api::V1::ApiController < ::ActionController::API
|
|
23
29
|
@instance_hash["current_token"]
|
24
30
|
end
|
25
31
|
end
|
32
|
+
|
33
|
+
def cors_set_access_control_headers
|
34
|
+
response.headers['Access-Control-Allow-Origin'] = '*'
|
35
|
+
response.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
|
36
|
+
response.headers['Access-Control-Allow-Headers'] = 'Origin, Content-Type, Accept, Authorization, Token, Auth-Token, Email'
|
37
|
+
response.headers['Access-Control-Max-Age'] = "1728000"
|
38
|
+
end
|
39
|
+
|
40
|
+
def cors_preflight_check
|
41
|
+
if request.method == 'OPTIONS'
|
42
|
+
request.headers['Access-Control-Allow-Origin'] = '*'
|
43
|
+
request.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
|
44
|
+
request.headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version, Token, Auth-Token, Email'
|
45
|
+
request.headers['Access-Control-Max-Age'] = '1728000'
|
46
|
+
render :text => '', :content_type => 'text/plain'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
26
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_voorhees
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cleophus Robinson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -57,6 +57,8 @@ files:
|
|
57
57
|
- config/routes.rb
|
58
58
|
- lib/generators/json_voorhees/app_make_admin/USAGE
|
59
59
|
- lib/generators/json_voorhees/app_make_admin/app_make_admin_generator.rb
|
60
|
+
- lib/generators/json_voorhees/app_make_admin/templates/dashboard.rb.erb
|
61
|
+
- lib/generators/json_voorhees/app_make_admin/templates/defcon_admin_register.rb.erb
|
60
62
|
- lib/generators/json_voorhees/app_make_admin/templates/views/_footer.html.erb
|
61
63
|
- lib/generators/json_voorhees/app_make_admin/templates/views/_header.html.erb
|
62
64
|
- lib/generators/json_voorhees/app_make_admin/templates/views/admin_home_no_user
|
@@ -75,6 +77,7 @@ files:
|
|
75
77
|
- lib/generators/json_voorhees/app_make_tests/templates/routing.rb.erb
|
76
78
|
- lib/generators/json_voorhees/app_make_user/USAGE
|
77
79
|
- lib/generators/json_voorhees/app_make_user/app_make_user_generator.rb
|
80
|
+
- lib/generators/json_voorhees/app_make_user/templates/active_admin_register.rb.erb
|
78
81
|
- lib/generators/json_voorhees/app_make_user/templates/user/include_authorization.rb
|
79
82
|
- lib/generators/json_voorhees/app_make_user/templates/user/specs/factory_girl.rb
|
80
83
|
- lib/generators/json_voorhees/app_make_user/templates/user/specs/model_specs.rb
|
@@ -102,8 +105,10 @@ files:
|
|
102
105
|
- lib/generators/json_voorhees/engine_scaffold/engine_scaffold_generator.rb
|
103
106
|
- lib/generators/json_voorhees/massive_scaffold/USAGE
|
104
107
|
- lib/generators/json_voorhees/massive_scaffold/massive_scaffold_generator.rb
|
108
|
+
- lib/generators/json_voorhees/massive_scaffold/templates/active_admin_register.rb.erb
|
105
109
|
- lib/generators/json_voorhees/setup_app/USAGE
|
106
110
|
- lib/generators/json_voorhees/setup_app/setup_app_generator.rb
|
111
|
+
- lib/generators/json_voorhees/setup_app/templates/active_admin_token_register.rb.erb
|
107
112
|
- lib/generators/json_voorhees/setup_app/templates/api_controller_no_arcadex.rb
|
108
113
|
- lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb
|
109
114
|
- lib/generators/json_voorhees/setup_app/templates/app_index_controller.rb
|