ucb_rails_user 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +166 -0
  4. data/Rakefile +36 -0
  5. data/app/assets/config/ucb_rails_user_manifest.js +0 -0
  6. data/app/assets/javascripts/ucb_rails_user/datatables.js +15441 -0
  7. data/app/assets/javascripts/ucb_rails_user/scripts.js +15 -0
  8. data/app/assets/javascripts/ucb_rails_user/ucb_rails_user.js +39 -0
  9. data/app/assets/stylesheets/ucb_rails_user/components/_add_users_search_results_table.sass +2 -0
  10. data/app/assets/stylesheets/ucb_rails_user/components/_loader.sass +46 -0
  11. data/app/assets/stylesheets/ucb_rails_user/components/_users_table.sass +10 -0
  12. data/app/assets/stylesheets/ucb_rails_user/datatables.css +201 -0
  13. data/app/assets/stylesheets/ucb_rails_user/main.sass +2 -0
  14. data/app/assets/stylesheets/ucb_rails_user/styles.css +19 -0
  15. data/app/controllers/ucb_rails_user/concerns/controller_methods.rb +92 -0
  16. data/app/controllers/ucb_rails_user/concerns/home_controller.rb +17 -0
  17. data/app/controllers/ucb_rails_user/concerns/sessions_controller.rb +68 -0
  18. data/app/controllers/ucb_rails_user/concerns/users_controller.rb +132 -0
  19. data/app/controllers/ucb_rails_user/home_controller.rb +10 -0
  20. data/app/controllers/ucb_rails_user/sessions_controller.rb +9 -0
  21. data/app/controllers/ucb_rails_user/users_controller.rb +8 -0
  22. data/app/helpers/ucb_rails_user/users_helper.rb +18 -0
  23. data/app/helpers/ucb_rails_user_helper.rb +17 -0
  24. data/app/models/concerns/user_concerns.rb +53 -0
  25. data/app/models/ucb_rails_user/configuration/cas.rb +53 -0
  26. data/app/models/ucb_rails_user/configuration/configuration.rb +72 -0
  27. data/app/models/ucb_rails_user/configuration/email.rb +73 -0
  28. data/app/models/ucb_rails_user/configuration/exception_notification.rb +21 -0
  29. data/app/models/ucb_rails_user/configuration/ldap.rb +50 -0
  30. data/app/models/ucb_rails_user/ldap_person/entry.rb +62 -0
  31. data/app/models/ucb_rails_user/ldap_person/finder.rb +87 -0
  32. data/app/models/ucb_rails_user/ldap_person/test_finder.rb +57 -0
  33. data/app/models/ucb_rails_user/user_ldap_service.rb +65 -0
  34. data/app/models/ucb_rails_user/user_session_manager/active_in_user_table.rb +29 -0
  35. data/app/models/ucb_rails_user/user_session_manager/admin_in_user_table.rb +13 -0
  36. data/app/models/ucb_rails_user/user_session_manager/base.rb +54 -0
  37. data/app/models/ucb_rails_user/user_session_manager/in_people_ou.rb +27 -0
  38. data/app/models/ucb_rails_user/user_session_manager/in_people_ou_add_to_users_table.rb +21 -0
  39. data/app/models/ucb_rails_user/user_session_manager/ldap_person_user_wrapper.rb +29 -0
  40. data/app/models/user.rb +8 -0
  41. data/app/views/ucb_rails_user/home/logged_in.html.haml +5 -0
  42. data/app/views/ucb_rails_user/home/not_logged_in.html.haml +5 -0
  43. data/app/views/ucb_rails_user/lps/_form.html.haml +19 -0
  44. data/app/views/ucb_rails_user/lps/_modal.html.haml +9 -0
  45. data/app/views/ucb_rails_user/lps/_results.html.haml +34 -0
  46. data/app/views/ucb_rails_user/lps/search.js.haml +3 -0
  47. data/app/views/ucb_rails_user/users/_form.html.haml +14 -0
  48. data/app/views/ucb_rails_user/users/_search_results.html.haml +24 -0
  49. data/app/views/ucb_rails_user/users/_user.html.haml +12 -0
  50. data/app/views/ucb_rails_user/users/edit.html.haml +3 -0
  51. data/app/views/ucb_rails_user/users/index.html.haml +23 -0
  52. data/app/views/ucb_rails_user/users/new.html.haml +16 -0
  53. data/app/views/ucb_rails_user/users/search.js.haml +4 -0
  54. data/config/initializers/simple_form.rb +171 -0
  55. data/config/initializers/simple_form_bootstrap.rb +154 -0
  56. data/config/locales/simple_form.en.yml +31 -0
  57. data/config/routes.rb +20 -0
  58. data/db/migrate/20170324221936_create_users.rb +29 -0
  59. data/lib/tasks/ucb_rails_user_tasks.rake +4 -0
  60. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  61. data/lib/ucb_rails_user.rb +21 -0
  62. data/lib/ucb_rails_user/engine.rb +28 -0
  63. data/lib/ucb_rails_user/version.rb +3 -0
  64. metadata +277 -0
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
5
+ // vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require_tree .
15
+
@@ -0,0 +1,39 @@
1
+ // the users table has width set to auto, but the pagination tries to stretch to full width - this
2
+ // forces the pagination to match the table
3
+ var resizePagination = function () {
4
+ var paginationDiv = $('.dataTables_info').parents('.row').first()
5
+ paginationDiv.width($('.dataTable').width())
6
+ }
7
+
8
+ var addDatatablesToSearchResults = function () {
9
+ $('.add-user-search-results-table').dataTable({
10
+ searching: false,
11
+ order: [[ 2, "asc" ]],
12
+ columnDefs: [ {
13
+ targets: 3,
14
+ orderable: false
15
+ }]
16
+ })
17
+ resizePagination()
18
+ }
19
+
20
+ var addDatatablesToUsersTable = function () {
21
+ $('.ucb-rails-users-table').dataTable({
22
+ searching: true,
23
+ order: [[ 3, "asc" ]],
24
+ columnDefs: [ {
25
+ targets: [8, 9],
26
+ orderable: false
27
+ }]
28
+ })
29
+ }
30
+
31
+ $( window ).on("load", function() {
32
+ // the datatable calling was failing intermittently, but adding the timeout
33
+ // seemed to fix it, so ¯\_(ツ)_/¯
34
+ window.setTimeout(addDatatablesToUsersTable, 100)
35
+
36
+ $('.user-search-form').on('submit', function() {
37
+ $('.ucb-rails-user-loader').show()
38
+ })
39
+ })
@@ -0,0 +1,2 @@
1
+ .add-user-search-results-table
2
+ width: 50%
@@ -0,0 +1,46 @@
1
+ .ucb-rails-user-loader,
2
+ .ucb-rails-user-loader:after
3
+ border-radius: 50%
4
+ width: 6em
5
+ height: 6em
6
+
7
+ .ucb-rails-user-loader
8
+ display: none
9
+ margin: 60px auto
10
+ font-size: 10px
11
+ position: relative
12
+ text-indent: -9999em
13
+ border-top: .8em solid rgba(0,50,97, 0.2)
14
+ border-right: .8em solid rgba(0,50,97, 0.2)
15
+ border-bottom: .8em solid rgba(0,50,97, 0.2)
16
+ border-left: .8em solid #003261
17
+ -webkit-transform: translateZ(0)
18
+ -ms-transform: translateZ(0)
19
+ transform: translateZ(0)
20
+ -webkit-animation: load8 1.1s infinite linear
21
+ animation: load8 1.1s infinite linear
22
+
23
+ @-webkit-keyframes load8
24
+ 0%
25
+ -webkit-transform: rotate(0deg)
26
+ transform: rotate(0deg)
27
+
28
+ 100%
29
+ -webkit-transform: rotate(360deg)
30
+ transform: rotate(360deg)
31
+
32
+
33
+ @keyframes load8
34
+ 0%
35
+ -webkit-transform: rotate(0deg)
36
+ transform: rotate(0deg)
37
+
38
+ 100%
39
+ -webkit-transform: rotate(360deg)
40
+ transform: rotate(360deg)
41
+
42
+ .ucb-rails-user-loader-small
43
+ margin: 16px
44
+ font-size: 6px
45
+
46
+
@@ -0,0 +1,10 @@
1
+ .ucb-rails-users-table-header
2
+ margin-top: 16px
3
+ margin-bottom: 16px
4
+
5
+ a
6
+ margin-top: 16px
7
+
8
+ table.ucb-rails-users-table
9
+ margin-top: 16px
10
+
@@ -0,0 +1,201 @@
1
+ /*
2
+ * This combined file was created by the DataTables downloader builder:
3
+ * https://datatables.net/download
4
+ *
5
+ * To rebuild or modify this file with the latest versions of the included
6
+ * software please visit:
7
+ * https://datatables.net/download/#bs/dt-1.10.16
8
+ *
9
+ * Included libraries:
10
+ * DataTables 1.10.16
11
+ */
12
+
13
+ table.dataTable {
14
+ clear: both;
15
+ margin-top: 6px !important;
16
+ margin-bottom: 6px !important;
17
+ max-width: none !important;
18
+ border-collapse: separate !important;
19
+ }
20
+ table.dataTable td,
21
+ table.dataTable th {
22
+ -webkit-box-sizing: content-box;
23
+ box-sizing: content-box;
24
+ }
25
+ table.dataTable td.dataTables_empty,
26
+ table.dataTable th.dataTables_empty {
27
+ text-align: center;
28
+ }
29
+ table.dataTable.nowrap th,
30
+ table.dataTable.nowrap td {
31
+ white-space: nowrap;
32
+ }
33
+
34
+ div.dataTables_wrapper div.dataTables_length label {
35
+ font-weight: normal;
36
+ text-align: left;
37
+ white-space: nowrap;
38
+ }
39
+ div.dataTables_wrapper div.dataTables_length select {
40
+ width: 75px;
41
+ display: inline-block;
42
+ }
43
+ div.dataTables_wrapper div.dataTables_filter {
44
+ text-align: right;
45
+ }
46
+ div.dataTables_wrapper div.dataTables_filter label {
47
+ font-weight: normal;
48
+ white-space: nowrap;
49
+ text-align: left;
50
+ }
51
+ div.dataTables_wrapper div.dataTables_filter input {
52
+ margin-left: 0.5em;
53
+ display: inline-block;
54
+ width: auto;
55
+ }
56
+ div.dataTables_wrapper div.dataTables_info {
57
+ padding-top: 8px;
58
+ white-space: nowrap;
59
+ }
60
+ div.dataTables_wrapper div.dataTables_paginate {
61
+ margin: 0;
62
+ white-space: nowrap;
63
+ text-align: right;
64
+ }
65
+ div.dataTables_wrapper div.dataTables_paginate ul.pagination {
66
+ margin: 2px 0;
67
+ white-space: nowrap;
68
+ }
69
+ div.dataTables_wrapper div.dataTables_processing {
70
+ position: absolute;
71
+ top: 50%;
72
+ left: 50%;
73
+ width: 200px;
74
+ margin-left: -100px;
75
+ margin-top: -26px;
76
+ text-align: center;
77
+ padding: 1em 0;
78
+ }
79
+
80
+ table.dataTable thead > tr > th.sorting_asc, table.dataTable thead > tr > th.sorting_desc, table.dataTable thead > tr > th.sorting,
81
+ table.dataTable thead > tr > td.sorting_asc,
82
+ table.dataTable thead > tr > td.sorting_desc,
83
+ table.dataTable thead > tr > td.sorting {
84
+ padding-right: 30px;
85
+ }
86
+ table.dataTable thead > tr > th:active,
87
+ table.dataTable thead > tr > td:active {
88
+ outline: none;
89
+ }
90
+ table.dataTable thead .sorting,
91
+ table.dataTable thead .sorting_asc,
92
+ table.dataTable thead .sorting_desc,
93
+ table.dataTable thead .sorting_asc_disabled,
94
+ table.dataTable thead .sorting_desc_disabled {
95
+ cursor: pointer;
96
+ position: relative;
97
+ }
98
+ table.dataTable thead .sorting:after,
99
+ table.dataTable thead .sorting_asc:after,
100
+ table.dataTable thead .sorting_desc:after,
101
+ table.dataTable thead .sorting_asc_disabled:after,
102
+ table.dataTable thead .sorting_desc_disabled:after {
103
+ position: absolute;
104
+ bottom: 8px;
105
+ right: 8px;
106
+ display: block;
107
+ font-family: 'Glyphicons Halflings';
108
+ opacity: 0.5;
109
+ }
110
+ table.dataTable thead .sorting:after {
111
+ opacity: 0.2;
112
+ content: "\e150";
113
+ /* sort */
114
+ }
115
+ table.dataTable thead .sorting_asc:after {
116
+ content: "\e155";
117
+ /* sort-by-attributes */
118
+ }
119
+ table.dataTable thead .sorting_desc:after {
120
+ content: "\e156";
121
+ /* sort-by-attributes-alt */
122
+ }
123
+ table.dataTable thead .sorting_asc_disabled:after,
124
+ table.dataTable thead .sorting_desc_disabled:after {
125
+ color: #eee;
126
+ }
127
+
128
+ div.dataTables_scrollHead table.dataTable {
129
+ margin-bottom: 0 !important;
130
+ }
131
+
132
+ div.dataTables_scrollBody > table {
133
+ border-top: none;
134
+ margin-top: 0 !important;
135
+ margin-bottom: 0 !important;
136
+ }
137
+ div.dataTables_scrollBody > table > thead .sorting:after,
138
+ div.dataTables_scrollBody > table > thead .sorting_asc:after,
139
+ div.dataTables_scrollBody > table > thead .sorting_desc:after {
140
+ display: none;
141
+ }
142
+ div.dataTables_scrollBody > table > tbody > tr:first-child > th,
143
+ div.dataTables_scrollBody > table > tbody > tr:first-child > td {
144
+ border-top: none;
145
+ }
146
+
147
+ div.dataTables_scrollFoot > .dataTables_scrollFootInner {
148
+ box-sizing: content-box;
149
+ }
150
+ div.dataTables_scrollFoot > .dataTables_scrollFootInner > table {
151
+ margin-top: 0 !important;
152
+ border-top: none;
153
+ }
154
+
155
+ @media screen and (max-width: 767px) {
156
+ div.dataTables_wrapper div.dataTables_length,
157
+ div.dataTables_wrapper div.dataTables_filter,
158
+ div.dataTables_wrapper div.dataTables_info,
159
+ div.dataTables_wrapper div.dataTables_paginate {
160
+ text-align: center;
161
+ }
162
+ }
163
+ table.dataTable.table-condensed > thead > tr > th {
164
+ padding-right: 20px;
165
+ }
166
+ table.dataTable.table-condensed .sorting:after,
167
+ table.dataTable.table-condensed .sorting_asc:after,
168
+ table.dataTable.table-condensed .sorting_desc:after {
169
+ top: 6px;
170
+ right: 6px;
171
+ }
172
+
173
+ table.table-bordered.dataTable th,
174
+ table.table-bordered.dataTable td {
175
+ border-left-width: 0;
176
+ }
177
+ table.table-bordered.dataTable th:last-child, table.table-bordered.dataTable th:last-child,
178
+ table.table-bordered.dataTable td:last-child,
179
+ table.table-bordered.dataTable td:last-child {
180
+ border-right-width: 0;
181
+ }
182
+ table.table-bordered.dataTable tbody th,
183
+ table.table-bordered.dataTable tbody td {
184
+ border-bottom-width: 0;
185
+ }
186
+
187
+ div.dataTables_scrollHead table.table-bordered {
188
+ border-bottom-width: 0;
189
+ }
190
+
191
+ div.table-responsive > div.dataTables_wrapper > div.row {
192
+ margin: 0;
193
+ }
194
+ div.table-responsive > div.dataTables_wrapper > div.row > div[class^="col-"]:first-child {
195
+ padding-left: 0;
196
+ }
197
+ div.table-responsive > div.dataTables_wrapper > div.row > div[class^="col-"]:last-child {
198
+ padding-right: 0;
199
+ }
200
+
201
+
@@ -0,0 +1,2 @@
1
+ @import "datatables"
2
+ @import "components/**/*"
@@ -0,0 +1,19 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *
13
+ ************************
14
+ * UCB: don't import stylesheets here - use ucb_rails_user.sass to take full advantage of Sass imports
15
+ * http://www.mattboldt.com/organizing-css-and-sass-rails/
16
+ *
17
+ *= require ucb_rails_user/main
18
+ */
19
+
@@ -0,0 +1,92 @@
1
+ module UcbRailsUser::Concerns::ControllerMethods
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ rescue_from UcbRailsUser::LdapPerson::Finder::BlankSearchTermsError do
6
+ render :js => %(alert("Enter search terms"))
7
+ end
8
+
9
+ before_action :ensure_authenticated_user
10
+ before_action :log_request
11
+
12
+ after_action :remove_user_settings
13
+
14
+ helper_method :superuser?, :current_ldap_person, :current_user, :logged_in?
15
+ end
16
+
17
+ def superuser?
18
+ current_user.try(:superuser?)
19
+ end
20
+
21
+ def current_user
22
+ @current_user ||= begin
23
+ logger.debug 'recalc of current_user'
24
+ user_session_manager.current_user(session[:uid])
25
+ end
26
+ end
27
+
28
+ # Returns +true+ if there is a logged in user
29
+ #
30
+ # @return [true] if user logged in
31
+ # @return [false] if user not logged in
32
+ def logged_in?
33
+ current_user.present?
34
+ end
35
+
36
+ def log_request
37
+ UcbRailsUser::UserSessionManager::Base.current_user = current_user
38
+ user_session_manager.log_request(current_user)
39
+ end
40
+
41
+ def remove_user_settings
42
+ UcbRailsUser::UserSessionManager::Base.current_user = nil
43
+ end
44
+
45
+ # Returns an instance of UCB::LDAP::Person if there is a logged in user
46
+ #
47
+ # @return [UCB::LDAP::Person] if user logged in
48
+ # @return [nil] if user not logged in
49
+ def current_ldap_person
50
+ if logged_in?
51
+ @current_ldap_person ||= begin
52
+ logger.debug 'recalc of current_ldap_person'
53
+ user_session_manager.people_ou_entry(session[:uid])
54
+ end
55
+ end
56
+ end
57
+
58
+ def ensure_admin_user
59
+ superuser? or not_authorized!
60
+ end
61
+
62
+ # Before filter that redirects redirects to +login_url+ unless user is logged in
63
+ #
64
+ # @return [nil]
65
+ def ensure_authenticated_user
66
+ unless session.has_key?(:uid)
67
+ session[:original_url] = request.env['REQUEST_URI']
68
+ redirect_to login_url
69
+ end
70
+ end
71
+
72
+ def user_session_manager
73
+ @user_session_manager ||= begin
74
+ logger.debug "creating new user_session_manager"
75
+ klass = UcbRailsUser[:user_session_manager] || UcbRailsUser::UserSessionManager::ActiveInUserTable
76
+ klass.to_s.classify.constantize.new
77
+ end
78
+ rescue NameError
79
+ raise "Could not find UcbRailsUser user_session_manager: #{klass}"
80
+ end
81
+
82
+ def not_authorized!
83
+ render plain: "Not Authorized", status: 401
84
+ return false
85
+ end
86
+
87
+ def not_authorized_unless(condition)
88
+ unless condition
89
+ not_authorized!
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,17 @@
1
+ module UcbRailsUser::Concerns::HomeController
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ skip_before_action :ensure_authenticated_user
6
+ end
7
+
8
+ def index
9
+ if logged_in?
10
+ render "logged_in"
11
+ else
12
+ render "not_logged_in"
13
+ end
14
+ end
15
+
16
+ end
17
+