ucb_rails 0.0.13 → 0.0.14

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 (42) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +21 -11
  3. data/Rakefile +1 -1
  4. data/app/assets/images/seal.png +0 -0
  5. data/app/assets/stylesheets/ucb_rails.css.scss +7 -0
  6. data/app/assets/stylesheets/ucb_rails/berkeley-colors.sass +27 -0
  7. data/app/assets/stylesheets/ucb_rails/bootstrap-view-helpers.sass +4 -0
  8. data/app/assets/stylesheets/ucb_rails/branding.sass +66 -0
  9. data/app/assets/stylesheets/ucb_rails/buttons.sass +2 -0
  10. data/app/assets/stylesheets/ucb_rails/common.sass +30 -0
  11. data/app/assets/stylesheets/ucb_rails/nav.sass +51 -0
  12. data/app/assets/stylesheets/ucb_rails/typography.sass +43 -0
  13. data/app/assets/stylesheets/ucb_rails/variables.sass +26 -0
  14. data/app/controllers/ucb_rails/admin/users_controller.rb +2 -2
  15. data/app/controllers/ucb_rails/bootstrap_controller.rb +1 -1
  16. data/app/datatables/ucb_rails/base_datatable.rb +2 -0
  17. data/app/datatables/ucb_rails/users_datatable.rb +11 -10
  18. data/app/models/ucb_rails/configuration/email.rb +1 -1
  19. data/app/models/ucb_rails/ldap_person/entry.rb +20 -13
  20. data/app/models/ucb_rails/ldap_person/finder.rb +16 -4
  21. data/app/models/ucb_rails/ldap_person/test_finder.rb +16 -9
  22. data/app/models/ucb_rails/user.rb +21 -13
  23. data/app/models/ucb_rails/user_ldap_service.rb +11 -10
  24. data/app/models/ucb_rails/user_typeahead.rb +20 -2
  25. data/app/views/ucb_rails/admin/email_test/index.html.haml +1 -1
  26. data/app/views/ucb_rails/admin/users/_form.html.haml +1 -0
  27. data/app/views/ucb_rails/admin/users/_user.html.haml +4 -3
  28. data/app/views/ucb_rails/admin/users/index.html.haml +2 -1
  29. data/app/views/ucb_rails/home/logged_in.html.haml +5 -2
  30. data/config/routes.rb +7 -7
  31. data/lib/generators/ucb_rails/install_generator.rb +10 -1
  32. data/lib/generators/ucb_rails/templates/app/assets/javascripts/application.js +1 -0
  33. data/lib/generators/ucb_rails/templates/app/assets/javascripts/ucb_rails/users_datatable.js +1 -1
  34. data/lib/generators/ucb_rails/templates/app/assets/stylesheets/application.css +1 -0
  35. data/lib/generators/ucb_rails/templates/app/assets/stylesheets/bootstrap_and_overrides.css.scss +4 -3
  36. data/lib/generators/ucb_rails/templates/app/views/layouts/_footer.html.haml +1 -1
  37. data/lib/generators/ucb_rails/templates/app/views/layouts/_navigation.html.haml +22 -19
  38. data/lib/generators/ucb_rails/templates/app/views/layouts/application.html.haml +3 -3
  39. data/lib/ucb_rails.rb +2 -1
  40. data/lib/ucb_rails/version.rb +1 -1
  41. metadata +111 -229
  42. data/lib/generators/ucb_rails/templates/app/assets/stylesheets/ucb_rails.css.scss +0 -56
@@ -12,7 +12,8 @@ module UcbRails::LdapPerson
12
12
 
13
13
  def find_by_uid(uid)
14
14
  benchmark("find_by_uid(#{uid})") do
15
- find_by_attributes(:uid => uid.to_s).first
15
+ find_by_attributes(:uid => uid.to_s).first ||
16
+ find_expired_by_attributes(:uid => uid.to_s).first
16
17
  end
17
18
  end
18
19
 
@@ -22,7 +23,7 @@ module UcbRails::LdapPerson
22
23
 
23
24
  def find_by_first_last(first_name, last_name, options={})
24
25
  raise BlankSearchTermsError unless first_name.present? || last_name.present?
25
-
26
+
26
27
  find_by_attributes(:givenname => first_name, :sn => last_name).tap do |entries|
27
28
  if options[:sort]
28
29
  sort_symbol = options[:sort]
@@ -31,6 +32,10 @@ module UcbRails::LdapPerson
31
32
  end
32
33
  end
33
34
 
35
+ def find_by_affiliate_id(affiliate_id)
36
+ find_by_attributes("berkeleyEduAffID" => affiliate_id)
37
+ end
38
+
34
39
  def find_by_attributes(attributes)
35
40
  attributes.each { |k, v| attributes.delete(k) if v.blank? }
36
41
  UCB::LDAP::Person.
@@ -38,6 +43,13 @@ module UcbRails::LdapPerson
38
43
  map { |ldap_entry| Entry.new_from_ldap_entry(ldap_entry) }
39
44
  end
40
45
 
46
+ def find_expired_by_attributes(attributes)
47
+ attributes.each { |k, v| attributes.delete(k) if v.blank? }
48
+ UCB::LDAP::ExpiredPerson.
49
+ search(:filter => build_filter(attributes)).
50
+ map { |ldap_entry| Entry.new_from_ldap_entry(ldap_entry) }
51
+ end
52
+
41
53
  def build_filter(attrs)
42
54
  filter_parts = attrs.map { |k, v| build_filter_part(k, v) }
43
55
  filter = filter_parts.inject { |accum, filter| accum.send(:&, filter) }
@@ -62,6 +74,6 @@ module UcbRails::LdapPerson
62
74
  klass.new.send(method, *args)
63
75
  end
64
76
  end
65
-
77
+
66
78
  end
67
- end
79
+ end
@@ -14,6 +14,10 @@ module UcbRails::LdapPerson
14
14
  find_by_attributes(:first_name => first_name, :last_name => last_name)
15
15
  end
16
16
 
17
+ def find_by_affiliate_id(affiliate_id)
18
+ find_by_attributes("affiliate_id" => affiliate_id)
19
+ end
20
+
17
21
  def find_by_attributes(attributes)
18
22
  self.class.entries.select { |entry| entry_matches_attributes(entry, attributes) }
19
23
  end
@@ -21,20 +25,20 @@ module UcbRails::LdapPerson
21
25
  def entry_matches_attributes(entry, attributes)
22
26
  attributes.keys.all? do |key|
23
27
  value = attributes[key].to_s.downcase
24
- value.blank? || entry.send(key).downcase.include?(value)
28
+ value.blank? || (entry.respond_to?(key) && entry.send(key).to_s.downcase.include?(value))
25
29
  end
26
30
  end
27
31
 
28
32
  def self.entries
29
33
  [
30
- new_entry("1", 'art', "Art", "Andrews", "art@example.com", "999-999-0001", "Dept 1"),
31
- new_entry("2", 'beth', "Beth", "Brown", "beth@example.com", "999-999-0002", "Dept 2"),
32
- new_entry("61065", 'runner', "Steven", "Hansen", "runner@berkeley.edu", "999-999-9998", "EAS"),
33
- new_entry("191501", 'stevedowney', "Steve", "Downey", "sldowney@berkeley.edu", "999-999-9999", "EAS"),
34
+ new_entry("1", 'art', "Art", "Andrews", "art@example.com", "999-999-0001", "Dept 1", "011"),
35
+ new_entry("2", 'beth', "Beth", "Brown", "beth@example.com", "999-999-0002", "Dept 2", "012"),
36
+ new_entry("61065", 'runner', "Steven", "Hansen", "runner@berkeley.edu", "999-999-9998", "EAS", "0161065"),
37
+ new_entry("191501", 'stevedowney', "Steve", "Downey", "sldowney@berkeley.edu", "999-999-9999", "EAS", "01191501"),
34
38
  ]
35
39
  end
36
40
 
37
- def self.new_entry(uid, calnet_id, fn, ln, email, phone, depts)
41
+ def self.new_entry(uid, calnet_id, fn, ln, email, phone, depts, employee_id = nil, affiliate_id = nil)
38
42
  ::UcbRails::LdapPerson::Entry.new(
39
43
  :uid => uid,
40
44
  :calnet_id => calnet_id,
@@ -42,9 +46,12 @@ module UcbRails::LdapPerson
42
46
  :last_name => ln,
43
47
  :email => email,
44
48
  :phone => phone,
45
- :departments => depts
49
+ :departments => depts,
50
+ :employee_id => employee_id,
51
+ :affiliate_id => affiliate_id,
52
+ :inactive => false
46
53
  )
47
54
  end
48
-
55
+
49
56
  end
50
- end
57
+ end
@@ -1,45 +1,53 @@
1
1
  class UcbRails::User < ActiveRecord::Base
2
2
  self.table_name = 'users'
3
-
4
- attr_accessible :uid, :first_name, :last_name, :inactive
5
-
3
+
4
+ # attr_accessible :uid, :first_name, :last_name, :inactive
5
+
6
6
  before_validation :set_first_last_name
7
-
7
+
8
8
  # Overridden by application
9
9
  def roles
10
10
  []
11
11
  end
12
-
12
+
13
13
  def has_role?(role)
14
14
  admin? || roles.include?(role)
15
15
  end
16
-
16
+
17
17
  def active?
18
18
  !inactive?
19
19
  end
20
-
20
+
21
21
  def admin!(_admin=true)
22
22
  update_attribute(:admin, _admin)
23
23
  end
24
-
24
+
25
25
  def inactive!(_inactive=true)
26
26
  update_attribute(:inactive, _inactive)
27
27
  end
28
-
28
+
29
29
  def self.active
30
30
  where(inactive: false)
31
31
  end
32
-
32
+
33
33
  def self.admin
34
34
  where(admin: true)
35
35
  end
36
-
36
+
37
+ def ldap_entry
38
+ UcbRails::LdapPerson::Finder.find_by_uid!(uid)
39
+ end
40
+
41
+ def full_name
42
+ "#{first_name} #{last_name}"
43
+ end
44
+
37
45
  private
38
-
46
+
39
47
  def set_first_last_name
40
48
  self.first_last_name = [first_name, last_name]
41
49
  .select { |n| n.present? }
42
50
  .join(' ')
43
51
  .presence
44
52
  end
45
- end
53
+ end
@@ -1,36 +1,37 @@
1
1
  class UcbRails::UserLdapService
2
-
2
+
3
3
  class << self
4
-
4
+
5
5
  def create_user_from_uid(uid)
6
6
  UcbRails.logger.debug "create_user_from_uid #{uid}"
7
-
7
+
8
8
  ldap_entry = UcbRails::LdapPerson::Finder.find_by_uid!(uid)
9
9
  create_user_from_ldap_entry(ldap_entry)
10
10
  end
11
-
11
+
12
12
  def create_user_from_ldap_entry(ldap_entry)
13
13
  UcbRails.logger.debug "create_user_from_ldap_entry #{ldap_entry.uid}"
14
-
14
+
15
15
  UcbRails::User.create! do |u|
16
16
  u.uid = ldap_entry.uid
17
17
  u.first_name = ldap_entry.first_name
18
18
  u.last_name = ldap_entry.last_name
19
19
  u.email = ldap_entry.email
20
20
  u.phone = ldap_entry.phone
21
+ u.inactive = ldap_entry.inactive
21
22
  end
22
23
  end
23
24
 
24
25
  def update_user_from_uid(uid)
25
26
  UcbRails.logger.debug "update_user_from_uid #{uid}"
26
-
27
+
27
28
  ldap_entry = UcbRails::LdapPerson::Finder.find_by_uid!(uid)
28
29
  update_user_from_ldap_entry(ldap_entry)
29
30
  end
30
31
 
31
32
  def update_user_from_ldap_entry(ldap_entry)
32
33
  UcbRails.logger.debug "update_user_from_ldap_entry #{ldap_entry.uid}"
33
-
34
+
34
35
  UcbRails::User.find_by_uid!(ldap_entry.uid).tap do |user|
35
36
  user.first_name = ldap_entry.first_name
36
37
  user.last_name = ldap_entry.last_name
@@ -39,7 +40,7 @@ class UcbRails::UserLdapService
39
40
  user.save(validate: false)
40
41
  end
41
42
  end
42
-
43
+
43
44
  def create_or_update_user(uid)
44
45
  if user = UcbRails::User.find_by_uid(uid)
45
46
  update_user_from_uid(uid)
@@ -47,7 +48,7 @@ class UcbRails::UserLdapService
47
48
  create_user_from_uid(uid)
48
49
  end
49
50
  end
50
-
51
+
51
52
  def create_or_update_user_from_entry(entry)
52
53
  if user = UcbRails::User.find_by_uid(entry.uid)
53
54
  update_user_from_ldap_entry(entry)
@@ -56,4 +57,4 @@ class UcbRails::UserLdapService
56
57
  end
57
58
  end
58
59
  end
59
- end
60
+ end
@@ -55,8 +55,8 @@ module UcbRails
55
55
 
56
56
  def where(query)
57
57
  tokens = query.to_s.strip.split(/\s+/)
58
- wheres = tokens.map { |e| "#{search_column} like ?" }.join(' and ')
59
- values = tokens.map { |e| "%#{e}%" }
58
+ wheres = build_wheres(tokens)
59
+ values = build_values(tokens)
60
60
 
61
61
  ["#{wheres}", *values]
62
62
  end
@@ -76,6 +76,24 @@ module UcbRails
76
76
  end
77
77
 
78
78
  end
79
+
80
+ private
81
+ def build_wheres(tokens)
82
+ if defined?(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter) && ActiveRecord::Base.connection.kind_of?(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter)
83
+ tokens.map { |e| "REGEXP_LIKE(#{search_column}, ?, 'i' )" }.join(' and ')
84
+ else
85
+ tokens.map { |e| "#{search_column} like ?" }.join(' and ')
86
+ end
87
+ end
88
+
89
+ def build_values(tokens)
90
+ if defined?(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter) && ActiveRecord::Base.connection.kind_of?(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter)
91
+ tokens.map { |e| "#{e}" }
92
+ else
93
+ tokens.map { |e| "%#{e}%" }
94
+ end
95
+
96
+ end
79
97
  end
80
98
 
81
99
  end
@@ -1,7 +1,7 @@
1
1
  %h1 Send Test Email
2
2
 
3
3
  = form_tag(ucb_rails_admin_email_test_path) do
4
- %p= text_field_tag :email, params[:email], placeholder: 'email@example.com', class: 'span3'
4
+ %p= text_field_tag :email, params[:email], placeholder: 'email@example.com', class: 'col-md-3'
5
5
  %p= submit_button_tag "Send"
6
6
 
7
7
  - if @email_result.present?
@@ -3,6 +3,7 @@
3
3
  = f.input :first_name, :input_html => {disabled: 'disabled'}
4
4
  = f.input :last_name, :input_html => {disabled: 'disabled'}
5
5
  = f.input :email, :input_html => {disabled: 'disabled'}
6
+ = f.input :alternate_email
6
7
  = f.input :phone, :input_html => {disabled: 'disabled'}
7
8
  = f.input :last_login_at, as: :string, :input_html => {disabled: 'disabled', value: datetime_to_s(@user.last_login_at, :long)}
8
9
  = f.input :last_request_at, as: :string, :input_html => {disabled: 'disabled', value: datetime_to_s(@user.last_request_at, :long)}
@@ -5,9 +5,10 @@
5
5
  %td= user.first_name
6
6
  %td= user.last_name
7
7
  %td= mail_to(user.email)
8
+ %td= mail_to(user.alternate_email)
8
9
  %td.phone= user.phone
9
10
  %td.dt= datetime_to_s(user.last_request_at, :long)
10
11
  %td.min= user.uid
11
- %td= link_to('edit', edit_ucb_rails_admin_user_path(user), :class => 'btn btn-mini', :id => dom_id(user, 'edit'))
12
- %td= link_to('delete', ucb_rails_admin_user_path(user), :data => {confirm: 'Are you sure?'}, :method => :delete, :class => 'btn btn-mini btn-danger')
13
-
12
+ %td= link_to('edit', edit_ucb_rails_admin_user_path(user), :class => 'btn btn-default btn-xs', :id => dom_id(user, 'edit'))
13
+ %td= link_to('delete', ucb_rails_admin_user_path(user), :data => {confirm: 'Are you sure?'}, :method => :delete, :class => 'btn btn-xs btn-danger')
14
+
@@ -10,6 +10,7 @@
10
10
  %th First Name
11
11
  %th Last Name
12
12
  %th Email
13
+ %th Alternate Email
13
14
  %th Phone
14
15
  %th.dt Last Request At
15
16
  %th UID
@@ -19,4 +20,4 @@
19
20
  =# render partial: 'ucb_rails/admin/users/user', collection: @users
20
21
 
21
22
  = render :partial => 'ucb_rails/lps/modal'
22
-
23
+
@@ -1,13 +1,16 @@
1
1
  %h1 Logged In
2
2
 
3
3
  %p
4
- Your are logged in as #{session[:uid]}
4
+ You are logged in as #{session[:uid]}
5
5
 
6
6
  %p
7
7
  = link_to("Logout", logout_path)
8
8
 
9
9
  %hr
10
- %p= current_ldap_person.inspect
10
+ - begin
11
+ %p= current_ldap_person.inspect
12
+ - rescue Net::LDAP::LdapError, UCB::LDAP::BindFailedException => e
13
+ %p= current_user.inspect
11
14
 
12
15
  %hr
13
16
  = session.inspect
@@ -1,15 +1,15 @@
1
1
  Rails.application.routes.draw do
2
2
  root to: 'ucb_rails/home#index'
3
3
 
4
- match 'ucb_rails', :to => 'ucb_rails/home#index'
4
+ match 'ucb_rails', :to => 'ucb_rails/home#index', via: [:get]
5
5
 
6
- match '/login', :to => 'ucb_rails/sessions#new', :as => 'login'
7
- match '/logout', :to => 'ucb_rails/sessions#destroy', :as => 'logout'
8
- match '/auth/:omniauth_provider/callback' => 'ucb_rails/sessions#create'
9
- match '/auth/failure' => "ucb_rails/sessions#failure"
10
- match '/not_authorized', :to => 'ucb_rails/sessions#not_authorized', as: 'not_authorized'
6
+ match '/login', :to => 'ucb_rails/sessions#new', :as => 'login', via: [:get]
7
+ match '/logout', :to => 'ucb_rails/sessions#destroy', :as => 'logout', via: [:all]
8
+ match '/auth/:omniauth_provider/callback' => 'ucb_rails/sessions#create', via: [:get]
9
+ match '/auth/failure' => "ucb_rails/sessions#failure", via: [:get]
10
+ match '/not_authorized', :to => 'ucb_rails/sessions#not_authorized', as: 'not_authorized', via: [:get]
11
11
 
12
- match '/ucb_rails/bootstrap(/:uid)' => 'ucb_rails/bootstrap#index'
12
+ match '/ucb_rails/bootstrap(/:uid)' => 'ucb_rails/bootstrap#index', via: [:get]
13
13
 
14
14
  resources :hidden_announcements, path: '/announcements', only: [:index, :create, :destroy]
15
15
 
@@ -27,6 +27,15 @@ module UcbRails
27
27
  readme "README"
28
28
  end
29
29
  end
30
+
31
+ def self.next_migration_number(path)
32
+ unless @prev_migration_nr
33
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
34
+ else
35
+ @prev_migration_nr += 1
36
+ end
37
+ @prev_migration_nr.to_s
38
+ end
30
39
 
31
40
  private
32
41
 
@@ -36,7 +45,7 @@ module UcbRails
36
45
  # migration_template migration_file
37
46
  # puts migration_file
38
47
  relative_name = Pathname.new(migration_file).relative_path_from(Pathname.new(template_dir))
39
- migration_template relative_name
48
+ migration_template migration_file, relative_name
40
49
  end
41
50
  end
42
51
  end
@@ -12,6 +12,7 @@
12
12
  //
13
13
  //= require jquery
14
14
  //= require jquery_ujs
15
+ //= require tether
15
16
  //= require bootstrap
16
17
  //= require dataTables/jquery.dataTables
17
18
  //= require dataTables/jquery.dataTables.api.fnSetFilteringDelay
@@ -1,7 +1,7 @@
1
1
  $(function() {
2
2
 
3
3
  $('#ucb_rails_users').dataTable({
4
- "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
4
+ "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
5
5
  "sPaginationType": "bootstrap",
6
6
  "bProcessing": true,
7
7
  "bServerSide": true,
@@ -8,6 +8,7 @@
8
8
  * You're free to add application-wide styles to this file and they'll appear at the top of the
9
9
  * compiled file, but it's generally better to create a new file per style scope.
10
10
  *
11
+ *= require bootstrap-datepicker3
11
12
  *= require_self
12
13
  *= require dataTables/jquery.dataTables.bootstrap
13
14
  *= require_tree .
@@ -1,3 +1,4 @@
1
- $baseFontSize: 13px;
2
-
3
- @import "bootstrap";
1
+ @import "ucb_rails/variables";
2
+ @import "bootstrap-sprockets";
3
+ @import "bootstrap";
4
+ @import "ucb_rails";
@@ -1,5 +1,5 @@
1
1
  .footer
2
2
  %hr
3
3
  .container
4
- %p.muted.credit
4
+ %p.text-muted.credit
5
5
  = [UcbRails[:user_session_manager], session[:omniauth_provider] ].join(', ')
@@ -2,24 +2,27 @@
2
2
 
3
3
  = brand(app_name, url: root_path, with_environment: true)
4
4
 
5
- = nav_bar_links do
6
- - if logged_in?
7
- - if admin?
8
- = nav_dropdown("Admin") do
9
- = dropdown_item(announcements_text, admin_announcements_path)
10
- = dropdown_item(icon('user', "Users"), ucb_rails_admin_users_path)
11
-
12
- = render partial: 'layouts/developer'
5
+ = nav_bar_wrapper do
6
+ = nav_bar_links(pull: 'right') do
7
+ - if logged_in?
8
+ - if admin?
9
+ = nav_dropdown("Admin") do
10
+ = dropdown_item(announcements_text, admin_announcements_path)
11
+ = dropdown_item(icon('user', "Users"), ucb_rails_admin_users_path)
12
+
13
+ = render partial: 'layouts/developer'
13
14
 
15
+ = nav_dropdown("Logged in as #{current_user.full_name}") do
16
+ - if admin?
17
+ = dropdown_item(icon('user', "Disable admin user"), toggle_admin_path)
18
+ - else
19
+ = dropdown_item(icon('user', "Enable admin user"), toggle_admin_path)
20
+ = dropdown_item(announcements_text, hidden_announcements_path)
21
+ = dropdown_divider
22
+ = dropdown_item(icon('remove', 'Logout'), logout_path)
23
+
14
24
 
15
- - else
16
- %li
17
- = link_to('Login', login_path)
18
-
19
- - if logged_in?
20
- = nav_bar_links(pull: 'right') do
21
- = nav_dropdown("Logged in as #{current_user.first_last_name}") do
22
- = dropdown_item(announcements_text, hidden_announcements_path)
23
- = dropdown_divider
24
- = dropdown_item(icon('remove', 'Logout'), logout_path)
25
-
25
+ - else
26
+ %li
27
+ = link_to('Login', login_path)
28
+