billet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +55 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/billet.gemspec +34 -0
- data/bin/console +15 -0
- data/bin/rspec +29 -0
- data/lib/billet/version.rb +5 -0
- data/lib/billet.rb +8 -0
- data/lib/generators/billet/namespace/USAGE +8 -0
- data/lib/generators/billet/namespace/namespace_generator.rb +165 -0
- data/lib/generators/billet/namespace/templates/Gemfile.erb +15 -0
- data/lib/generators/billet/namespace/templates/abilities/ability.rb.erb +14 -0
- data/lib/generators/billet/namespace/templates/assets/css.js.erb +4 -0
- data/lib/generators/billet/namespace/templates/assets/css.scss.erb +5 -0
- data/lib/generators/billet/namespace/templates/assets/js.js.erb +1 -0
- data/lib/generators/billet/namespace/templates/config/api_routes.rb.erb +13 -0
- data/lib/generators/billet/namespace/templates/config/locales/activerecord.yml.erb +12 -0
- data/lib/generators/billet/namespace/templates/config/locales/defaults.yml.erb +215 -0
- data/lib/generators/billet/namespace/templates/config/locales/module_name.yml.erb +5 -0
- data/lib/generators/billet/namespace/templates/config/locales/views.yml.erb +24 -0
- data/lib/generators/billet/namespace/templates/config/routes.rb.erb +3 -0
- data/lib/generators/billet/namespace/templates/controller_concerns/.keep +0 -0
- data/lib/generators/billet/namespace/templates/controller_concerns/api_current_identity.rb.erb +69 -0
- data/lib/generators/billet/namespace/templates/controller_concerns/current_identity.rb.erb +75 -0
- data/lib/generators/billet/namespace/templates/controllers/api_controllers/authorizations_controller.rb.erb +25 -0
- data/lib/generators/billet/namespace/templates/controllers/api_controllers/ping_controller.rb.erb +12 -0
- data/lib/generators/billet/namespace/templates/controllers/api_controllers/profiles_controller.rb.erb +14 -0
- data/lib/generators/billet/namespace/templates/controllers/api_controllers/projects_controller.rb.erb +35 -0
- data/lib/generators/billet/namespace/templates/controllers/api_controllers/user_identities_controller.rb.erb +14 -0
- data/lib/generators/billet/namespace/templates/controllers/crud_controllers/application_controller.rb.erb +93 -0
- data/lib/generators/billet/namespace/templates/controllers/crud_controllers/controller.rb.erb +1 -0
- data/lib/generators/billet/namespace/templates/controllers/crud_controllers/home_controller.rb.erb +11 -0
- data/lib/generators/billet/namespace/templates/drappers/application_drapper.rb.erb +25 -0
- data/lib/generators/billet/namespace/templates/drappers/concerns/display_name_glipper.rb.erb +32 -0
- data/lib/generators/billet/namespace/templates/drappers/concerns/timestamp_glipper.rb.erb +21 -0
- data/lib/generators/billet/namespace/templates/drappers/concerns/type_glipper.rb.erb +9 -0
- data/lib/generators/billet/namespace/templates/drappers/user_drapper.rb.erb +10 -0
- data/lib/generators/billet/namespace/templates/gemspec.erb +19 -0
- data/lib/generators/billet/namespace/templates/helpers/application_helper.rb.erb +27 -0
- data/lib/generators/billet/namespace/templates/lib/engine.rb.erb +13 -0
- data/lib/generators/billet/namespace/templates/lib/module.rb.erb +4 -0
- data/lib/generators/billet/namespace/templates/lib/version.rb.erb +3 -0
- data/lib/generators/billet/namespace/templates/views/api_views/application/index.json.jbuilder +6 -0
- data/lib/generators/billet/namespace/templates/views/api_views/application/show.json.jbuilder +1 -0
- data/lib/generators/billet/namespace/templates/views/api_views/authorizations/create.json.jbuilder +1 -0
- data/lib/generators/billet/namespace/templates/views/api_views/authorizations/failure.json.jbuilder +1 -0
- data/lib/generators/billet/namespace/templates/views/api_views/authorizations/index.json.jbuilder +4 -0
- data/lib/generators/billet/namespace/templates/views/api_views/ping/index.json.jbuilder +15 -0
- data/lib/generators/billet/namespace/templates/views/api_views/ping/secured.json.jbuilder +1 -0
- data/lib/generators/billet/namespace/templates/views/api_views/profiles/_detailed.json.jbuilder +6 -0
- data/lib/generators/billet/namespace/templates/views/api_views/projects/_show.json.jbuilder +6 -0
- data/lib/generators/billet/namespace/templates/views/api_views/user_identities/_short.json.jbuilder +6 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_analytics.html.haml +9 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_button_add.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_button_destroy.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_button_edit.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_button_index.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_button_show.html.haml +3 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_buttons_edit.html.haml +3 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_buttons_index.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_buttons_new.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_buttons_show.html.haml +3 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_container.html.haml +4 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_favicon.html.haml +15 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_flash.html.haml +4 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_footer.html.haml +4 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_form.html.haml +5 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_form_fields.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_header.html.haml +11 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_header_edit.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_header_index.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_header_new.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_header_show.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_logo.html.haml +1 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_metas.html.haml +13 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_names.html.haml +7 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_primary_menu.html.haml +0 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_row.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_row_header.html.haml +2 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_secondary_menu.html.haml +5 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_show.html.haml +14 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/_states.html.haml +9 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/edit.html.haml +5 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/index.html.haml +16 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/new.html.haml +5 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/application/show.html.haml +5 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/home/index.html.haml.erb +1 -0
- data/lib/generators/billet/namespace/templates/views/crud_views/layouts/application.html.haml.erb +23 -0
- metadata +139 -0
@@ -0,0 +1,215 @@
|
|
1
|
+
en:
|
2
|
+
date:
|
3
|
+
abbr_day_names:
|
4
|
+
- Sun
|
5
|
+
- Mon
|
6
|
+
- Tue
|
7
|
+
- Wed
|
8
|
+
- Thu
|
9
|
+
- Fri
|
10
|
+
- Sat
|
11
|
+
abbr_month_names:
|
12
|
+
-
|
13
|
+
- Jan
|
14
|
+
- Feb
|
15
|
+
- Mar
|
16
|
+
- Apr
|
17
|
+
- May
|
18
|
+
- Jun
|
19
|
+
- Jul
|
20
|
+
- Aug
|
21
|
+
- Sep
|
22
|
+
- Oct
|
23
|
+
- Nov
|
24
|
+
- Dec
|
25
|
+
day_names:
|
26
|
+
- Sunday
|
27
|
+
- Monday
|
28
|
+
- Tuesday
|
29
|
+
- Wednesday
|
30
|
+
- Thursday
|
31
|
+
- Friday
|
32
|
+
- Saturday
|
33
|
+
formats:
|
34
|
+
default: '%Y-%m-%d'
|
35
|
+
long: '%B %d, %Y'
|
36
|
+
short: '%b %d'
|
37
|
+
month_names:
|
38
|
+
-
|
39
|
+
- January
|
40
|
+
- February
|
41
|
+
- March
|
42
|
+
- April
|
43
|
+
- May
|
44
|
+
- June
|
45
|
+
- July
|
46
|
+
- August
|
47
|
+
- September
|
48
|
+
- October
|
49
|
+
- November
|
50
|
+
- December
|
51
|
+
order:
|
52
|
+
- :year
|
53
|
+
- :month
|
54
|
+
- :day
|
55
|
+
datetime:
|
56
|
+
distance_in_words:
|
57
|
+
about_x_hours:
|
58
|
+
one: 'about 1 hour'
|
59
|
+
other: 'about %{count} hours'
|
60
|
+
about_x_months:
|
61
|
+
one: 'about 1 month'
|
62
|
+
other: 'about %{count} months'
|
63
|
+
about_x_years:
|
64
|
+
one: 'about 1 year'
|
65
|
+
other: 'about %{count} years'
|
66
|
+
almost_x_years:
|
67
|
+
one: 'almost 1 year'
|
68
|
+
other: 'almost %{count} years'
|
69
|
+
half_a_minute: 'half a minute'
|
70
|
+
less_than_x_minutes:
|
71
|
+
one: 'less than a minute'
|
72
|
+
other: 'less than %{count} minutes'
|
73
|
+
less_than_x_seconds:
|
74
|
+
one: 'less than 1 second'
|
75
|
+
other: 'less than %{count} seconds'
|
76
|
+
over_x_years:
|
77
|
+
one: 'over 1 year'
|
78
|
+
other: 'over %{count} years'
|
79
|
+
x_days:
|
80
|
+
one: '1 day'
|
81
|
+
other: '%{count} days'
|
82
|
+
x_minutes:
|
83
|
+
one: '1 minute'
|
84
|
+
other: '%{count} minutes'
|
85
|
+
x_months:
|
86
|
+
one: '1 month'
|
87
|
+
other: '%{count} months'
|
88
|
+
x_seconds:
|
89
|
+
one: '1 second'
|
90
|
+
other: '%{count} seconds'
|
91
|
+
prompts:
|
92
|
+
day: Day
|
93
|
+
hour: Hour
|
94
|
+
minute: Minute
|
95
|
+
month: Month
|
96
|
+
second: Seconds
|
97
|
+
year: Year
|
98
|
+
errors: &errors
|
99
|
+
format: '%{attribute} %{message}'
|
100
|
+
messages:
|
101
|
+
accepted: must be accepted
|
102
|
+
blank: "can't be blank"
|
103
|
+
present: must be blank
|
104
|
+
confirmation: "doesn't match %{attribute}"
|
105
|
+
empty: can't be empty
|
106
|
+
equal_to: 'must be equal to %{count}'
|
107
|
+
even: 'must be even'
|
108
|
+
exclusion: 'is reserved'
|
109
|
+
greater_than: 'must be greater than %{count}'
|
110
|
+
greater_than_or_equal_to: must be greater than or equal to %{count}
|
111
|
+
inclusion: is not included in the list
|
112
|
+
invalid: is invalid
|
113
|
+
less_than: must be less than %{count}
|
114
|
+
less_than_or_equal_to: must be less than or equal to %{count}
|
115
|
+
not_a_number: is not a number
|
116
|
+
not_an_integer: must be an integer
|
117
|
+
odd: must be odd
|
118
|
+
record_invalid: 'Validation failed: %{errors}'
|
119
|
+
restrict_dependent_destroy:
|
120
|
+
one: "Cannot delete record because a dependent %{record} exists"
|
121
|
+
many: "Cannot delete record because dependent %{record} exist"
|
122
|
+
taken: has already been taken
|
123
|
+
too_long:
|
124
|
+
one: is too long (maximum is 1 character)
|
125
|
+
other: is too long (maximum is %{count} characters)
|
126
|
+
too_short:
|
127
|
+
one: is too short (minimum is 1 character)
|
128
|
+
other: is too short (minimum is %{count} characters)
|
129
|
+
wrong_length:
|
130
|
+
one: is the wrong length (should be 1 character)
|
131
|
+
other: is the wrong length (should be %{count} characters)
|
132
|
+
other_than: "must be other than %{count}"
|
133
|
+
template:
|
134
|
+
body: ! 'There were problems with the following fields:'
|
135
|
+
header:
|
136
|
+
one: 1 error prohibited this %{model} from being saved
|
137
|
+
other: '%{count} errors prohibited this %{model} from being saved'
|
138
|
+
helpers:
|
139
|
+
select:
|
140
|
+
prompt: Please select
|
141
|
+
submit:
|
142
|
+
create: Create
|
143
|
+
submit: Save %{model}
|
144
|
+
update: Update
|
145
|
+
number:
|
146
|
+
currency:
|
147
|
+
format:
|
148
|
+
delimiter: ','
|
149
|
+
format: '%u%n'
|
150
|
+
precision: 2
|
151
|
+
separator: .
|
152
|
+
significant: false
|
153
|
+
strip_insignificant_zeros: false
|
154
|
+
unit: $
|
155
|
+
format:
|
156
|
+
delimiter: ','
|
157
|
+
precision: 3
|
158
|
+
separator: .
|
159
|
+
significant: false
|
160
|
+
strip_insignificant_zeros: false
|
161
|
+
human:
|
162
|
+
decimal_units:
|
163
|
+
format: '%n %u'
|
164
|
+
units:
|
165
|
+
billion: Billion
|
166
|
+
million: Million
|
167
|
+
quadrillion: Quadrillion
|
168
|
+
thousand: Thousand
|
169
|
+
trillion: Trillion
|
170
|
+
unit: ''
|
171
|
+
format:
|
172
|
+
delimiter: ''
|
173
|
+
precision: 3
|
174
|
+
significant: true
|
175
|
+
strip_insignificant_zeros: true
|
176
|
+
storage_units:
|
177
|
+
format: '%n %u'
|
178
|
+
units:
|
179
|
+
byte:
|
180
|
+
one: Byte
|
181
|
+
other: Bytes
|
182
|
+
gb: GB
|
183
|
+
kb: KB
|
184
|
+
mb: MB
|
185
|
+
tb: TB
|
186
|
+
percentage:
|
187
|
+
format:
|
188
|
+
delimiter: ''
|
189
|
+
format: "%n%"
|
190
|
+
precision:
|
191
|
+
format:
|
192
|
+
delimiter: ''
|
193
|
+
support:
|
194
|
+
array:
|
195
|
+
last_word_connector: ', and '
|
196
|
+
two_words_connector: ' and '
|
197
|
+
words_connector: ', '
|
198
|
+
time:
|
199
|
+
am: am
|
200
|
+
formats:
|
201
|
+
default: '%a, %d %b %Y %H:%M:%S %z'
|
202
|
+
long: '%B %d, %Y %H:%M'
|
203
|
+
short: '%d %b %H:%M'
|
204
|
+
pm: pm
|
205
|
+
# remove these aliases after 'activemodel' and 'activerecord' namespaces are removed from Rails repository
|
206
|
+
activemodel:
|
207
|
+
errors:
|
208
|
+
<<: *errors
|
209
|
+
activerecord:
|
210
|
+
errors:
|
211
|
+
<<: *errors
|
212
|
+
|
213
|
+
time_ago_in_words:
|
214
|
+
ago: "%{sencence} ago"
|
215
|
+
since: "%{sencence} since"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
en:
|
2
|
+
<%= singular_name %>:
|
3
|
+
application:
|
4
|
+
index:
|
5
|
+
header: "%{Models}"
|
6
|
+
button: "Back"
|
7
|
+
new:
|
8
|
+
button: "Add new one"
|
9
|
+
header: "%{display_name}"
|
10
|
+
create:
|
11
|
+
button: "Add %{model}"
|
12
|
+
edit:
|
13
|
+
button: "Edit"
|
14
|
+
header: "Edit %{display_name}"
|
15
|
+
update:
|
16
|
+
button: "Save Changes"
|
17
|
+
destroy:
|
18
|
+
button: "Destroy"
|
19
|
+
confirm: "Are you sure that you want to delete %{model}? It can't be restored!"
|
20
|
+
show:
|
21
|
+
html: "Go"
|
22
|
+
header: "%{Model} #%{id}"
|
23
|
+
home:
|
24
|
+
title: "Home title"
|
File without changes
|
data/lib/generators/billet/namespace/templates/controller_concerns/api_current_identity.rb.erb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
module CurrentIdentity
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
helper_method :current_user, :signed_in?, :current_config
|
7
|
+
|
8
|
+
<%- if @access.cancan? -%>
|
9
|
+
rescue_from CanCan::AccessDenied do |exception|
|
10
|
+
render json: { error: exception.message }, status: 401
|
11
|
+
end
|
12
|
+
<%- end -%>
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
<%- if @access.cancan? -%>
|
17
|
+
def require_login!(options={}, &block)
|
18
|
+
block ||= Proc.new {
|
19
|
+
authorize!(:secured, :all)
|
20
|
+
authorize!(:anything, :all)
|
21
|
+
}
|
22
|
+
before_action(options, &block)
|
23
|
+
define_method(:begin_of_association_chain) { current_user }
|
24
|
+
end
|
25
|
+
<%- end -%>
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def current_user
|
31
|
+
return @user if @user
|
32
|
+
return nil unless header_token.present?
|
33
|
+
@user = user_application.try(:user)
|
34
|
+
end
|
35
|
+
|
36
|
+
def current_ability
|
37
|
+
@current_ability ||= <%= class_name %>::Ability.new(current_user)
|
38
|
+
end
|
39
|
+
|
40
|
+
def user_application
|
41
|
+
UserApplication.find_by!(token: header_token)
|
42
|
+
rescue ActiveRecord::RecordNotFound
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def sign_in(user_identity)
|
47
|
+
if user_identity.valid? && user_identity.user
|
48
|
+
@user = user_identity.user
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def signed_in?
|
53
|
+
current_user.present?
|
54
|
+
end
|
55
|
+
|
56
|
+
def header_key
|
57
|
+
settings.header_key
|
58
|
+
end
|
59
|
+
|
60
|
+
def header_token
|
61
|
+
request.headers[header_key] || params[header_key]
|
62
|
+
end
|
63
|
+
|
64
|
+
def current_config
|
65
|
+
@current_config ||= ::Settings.default_user_config
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
module CurrentIdentity
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
HELPER_METHODS = [
|
5
|
+
:url_after_create,
|
6
|
+
:url_after_destroy,
|
7
|
+
:url_after_confirmation,
|
8
|
+
:provider_provided?,
|
9
|
+
:current_ability,
|
10
|
+
:current_config,
|
11
|
+
:current_user,
|
12
|
+
:signed_in?,
|
13
|
+
:user_active?,
|
14
|
+
:signed_out?
|
15
|
+
]
|
16
|
+
|
17
|
+
included do
|
18
|
+
helper_method(*HELPER_METHODS)
|
19
|
+
|
20
|
+
rescue_from CanCan::AccessDenied do |exception|
|
21
|
+
redirect_to main_app.root_url, :alert => exception.message
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def sign_out
|
27
|
+
session[:sign_out] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
def provider_provided?(provider)
|
31
|
+
signed_in? && current_user.user_identities.provider_exists?(provider)
|
32
|
+
end
|
33
|
+
|
34
|
+
def current_ability
|
35
|
+
@current_ability ||= <%= class_name %>::Ability.new(current_user)
|
36
|
+
end
|
37
|
+
|
38
|
+
def current_config
|
39
|
+
@current_config ||= ::Settings.default_user_config
|
40
|
+
end
|
41
|
+
|
42
|
+
def current_user
|
43
|
+
authenticator['current_user']
|
44
|
+
end
|
45
|
+
|
46
|
+
def signed_in?
|
47
|
+
authenticator['signed_in?']
|
48
|
+
end
|
49
|
+
|
50
|
+
def user_active?
|
51
|
+
authenticator['user_active?']
|
52
|
+
end
|
53
|
+
|
54
|
+
def signed_out?
|
55
|
+
authenticator['signed_out?']
|
56
|
+
end
|
57
|
+
|
58
|
+
def url_after_create
|
59
|
+
auth_in_url
|
60
|
+
end
|
61
|
+
|
62
|
+
def url_after_destroy
|
63
|
+
root_url
|
64
|
+
end
|
65
|
+
|
66
|
+
def url_after_confirmation
|
67
|
+
root_url
|
68
|
+
end
|
69
|
+
|
70
|
+
private def authenticator
|
71
|
+
@authenticator ||= request.env.fetch('authenticator', {})
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
class AuthorizationsController < ::<%= class_name %>Controller
|
3
|
+
|
4
|
+
def index
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
user_identity = UserIdentity.find_or_create_with_omniauth(permitted_params, current_user)
|
9
|
+
if signed_in?
|
10
|
+
@app = user_application
|
11
|
+
else
|
12
|
+
sign_in user_identity
|
13
|
+
render 'failure' and return unless signed_in?
|
14
|
+
@app = current_user.user_applications.create
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def permitted_params
|
21
|
+
params
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
class ProfilesController < ::<%= class_name %>Controller
|
3
|
+
require_login!
|
4
|
+
before_filter(only: :show) { authorize!(:read, resource) }
|
5
|
+
before_filter(only: :update) { authorize!(:update, resource) }
|
6
|
+
|
7
|
+
unobtrusive resource_class: User,
|
8
|
+
resource: -> { current_user },
|
9
|
+
relationship_name: :users
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
class ProjectsController < ::<%= class_name %>Controller
|
3
|
+
require_login!
|
4
|
+
before_filter(only: :show) { authorize!(:read, resource) }
|
5
|
+
before_filter(only: :update) { authorize!(:update, resource) }
|
6
|
+
before_filter(only: :index) { authorize!(:read, resource_class) }
|
7
|
+
before_filter(only: :create) { authorize!(:create, resource_class) }
|
8
|
+
|
9
|
+
unobtrusive finder_method: :find_by_slug!,
|
10
|
+
resource_class: Project,
|
11
|
+
relationship_name: :projects,
|
12
|
+
permitted_params_key: :project,
|
13
|
+
permitted_params_create_value: [:name],
|
14
|
+
permitted_params_update_value: [:name]
|
15
|
+
paginate!
|
16
|
+
|
17
|
+
def index
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
build_resource
|
25
|
+
update_resource
|
26
|
+
respond_with resource
|
27
|
+
end
|
28
|
+
|
29
|
+
def update
|
30
|
+
update_resource
|
31
|
+
respond_with resource
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
class UserIdentitiesController < ::<%= class_name %>Controller
|
3
|
+
require_login!
|
4
|
+
|
5
|
+
unobtrusive resource_class: UserIdentity,
|
6
|
+
relationship_name: :user_identities
|
7
|
+
|
8
|
+
def destroy
|
9
|
+
destroy_resource
|
10
|
+
respond_with resource
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
class ApplicationController < ::ApplicationController
|
3
|
+
include ::Susanin
|
4
|
+
include ::MuteAction
|
5
|
+
include ::StateMachineAbilities
|
6
|
+
include ::Paginator
|
7
|
+
<%- if @kind.api? -%>
|
8
|
+
include ::<%= class_name %>::CurrentIdentity
|
9
|
+
<%- end -%>
|
10
|
+
<%- unless @access.cancan? -%>
|
11
|
+
include ::MockAuthorization
|
12
|
+
<%- end -%>
|
13
|
+
<%- if @access.cancan? -%>
|
14
|
+
include CanCan::ControllerAdditions
|
15
|
+
include <%= class_name %>::CurrentIdentity
|
16
|
+
|
17
|
+
<%- end -%>
|
18
|
+
meta_for(:title, :suffix, Settings.application.name)
|
19
|
+
|
20
|
+
<%- if @kind.api? -%>
|
21
|
+
respond_to :json
|
22
|
+
self.responder = <%= class_name %>::ApiResponder
|
23
|
+
|
24
|
+
<%- end -%>
|
25
|
+
susanin do
|
26
|
+
[
|
27
|
+
# [:root, ->(r) { [(signed_in? ? :client : :public), r] }]
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
<%- if @access.cancan? && @begin_chain -%>
|
32
|
+
before_filter :authorize_<%= @begin_chain -%>!
|
33
|
+
|
34
|
+
<%- end -%>
|
35
|
+
<%- if @begin_chain -%>
|
36
|
+
helper_method :<%= @begin_chain -%>
|
37
|
+
|
38
|
+
<%- end -%>
|
39
|
+
<%- if @kind.api? -%>
|
40
|
+
rescue_from ActiveRecord::RecordNotFound do |exception|
|
41
|
+
render json: { error: exception.message }, status: 404
|
42
|
+
end
|
43
|
+
|
44
|
+
rescue_from ParamsConverter::ParamsConverterError do |exception|
|
45
|
+
render json: { error: exception.message }, status: 401
|
46
|
+
end
|
47
|
+
|
48
|
+
<%- end -%>
|
49
|
+
<%- if @access.cancan? -%>
|
50
|
+
check_authorization
|
51
|
+
rescue_from CanCan::AccessDenied do |exception|
|
52
|
+
redirect_to main_app.root_url, :alert => exception.message
|
53
|
+
end
|
54
|
+
|
55
|
+
<%- end -%>
|
56
|
+
<%- if @access.http? -%>
|
57
|
+
http_basic_authenticate_with name: Settings.admin.name, password: Settings.admin.password
|
58
|
+
|
59
|
+
<%- end -%>
|
60
|
+
protected
|
61
|
+
|
62
|
+
<%- if @begin_chain -%>
|
63
|
+
def title_prefix
|
64
|
+
<%= @begin_chain -%>.name
|
65
|
+
end
|
66
|
+
|
67
|
+
<%- end -%>
|
68
|
+
<%- if @begin_chain -%>
|
69
|
+
def <%= @begin_chain %>
|
70
|
+
@<%= @begin_chain %> ||= current_user.try(:company)
|
71
|
+
end
|
72
|
+
|
73
|
+
<%- end -%>
|
74
|
+
<%- if @begin_chain -%>
|
75
|
+
def begin_of_association_chain
|
76
|
+
<%= @begin_chain %>
|
77
|
+
end
|
78
|
+
|
79
|
+
<%- end -%>
|
80
|
+
<%- if @begin_chain -%>
|
81
|
+
def current_ability
|
82
|
+
@current_ability ||= <%= class_name %>::Ability.new(current_user, <%= @begin_chain -%>)
|
83
|
+
end
|
84
|
+
|
85
|
+
<%- end -%>
|
86
|
+
<%- if @access.cancan? && @begin_chain -%>
|
87
|
+
def authorize_<%= @begin_chain %>!
|
88
|
+
authorize! :login, <%= @begin_chain %>
|
89
|
+
end
|
90
|
+
|
91
|
+
<%- end -%>
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= class_name %>Controller = <%= class_name %>::ApplicationController
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
class ApplicationDrapper < Glipper::Base
|
3
|
+
decorates ActiveRecord::Base
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def engine_root
|
7
|
+
<%= class_name %>::Engine.root
|
8
|
+
end
|
9
|
+
|
10
|
+
def root_classes
|
11
|
+
[ActiveRecord::Base, ActiveRecord::Relation, Array]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
include <%= class_name %>::DisplayNameGlipper
|
16
|
+
include <%= class_name %>::TypeGlipper
|
17
|
+
include <%= class_name %>::ImageGlipper
|
18
|
+
include <%= class_name %>::TimestampGlipper
|
19
|
+
|
20
|
+
def decorate(another_resource)
|
21
|
+
<%= class_name %>::ApplicationDrapper.decorate(another_resource, self.helpers)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
module DisplayNameGlipper
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def blank_display_name
|
6
|
+
self.blank_display_name_backward
|
7
|
+
end
|
8
|
+
|
9
|
+
def blank_display_name_backward
|
10
|
+
self.blank_display_name_assumption ? resource.public_send(self.blank_display_name_assumption) : self.blank_display_name_default
|
11
|
+
end
|
12
|
+
|
13
|
+
def blank_display_name_assumptions
|
14
|
+
%w{full_name name title subject}
|
15
|
+
end
|
16
|
+
|
17
|
+
def blank_display_name_assumption
|
18
|
+
Array.wrap(self.blank_display_name_assumptions).find do |method_name|
|
19
|
+
resource.respond_to?(method_name) && resource.public_send(method_name).presence
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def blank_display_name_default
|
24
|
+
o.id ? "#{resource.class.model_name.human} #{resource.id}" : "New #{resource.class.model_name.human}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def display_name(options={})
|
28
|
+
self.blank_display_name
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
module TimestampGlipper
|
3
|
+
|
4
|
+
def timestamp(field=:created_at, format=:default, config=Veil.config)
|
5
|
+
h.content_tag :span, get_date(field),
|
6
|
+
data: { :toggle => "tooltip", :placement => "top", :timestamp => get_date(field), 'timestamp-format' => timestamp_format(field, format) },
|
7
|
+
class: 'timestamp',
|
8
|
+
title: get_date(field)
|
9
|
+
end
|
10
|
+
|
11
|
+
# possible values: fromNow, default
|
12
|
+
private def timestamp_format(field, format)
|
13
|
+
format
|
14
|
+
end
|
15
|
+
|
16
|
+
private def get_date(field)
|
17
|
+
o.public_send(field).try(:iso8601) || '-'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|