isaca-rails 0.2.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 (60) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +28 -0
  3. data/Rakefile +102 -0
  4. data/app/assets/images/isaca/rails/geometric-1920-blue.png +0 -0
  5. data/app/assets/images/isaca/rails/isaca-logo.png +0 -0
  6. data/app/assets/javascript/isaca/rails/application.js +13 -0
  7. data/app/assets/stylesheets/isaca/rails/all.css +46 -0
  8. data/app/assets/stylesheets/isaca/rails/application.css +15 -0
  9. data/app/assets/stylesheets/isaca/rails/components/button.css +34 -0
  10. data/app/assets/stylesheets/isaca/rails/components/container.css +4 -0
  11. data/app/assets/stylesheets/isaca/rails/components/flash.css +18 -0
  12. data/app/assets/stylesheets/isaca/rails/components/form-control.css +7 -0
  13. data/app/assets/stylesheets/isaca/rails/sessions.css +96 -0
  14. data/app/assets/stylesheets/isaca/rails/user_consent.css +87 -0
  15. data/app/controllers/isaca/rails/application_controller.rb +5 -0
  16. data/app/controllers/isaca/rails/platform/administrators_controller.rb +68 -0
  17. data/app/controllers/isaca/rails/platform/application_controller.rb +10 -0
  18. data/app/controllers/isaca/rails/platform/claims_controller.rb +34 -0
  19. data/app/controllers/isaca/rails/sessions_controller.rb +56 -0
  20. data/app/controllers/isaca/rails/users_consent_controller.rb +24 -0
  21. data/app/controllers/isaca/rails/welcome_controller.rb +3 -0
  22. data/app/helpers/isaca/rails/application_helper.rb +48 -0
  23. data/app/helpers/isaca/rails/claims_helper.rb +13 -0
  24. data/app/models/session/sign_in/form_object.rb +28 -0
  25. data/app/models/user_consent/agreement/form_object.rb +33 -0
  26. data/app/views/isaca/rails/platform/administrators/_administrator.html.erb +6 -0
  27. data/app/views/isaca/rails/platform/administrators/_claims_form.html.erb +9 -0
  28. data/app/views/isaca/rails/platform/administrators/edit.html.erb +9 -0
  29. data/app/views/isaca/rails/platform/administrators/index.html.erb +15 -0
  30. data/app/views/isaca/rails/platform/administrators/new.html.erb +17 -0
  31. data/app/views/isaca/rails/platform/administrators/show.html.erb +29 -0
  32. data/app/views/isaca/rails/sessions/_form.html.erb +15 -0
  33. data/app/views/isaca/rails/sessions/new.html.erb +28 -0
  34. data/app/views/isaca/rails/sessions/shared/_links.html.erb +2 -0
  35. data/app/views/isaca/rails/users_consent/_form.html.erb +50 -0
  36. data/app/views/isaca/rails/users_consent/show.html.erb +21 -0
  37. data/app/views/isaca/rails/welcome/index.html.erb +81 -0
  38. data/app/views/layouts/isaca-rails.html.erb +23 -0
  39. data/config/application.rb +0 -0
  40. data/config/locales/isaca-rails.en.yml +25 -0
  41. data/config/routes.rb +2 -0
  42. data/lib/generators/isaca/rails/install/USAGE +24 -0
  43. data/lib/generators/isaca/rails/install/install_generator.rb +148 -0
  44. data/lib/generators/isaca/rails/install/templates/README +14 -0
  45. data/lib/generators/isaca/rails/install/templates/add_isaca_claims.rb.erb +10 -0
  46. data/lib/generators/isaca/rails/install/templates/add_isaca_to_existing_users.rb.erb +17 -0
  47. data/lib/generators/isaca/rails/install/templates/add_isaca_users.rb.erb +21 -0
  48. data/lib/generators/isaca/rails/install/templates/claim.rb.erb +13 -0
  49. data/lib/generators/isaca/rails/install/templates/isaca-rails.rb +4 -0
  50. data/lib/generators/isaca/rails/install/templates/isaca.rb +5 -0
  51. data/lib/generators/isaca/rails/install/templates/user.rb.erb +3 -0
  52. data/lib/isaca/rails/authentication.rb +166 -0
  53. data/lib/isaca/rails/authorization.rb +51 -0
  54. data/lib/isaca/rails/controller.rb +14 -0
  55. data/lib/isaca/rails/engine.rb +7 -0
  56. data/lib/isaca/rails/user.rb +16 -0
  57. data/lib/isaca/rails/version.rb +5 -0
  58. data/lib/isaca/rails.rb +83 -0
  59. data/lib/tasks/isaca/rails_tasks.rake +4 -0
  60. metadata +297 -0
@@ -0,0 +1,48 @@
1
+ module Isaca::Rails::ApplicationHelper
2
+ # Injects the isaca privacy policy and cookie consent notices
3
+ def isaca_consent_javascript
4
+ javascript_include_tag 'https://www.isaca.org/info/shared/js/isaca-consent.min.js'
5
+ end
6
+
7
+ # Presents beautiful flash notices if flash notices exist
8
+ def isaca_flash_messages
9
+ content_tag :div do
10
+ flash.collect do |name, message|
11
+ concat(content_tag :div, message, class: "ir-flash ir-flash-#{name.underscore}")
12
+ end
13
+ end
14
+ end
15
+
16
+ # Presents beautiful error messages for form objects
17
+ def isaca_form_errors(model)
18
+ if model.errors.size > 1
19
+ message = 'The following errors occurred:'
20
+ else
21
+ message = 'The following error occurred:'
22
+ end
23
+
24
+ concat(content_tag(:p, message))
25
+
26
+ content_tag :div, class: 'ir-flash ir-flash-alert' do
27
+ error_list = content_tag (:ul) do
28
+ model.errors.full_messages.collect do |message|
29
+ concat(content_tag :li, message)
30
+ end
31
+ end
32
+
33
+ concat(error_list)
34
+ end
35
+ end
36
+
37
+ # Provides a link to reset user credentials
38
+ def link_to_forgot_isaca_credentials
39
+ link_to 'Forgot password and/or username?',
40
+ 'https://www.isaca.org/ecommerce/Pages/Forgot-Password.aspx', target: :blank
41
+ end
42
+
43
+ # Provides a link to create an ISACA account
44
+ def link_to_create_isaca_account
45
+ link_to 'Create ISACA account',
46
+ 'https://www.isaca.org/ecommerce/Pages/CreateAccountLite.aspx?pf=1', target: :blank
47
+ end
48
+ end
@@ -0,0 +1,13 @@
1
+ module Isaca
2
+ module Rails
3
+ module ClaimsHelper
4
+ def claim_checkbox(form, administrator, privilege)
5
+ content_tag(:div, class: 'form-group') do
6
+ concat form.check_box(privilege, {checked: user_has_privilege?(administrator, privilege),
7
+ id: "claims_#{privilege}_#{administrator.id}"})
8
+ concat form.label(privilege, privilege, value: administrator.id)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ module Session
2
+ module SignIn
3
+ # Class used as to easily integrate a session form with some basic validation
4
+ class FormObject
5
+ include ActiveModel::Model
6
+
7
+ attr_accessor :username, :password
8
+ validates_presence_of :username, :password
9
+
10
+ # This method will attempt to generate a session with the ISACA SSO service
11
+ #
12
+ # @raise [ISACA::ConnectionError] Occurs when a connection could not be established. This could be due to IP whitelisting or an invalid endpoint URL
13
+ #
14
+ # @return [Isaca::Model::AuthenticateUser]
15
+ def sign_in
16
+ Isaca::Request::AuthenticateUser.get(username, password) if valid?
17
+ end
18
+
19
+ # Defining this method allows us to use some ActiveModel patterns. For example, forms will be identified
20
+ # as sign_in instead of session_sign_in_form_object.
21
+ #
22
+ # @return [ActiveModel::Name]
23
+ def self.model_name
24
+ ActiveModel::Name.new(self, nil, 'SignIn')
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ module UserConsent
2
+ module Agreement
3
+ # Form object used for handling user consent
4
+ class FormObject
5
+ include ActiveModel::Model
6
+
7
+ attr_accessor :privacy_policy, :marketing_policy
8
+ validates_acceptance_of :privacy_policy, allow_nil: false
9
+ validates_presence_of :marketing_policy
10
+
11
+
12
+ # Method used to report user consent of the privacy policy and marketing
13
+ #
14
+ # @param options [Hash] Optional. If not provided, marketing consent will default to NO [0].
15
+ #
16
+ # == Options
17
+ # [marketing] Consent for marketing. Acceptable values are 0 [for NO] and 1 [for YES].
18
+ #
19
+ # @return [Boolean] Whether or not the consent was successfully reported to ISACA
20
+ def report_consent(imis_id, options={})
21
+ Isaca::Request::ReportConsent.get(imis_id, options).success? if valid?
22
+ end
23
+
24
+ # Defining this method allows us to use some ActiveModel patterns. For example, forms will be identified
25
+ # as sign_in instead of session_sign_in_form_object.
26
+ #
27
+ # @return [ActiveModel::Name]
28
+ def self.model_name
29
+ ActiveModel::Name.new(self, nil, 'Agreement')
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ <li>
2
+ <%= administrator.first_name %> <%= administrator.last_name %>
3
+ <%= link_to 'Show', administrator_path(administrator) %> |
4
+ <%= link_to 'Edit Claims', edit_administrator_path(administrator) %> |
5
+ <%= link_to 'Remove Administrator Privileges', administrator_path(administrator), method: :delete, data: {confirm: t('isaca.rails.administrators.delete_confirmation')} %>
6
+ </li>
@@ -0,0 +1,9 @@
1
+ <%= form_for :claims, url: administrator_claims_path(@administrator) do |f| %>
2
+ <% ::Claim.privileges.keys.collect(&:to_sym).each do |privilege| %>
3
+ <%= claim_checkbox(f, @administrator, privilege) %>
4
+ <% end %>
5
+
6
+ <div class="form-group">
7
+ <%= f.submit %>
8
+ </div>
9
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <div class="ir-container">
2
+ <%= image_tag 'isaca/rails/isaca-logo.png', height: 50 %>
3
+ <h1><%= @administrator.first_name %> <%= @administrator.last_name %></h1>
4
+
5
+ <div class="ir-container">
6
+ <h2>Edit Administrator Claims</h2>
7
+ <%= render 'isaca/rails/platform/administrators/claims_form' %>
8
+ </div>
9
+ </div>
@@ -0,0 +1,15 @@
1
+ <div class="ir-container">
2
+ <%= image_tag 'isaca/rails/isaca-logo.png', height: 50 %>
3
+ <h1><%= Rails.application.class.parent_name %> Administrators</h1>
4
+
5
+ <div class="ir-container">
6
+ <%= link_to 'Add an Administrator', new_administrator_path %>
7
+ <% if @administrators.any? %>
8
+ <ul>
9
+ <%= render partial: 'isaca/rails/platform/administrators/administrator', collection: @administrators %>
10
+ </ul>
11
+ <% else %>
12
+ <p>No administrators exist for this application.</p>
13
+ <% end %>
14
+ </div>
15
+ </div>
@@ -0,0 +1,17 @@
1
+ <div class="ir-container">
2
+ <%= image_tag 'isaca/rails/isaca-logo.png', height: 50 %>
3
+ <h1><%= Rails.application.class.parent_name %> Administrators</h1>
4
+
5
+ <div class="ir-container">
6
+ <h2>Create Administrator</h2>
7
+
8
+ <%= form_for :administrator, url: administrators_path do |f| %>
9
+ <div class="form-group">
10
+ <%= f.label :email %>
11
+ <%= f.text_field :email, autofocus: true %>
12
+ </div>
13
+
14
+ <%= f.submit 'Create Administrator' %>
15
+ <% end %>
16
+ </div>
17
+ </div>
@@ -0,0 +1,29 @@
1
+ <div class="ir-container">
2
+ <h1><%= @administrator.first_name %> <%= @administrator.last_name %></h1>
3
+ <p>
4
+ <strong>Actions: </strong>
5
+ <%= link_to 'List All Administrators', administrators_path %> |
6
+ <% if user_has_privilege?(current_isaca_user, :write_claims) %>
7
+ <%= link_to 'Edit Claims', edit_administrator_path(@administrator) %> |
8
+ <% end %>
9
+ <%= link_to 'Remove Administrator Privileges', administrator_path(@administrator), method: :delete, data: {confirm: t('isaca.rails.administrators.delete_confirmation')} %>
10
+ </p>
11
+ <p><strong>IMIS ID:</strong> <%= @administrator.imis_id %></p>
12
+
13
+ <p>
14
+ <strong>Claims:</strong>
15
+ <% if user_has_privilege?(current_isaca_user, :read_claims) %>
16
+ <% if @administrator.claims.any? %>
17
+ <ul>
18
+ <% @administrator.claims.each do |claim| %>
19
+ <li><%= claim.privilege %></li>
20
+ <% end %>
21
+ </ul>
22
+ <% else %>
23
+ No claims exist for this administrator.
24
+ <% end %>
25
+ <% else %>
26
+ You do not have the necessary privileges to view an administrator's claims.
27
+ <% end %>
28
+ </p>
29
+ </div>
@@ -0,0 +1,15 @@
1
+ <%= form_for @form_object, url: session_path do |f| %>
2
+ <%= isaca_form_errors(@form_object) if @form_object.errors.any? %>
3
+
4
+ <div class="form-group">
5
+ <%= f.label :username %>
6
+ <%= f.text_field :username, autofocus: true, class: 'ir-form-control' %>
7
+ </div>
8
+
9
+ <div class="form-group">
10
+ <%= f.label :password %>
11
+ <%= f.password_field :password, class: 'ir-form-control' %>
12
+ </div>
13
+
14
+ <%= f.submit 'Sign In', class: 'ir-btn ir-btn-lg ir-btn-primary ir-form-control' %>
15
+ <% end %>
@@ -0,0 +1,28 @@
1
+ <% content_for :title, 'Sign In' %>
2
+
3
+ <div class="ir-login-container">
4
+ <main>
5
+ <div class="ir-brand">
6
+ <a href="/">
7
+ <%= image_tag 'isaca/rails/isaca-logo.png' %>
8
+ </a>
9
+ </div>
10
+
11
+ <div class="ir-form-body">
12
+ <%= isaca_flash_messages %>
13
+
14
+ <% if user_signed_in? %>
15
+ <p>You are signed in as <%= current_isaca_user.first_name %> <%= current_isaca_user.last_name %>.</p>
16
+
17
+ <%= link_to t('isaca.rails.sessions.sign_out'), sign_out_path, method: :delete, data: {confirm: t('isaca.rails.sessions.sign_out_confirmation')} %>
18
+ <% else %>
19
+ <%= render 'isaca/rails/sessions/form' %>
20
+
21
+ <ul class="ir-shared-links">
22
+ <%= render 'isaca/rails/sessions/shared/links' %>
23
+ </ul>
24
+ <% end %>
25
+ </div>
26
+ </main>
27
+ <aside></aside>
28
+ </div>
@@ -0,0 +1,2 @@
1
+ <li><%= link_to_forgot_isaca_credentials %></li>
2
+ <li><%= link_to_create_isaca_account %></li>
@@ -0,0 +1,50 @@
1
+ <%= form_for @form_object, url: user_consent_path do |f| %>
2
+ <%= isaca_form_errors(@form_object) if @form_object.errors.any? %>
3
+
4
+ <div class="form-group" style="margin-bottom: 20px;">
5
+ <label for="agreements_privacy">
6
+ <%= f.check_box :privacy_policy %>
7
+
8
+ ISACA has changed their privacy notice, to access the revised notice and terms,
9
+ <a href="https://www.isaca.org/pages/Privacy.aspx" target="_blank">click here</a>.
10
+
11
+ By continuing to use the site you agree to the revised terms.
12
+ </label>
13
+ </div>
14
+
15
+ <div class="form-group">
16
+ <label for="agreements_marketing">
17
+ <% if Isaca::Request::ExplicitCountries.get.includes_country?(current_isaca_user.country) %>
18
+ <%= f.check_box :marketing_policy %>
19
+ <% else %>
20
+ <%= f.check_box :marketing_policy, checked: true %>
21
+ <% end %>
22
+
23
+ Yes! I would like to receive by post, e-mail and/or telephone marketing information from ISACA
24
+ and their affiliates about ISACA and their affiliates and their products and services, and other
25
+ information in which ISACA and their affiliates think I may be interested.
26
+ </label>
27
+ </div>
28
+
29
+ <p>
30
+ By pressing submit, I understand and agree that the information I have provided will be used as described
31
+ in the ISACA Privacy Policy. By pressing submit, I further agree to the website Terms, and confirm that
32
+ the information I have provided is my own.
33
+ </p>
34
+
35
+ <%= f.submit 'Save Preferences', class: 'ir-btn ir-btn-primary ir-btn-lg ir-form-control', disabled: true %>
36
+ <% end %>
37
+
38
+ <script type="text/javascript" charset="utf-8">
39
+ const form = document.getElementById('new_agreement');
40
+ const submit = form.getElementsByTagName('input')[6];
41
+
42
+ if (submit) {
43
+ submit.disabled = true;
44
+ }
45
+
46
+ const privacyCheckBox = document.getElementById('agreement_privacy_policy');
47
+ privacyCheckBox.addEventListener('change', (event) => {
48
+ submit.disabled = !event.target.checked;
49
+ });
50
+ </script>
@@ -0,0 +1,21 @@
1
+ <% content_for :title, 'Consent' %>
2
+
3
+ <div class="ir-consent-container">
4
+ <aside></aside>
5
+ <main>
6
+ <div class="ir-brand">
7
+ <a href="/">
8
+ <%= image_tag 'isaca/rails/isaca-logo.png' %>
9
+ </a>
10
+ </div>
11
+
12
+ <div class="ir-form-body">
13
+ <%= isaca_flash_messages %>
14
+
15
+ <h3>Hi <%= current_isaca_user.first_name %>, </h3>
16
+
17
+ <p>WE HAVE UPDATED OUR PRIVACY AND COMMUNICATION PREFERENCES</p>
18
+ <%= render 'isaca/rails/users_consent/form' %>
19
+ </div>
20
+ </main>
21
+ </div>