microservice 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/microservice_manifest.js +2 -0
  6. data/app/assets/images/microservice/favicon.ico +0 -0
  7. data/app/assets/images/microservice/logo.svg +51 -0
  8. data/app/assets/javascripts/microservice/application.js +21 -0
  9. data/app/assets/javascripts/microservice/microservice.js +0 -0
  10. data/app/assets/stylesheets/microservice/application.css +16 -0
  11. data/app/assets/stylesheets/microservice/microservice.css +0 -0
  12. data/app/controllers/microservice/application_controller.rb +58 -0
  13. data/app/controllers/microservice/entities_controller.rb +138 -0
  14. data/app/controllers/microservice/omniauth_callbacks_controller.rb +36 -0
  15. data/app/controllers/microservice/welcome_controller.rb +8 -0
  16. data/app/helpers/microservice/application_helper.rb +216 -0
  17. data/app/helpers/microservice/breadcrumbs_helper.rb +89 -0
  18. data/app/jobs/microservice/application_job.rb +5 -0
  19. data/app/mailers/microservice/application_mailer.rb +13 -0
  20. data/app/mailers/microservice/devise_mailer.rb +13 -0
  21. data/app/models/microservice/concerns/entity_cloneable.rb +40 -0
  22. data/app/models/microservice/concerns/entity_model.rb +118 -0
  23. data/app/models/microservice/concerns/entity_movable.rb +27 -0
  24. data/app/models/microservice/concerns/entity_naming.rb +95 -0
  25. data/app/models/microservice/concerns/user_model.rb +36 -0
  26. data/app/views/layouts/microservice/application.html.erb +26 -0
  27. data/app/views/layouts/microservice/mailer.html.erb +13 -0
  28. data/app/views/layouts/microservice/mailer.text.erb +1 -0
  29. data/app/views/microservice/common/_no_data.html.erb +6 -0
  30. data/app/views/microservice/common/error.html.erb +7 -0
  31. data/app/views/microservice/common/error.json.jbuilder +3 -0
  32. data/app/views/microservice/entities/_card.html.erb +17 -0
  33. data/app/views/microservice/entities/_form.html.erb +0 -0
  34. data/app/views/microservice/entities/edit.html.erb +16 -0
  35. data/app/views/microservice/entities/index.html.erb +7 -0
  36. data/app/views/microservice/entities/new.html.erb +19 -0
  37. data/app/views/microservice/entities/show.html.erb +3 -0
  38. data/app/views/microservice/welcome/index.html.erb +1 -0
  39. data/config/initializers/devise.rb +270 -0
  40. data/config/initializers/microservice.rb +5 -0
  41. data/config/initializers/sso.rb +78 -0
  42. data/config/locales/en.yml +55 -0
  43. data/config/routes.rb +5 -0
  44. data/db/migrate/20170618202500_create_users.rb +51 -0
  45. data/lib/microservice.rb +27 -0
  46. data/lib/microservice/engine.rb +16 -0
  47. data/lib/microservice/settings.rb +62 -0
  48. data/lib/microservice/version.rb +3 -0
  49. data/lib/tasks/microservice_tasks.rake +4 -0
  50. metadata +330 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
7
+ <title><%= html_title %></title>
8
+ <link rel="icon" href="<%= favicon_path %>"/>
9
+ <%= csrf_meta_tags %>
10
+ <%= yield :html_head_before_assets %>
11
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
12
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
13
+ <%= javascript_tag do %>
14
+ I18n.defaultLocale = "<%= I18n.default_locale %>";
15
+ I18n.locale = "<%= I18n.locale %>";
16
+ <% end %>
17
+ <%= yield :html_head %>
18
+ </head>
19
+ <body>
20
+ <%= yield %>
21
+ </div>
22
+
23
+ <!-- __EP_.O.K.__ SITE: <%= Microservice::Settings.host_name %> -->
24
+ </body>
25
+
26
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,6 @@
1
+ <div class="ui icon info message">
2
+ <i class="announcement icon"></i>
3
+ <div class="content">
4
+ <%= t(:text_no_data) %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,7 @@
1
+ <div class="ui error message">
2
+ <ul class="list">
3
+ <% @errors.each do |error| %>
4
+ <li><%= error %></li>
5
+ <% end %>
6
+ </ul>
7
+ </div>
@@ -0,0 +1,3 @@
1
+ json.errors @errors do |error|
2
+ json.error error
3
+ end
@@ -0,0 +1,17 @@
1
+ <div class="card">
2
+ <div class="content">
3
+ <i class="right floated icon <%= entity.css_class %>"></i>
4
+ <%= link_to_entity(entity, class: 'header', no_icon: true) %>
5
+ <div class="meta">
6
+ </div>
7
+ <% if entity.respond_to?(:description) %>
8
+ <div class="description">
9
+ <%= simple_format(entity.description) %>
10
+ </div>
11
+ <% end %>
12
+ </div>
13
+ <div class="extra content">
14
+ <%= link_to_entity(entity, :edit, class: 'ui icon button', no_label: true) %>
15
+ <%= link_to_entity(entity, :delete, class: 'ui icon button', no_label: true) %>
16
+ </div>
17
+ </div>
@@ -0,0 +1,16 @@
1
+ <%= semantic_ui_form_for(@entity.model_route_array, remote: request.xhr?) do |f| %>
2
+ <% if !request.xhr? %>
3
+ <%= f.error_messages %>
4
+ <% end %>
5
+
6
+ <%= render 'form' %>
7
+
8
+ <% if !request.xhr? %>
9
+ <%= f.submit t(:button_update), class: 'ui primary button' %>
10
+ <% end %>
11
+ <% end %>
12
+ <% if request.xhr? %>
13
+ <script type="text/javascript">
14
+ updateSemanticElements($('#<%= dom_id(@entity.polymorphic_class, :edit) %>'));
15
+ </script>
16
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% if @entities.blank? %>
2
+ <%= render 'common/no_data' %>
3
+ <% else %>
4
+ <div class="ui cards">
5
+ <%= render partial: 'card', collection: @entities, as: :entity %>
6
+ </div>
7
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <%= semantic_ui_form_for(@entity.model_route_array, remote: request.xhr?) do |f| %>
2
+ <%= hidden_field_tag(:type, params[:type]) if params[:type] && controller.allow_custom_type %>
3
+ <%= hidden_field_tag(:copy_from, params[:copy_from]) if params[:copy_from] %>
4
+
5
+ <% if !request.xhr? %>
6
+ <%= f.error_messages %>
7
+ <% end %>
8
+
9
+ <%= render 'form' %>
10
+
11
+ <% if !request.xhr? %>
12
+ <%= f.submit t(:button_create), class: 'ui primary button' %>
13
+ <% end %>
14
+ <% end %>
15
+ <% if request.xhr? %>
16
+ <script type="text/javascript">
17
+ updateSemanticElements($('#<%= dom_id(@entity.polymorphic_class, :new) %>'));
18
+ </script>
19
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <div class="ui cards">
2
+ <%= render partial: 'card', locals: {entity: @entity} %>
3
+ </div>
@@ -0,0 +1,270 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth.
2
+ # Many of these configuration options can be set straight in your model.
3
+ Devise.setup do |config|
4
+ # ==> Mailer Configuration
5
+ # Configure the e-mail address which will be shown in Devise::Mailer,
6
+ # note that it will be overwritten if you use your own mailer class
7
+ # with default "from" parameter.
8
+ # config.mailer_sender = 'no-reply@example.com'
9
+
10
+ # Configure the class responsible to send e-mails.
11
+ config.mailer = 'Microservice::DeviseMailer'
12
+
13
+ # ==> ORM configuration
14
+ # Load and configure the ORM. Supports :active_record (default) and
15
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
16
+ # available as additional gems.
17
+ require 'devise/orm/active_record'
18
+
19
+ # ==> Configuration for any authentication mechanism
20
+ # Configure which keys are used when authenticating a user. The default is
21
+ # just :email. You can configure it to use [:username, :subdomain], so for
22
+ # authenticating a user, both parameters are required. Remember that those
23
+ # parameters are used only when authenticating and not when retrieving from
24
+ # session. If you need permissions, you should implement that in a before filter.
25
+ # You can also supply a hash where the value is a boolean determining whether
26
+ # or not authentication should be aborted when the value is not present.
27
+ config.authentication_keys = [:email]
28
+
29
+ # Configure parameters from the request object used for authentication. Each entry
30
+ # given should be a request method and it will automatically be passed to the
31
+ # find_for_authentication method and considered in your model lookup. For instance,
32
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
33
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
34
+ # config.request_keys = []
35
+ # config.request_keys = {subdomain: false}
36
+
37
+ # Configure which authentication keys should be case-insensitive.
38
+ # These keys will be downcased upon creating or modifying a user and when used
39
+ # to authenticate or find a user. Default is :email.
40
+ config.case_insensitive_keys = [:email]
41
+
42
+ # Configure which authentication keys should have whitespace stripped.
43
+ # These keys will have whitespace before and after removed upon creating or
44
+ # modifying a user and when used to authenticate or find a user. Default is :email.
45
+ config.strip_whitespace_keys = [:email]
46
+
47
+ # Tell if authentication through request.params is enabled. True by default.
48
+ # It can be set to an array that will enable params authentication only for the
49
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
50
+ # enable it only for database (email + password) authentication.
51
+ # config.params_authenticatable = true
52
+
53
+ # Tell if authentication through HTTP Auth is enabled. False by default.
54
+ # It can be set to an array that will enable http authentication only for the
55
+ # given strategies, for example, `config.http_authenticatable = [:database]` will
56
+ # enable it only for database authentication. The supported strategies are:
57
+ # :database = Support basic authentication with authentication key + password
58
+ # config.http_authenticatable = false
59
+
60
+ # If 401 status code should be returned for AJAX requests. True by default.
61
+ # config.http_authenticatable_on_xhr = true
62
+
63
+ # The realm used in Http Basic Authentication. 'Application' by default.
64
+ # config.http_authentication_realm = 'Application'
65
+
66
+ # It will change confirmation, password recovery and other workflows
67
+ # to behave the same regardless if the e-mail provided was right or wrong.
68
+ # Does not affect registerable.
69
+ # config.paranoid = true
70
+
71
+ # By default Devise will store the user in session. You can skip storage for
72
+ # particular strategies by setting this option.
73
+ # Notice that if you are skipping storage for all authentication paths, you
74
+ # may want to disable generating routes to Devise's sessions controller by
75
+ # passing skip: :sessions to `devise_for` in your config/routes.rb
76
+ config.skip_session_storage = [:http_auth, :token_auth]
77
+
78
+ # By default, Devise cleans up the CSRF token on authentication to
79
+ # avoid CSRF token fixation attacks. This means that, when using AJAX
80
+ # requests for sign in and sign up, you need to get a new CSRF token
81
+ # from the server. You can disable this option at your own risk.
82
+ # config.clean_up_csrf_token_on_authentication = true
83
+
84
+ # ==> Configuration for :database_authenticatable
85
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
86
+ # using other encryptors, it sets how many times you want the password re-encrypted.
87
+ #
88
+ # Limiting the stretches to just one in testing will increase the performance of
89
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
90
+ # a value less than 10 in other environments. Note that, for bcrypt (the default
91
+ # encryptor), the cost increases exponentially with the number of stretches (e.g.
92
+ # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
93
+ config.stretches = Rails.env.test? ? 1 : 10
94
+
95
+ # Setup a pepper to generate the encrypted password.
96
+ # config.pepper = '2932b36d40b6551deeaf1575651a03173e8315efe57fae0f044dbbe56020942b7ef8bfb4c448de29a38a9d8c72da41a4382684ce438a67ddbf895a84427405a9'
97
+
98
+ # ==> Configuration for :confirmable
99
+ # A period that the user is allowed to access the website even without
100
+ # confirming their account. For instance, if set to 2.days, the user will be
101
+ # able to access the website for two days without confirming their account,
102
+ # access will be blocked just in the third day. Default is 0.days, meaning
103
+ # the user cannot access the website without confirming their account.
104
+ # config.allow_unconfirmed_access_for = 2.days
105
+
106
+ # A period that the user is allowed to confirm their account before their
107
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
108
+ # their account within 3 days after the mail was sent, but on the fourth day
109
+ # their account can't be confirmed with the token any more.
110
+ # Default is nil, meaning there is no restriction on how long a user can take
111
+ # before confirming their account.
112
+ # config.confirm_within = 3.days
113
+
114
+ # If true, requires any email changes to be confirmed (exactly the same way as
115
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
116
+ # db field (see migrations). Until confirmed, new email is stored in
117
+ # unconfirmed_email column, and copied to email column on successful confirmation.
118
+ config.reconfirmable = true
119
+
120
+ # Defines which key will be used when confirming an account
121
+ config.confirmation_keys = [:email]
122
+
123
+ # ==> Configuration for :rememberable
124
+ # The time the user will be remembered without asking for credentials again.
125
+ # config.remember_for = 2.weeks
126
+
127
+ # Invalidates all the remember me tokens when the user signs out.
128
+ config.expire_all_remember_me_on_sign_out = true
129
+
130
+ # If true, extends the user's remember period when remembered via cookie.
131
+ # config.extend_remember_period = false
132
+
133
+ # Options to be passed to the created cookie. For instance, you can set
134
+ # secure: true in order to force SSL only cookies.
135
+ # config.rememberable_options = {}
136
+
137
+ # ==> Configuration for :validatable
138
+ # Range for password length.
139
+ config.password_length = 8..72
140
+
141
+ # Email regex used to validate email formats. It simply asserts that
142
+ # one (and only one) @ exists in the given string. This is mainly
143
+ # to give user feedback and not to assert the e-mail validity.
144
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
145
+
146
+ # ==> Configuration for :timeoutable
147
+ # The time you want to timeout the user session without activity. After this
148
+ # time the user will be asked for credentials again. Default is 30 minutes.
149
+ config.timeout_in = 60.minutes
150
+
151
+ # ==> Configuration for :lockable
152
+ # Defines which strategy will be used to lock an account.
153
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
154
+ # :none = No lock strategy. You should handle locking by yourself.
155
+ config.lock_strategy = :failed_attempts
156
+
157
+ # Defines which key will be used when locking and unlocking an account
158
+ config.unlock_keys = [:email]
159
+
160
+ # Defines which strategy will be used to unlock an account.
161
+ # :email = Sends an unlock link to the user email
162
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
163
+ # :both = Enables both strategies
164
+ # :none = No unlock strategy. You should handle unlocking by yourself.
165
+ config.unlock_strategy = :both
166
+
167
+ # Number of authentication tries before locking an account if lock_strategy
168
+ # is failed attempts.
169
+ config.maximum_attempts = 20
170
+
171
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
172
+ config.unlock_in = 1.hour
173
+
174
+ # Warn on the last attempt before the account is locked.
175
+ config.last_attempt_warning = true
176
+
177
+ # ==> Configuration for :recoverable
178
+ #
179
+ # Defines which key will be used when recovering the password for an account
180
+ config.reset_password_keys = [:email]
181
+
182
+ # Time interval you can reset your password with a reset password key.
183
+ # Don't put a too small interval or your users won't have the time to
184
+ # change their passwords.
185
+ config.reset_password_within = 6.hours
186
+
187
+ # When set to false, does not sign a user in automatically after their password is
188
+ # reset. Defaults to true, so a user is signed in automatically after a reset.
189
+ # config.sign_in_after_reset_password = true
190
+
191
+ # ==> Configuration for :encryptable
192
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
193
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
194
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
195
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
196
+ # REST_AUTH_SITE_KEY to pepper).
197
+ #
198
+ # Require the `devise-encryptable` gem when using anything other than bcrypt
199
+ # config.encryptor = :sha512
200
+
201
+ # ==> Scopes configuration
202
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
203
+ # "users/sessions/new". It's turned off by default because it's slower if you
204
+ # are using only default views.
205
+ config.scoped_views = true
206
+
207
+ # Configure the default scope given to Warden. By default it's the first
208
+ # devise role declared in your routes (usually :user).
209
+ # config.default_scope = :user
210
+
211
+ # Set this configuration to false if you want /users/sign_out to sign out
212
+ # only the current scope. By default, Devise signs out all scopes.
213
+ # config.sign_out_all_scopes = true
214
+
215
+ # ==> Navigation configuration
216
+ # Lists the formats that should be treated as navigational. Formats like
217
+ # :html, should redirect to the sign in page when the user does not have
218
+ # access, but formats like :xml or :json, should return 401.
219
+ #
220
+ # If you have any extra navigational formats, like :iphone or :mobile, you
221
+ # should add them to the navigational formats lists.
222
+ #
223
+ # The "*/*" below is required to match Internet Explorer requests.
224
+ # config.navigational_formats = ['*/*', :html]
225
+
226
+ # The default HTTP method used to sign out a resource. Default is :delete.
227
+ config.sign_out_via = :delete
228
+
229
+ # ==> OmniAuth
230
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
231
+ # up on your models and hooks.
232
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
233
+
234
+ # ==> Warden configuration
235
+ # If you want to use other strategies, that are not supported by Devise, or
236
+ # change the failure app, you can configure them inside the config.warden block.
237
+ #
238
+ # config.warden do |manager|
239
+ # manager.intercept_401 = false
240
+ # manager.default_strategies(scope: :user).unshift :some_external_strategy
241
+ # end
242
+
243
+ # ==> Mountable engine configurations
244
+ # When using Devise inside an engine, let's call it `MyEngine`, and this engine
245
+ # is mountable, there are some extra configurations to be taken into account.
246
+ # The following options are available, assuming the engine is mounted as:
247
+ #
248
+ # mount MyEngine, at: '/my_engine'
249
+ #
250
+ # The router that invoked `devise_for`, in the example above, would be:
251
+ # config.router_name = :microservice
252
+
253
+ #
254
+ # When using OmniAuth, Devise cannot automatically set OmniAuth path,
255
+ # so you need to do it manually. For the users scope, it would be:
256
+ # config.omniauth_path_prefix = '/my_engine/users/auth'
257
+
258
+ Microservice::Settings.omniauth_providers.each do |provider, options|
259
+ omniauth_opts = {redirect_uri: options[:app_redirect_uri]}
260
+ omniauth_opts[:setup] = ->(env) {
261
+ request = Rack::Request.new(env)
262
+ site_url = request.params['auth_url'] || request.session['auth_url']
263
+ site_url ||= request.session['omniauth.params']['auth_url'] if request.session['omniauth.params']
264
+ env['omniauth.strategy'].options[:client_options].site = site_url if site_url
265
+ } if options[:dynamic_url]
266
+
267
+ config.omniauth provider, options[:app_id], options[:app_secret], omniauth_opts
268
+ end
269
+
270
+ end
@@ -0,0 +1,5 @@
1
+ # ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
2
+ # html_tag.html_safe
3
+ # end
4
+ #
5
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE if Rails.env.development?
@@ -0,0 +1,78 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ # central sso server
4
+ module OmniAuth
5
+ module Strategies
6
+ class Sso < OmniAuth::Strategies::OAuth2
7
+
8
+ option :name, :sso
9
+
10
+ option :client_options, {
11
+ site: 'https://sso.easysoftware.com',
12
+ authorize_url: 'https://sso.easysoftware.com/auth/sso/authorize',
13
+ token_url: 'https://sso.easysoftware.com/auth/sso/token'
14
+ }
15
+
16
+ uid do
17
+ raw_info['id']
18
+ end
19
+
20
+ info do
21
+ {
22
+ email: raw_info['info']['email'],
23
+ first_name: raw_info['info']['first_name'],
24
+ last_name: raw_info['info']['last_name'],
25
+ image: raw_info['info']['image'],
26
+ name: raw_info['info']['name'],
27
+ username: raw_info['info']['username'],
28
+ status: raw_info['info']['status']
29
+ }
30
+ end
31
+
32
+ def raw_info
33
+ @raw_info ||= access_token.get("/auth/sso/user.json?oauth_token=#{access_token.token}").parsed
34
+ end
35
+
36
+ def authorize_params
37
+ super.merge(auth_provider: request.params['auth_provider'], auth_url: request.params['auth_url'])
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+
44
+ # trial / client
45
+ module OmniAuth
46
+ module Strategies
47
+ class EasySoftware < OmniAuth::Strategies::OAuth2
48
+
49
+ option :name, :easy_software
50
+
51
+ option :client_options, {
52
+ authorize_url: '/easy_oauth/authorize',
53
+ token_url: '/easy_oauth/token'
54
+ }
55
+
56
+ uid do
57
+ raw_info['id']
58
+ end
59
+
60
+ info do
61
+ {
62
+ email: raw_info['info']['email'],
63
+ first_name: raw_info['info']['first_name'],
64
+ last_name: raw_info['info']['last_name'],
65
+ image: raw_info['info']['image'],
66
+ name: raw_info['info']['name'],
67
+ username: raw_info['info']['username'],
68
+ status: raw_info['info']['status']
69
+ }
70
+ end
71
+
72
+ def raw_info
73
+ @raw_info ||= access_token.get("/easy_oauth/user.json?key=#{access_token.token}").parsed
74
+ end
75
+
76
+ end
77
+ end
78
+ end