bpluser 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +16 -0
  5. data/app/assets/javascripts/bpluser/application.js +15 -0
  6. data/app/assets/stylesheets/bpluser/application.css +13 -0
  7. data/app/controllers/bpluser/application_controller.rb +4 -0
  8. data/app/controllers/bpluser/registrations_controller.rb +0 -0
  9. data/app/controllers/bpluser/users/omniauth_callbacks_controller.rb +56 -0
  10. data/app/controllers/bpluser/users/registrations_controller.rb +30 -0
  11. data/app/controllers/bpluser/users/sessions_controller.rb +23 -0
  12. data/app/helpers/bpluser/application_helper.rb +4 -0
  13. data/app/models/bpluser/ability.rb +19 -0
  14. data/app/models/bpluser/folder.rb +21 -0
  15. data/app/models/bpluser/folder_item.rb +15 -0
  16. data/app/models/bpluser/user.rb +196 -0
  17. data/app/models/bpluser/user_institution.rb +6 -0
  18. data/app/views/layouts/bpluser/application.html.erb +14 -0
  19. data/config/routes.rb +2 -0
  20. data/lib/bpluser.rb +9 -0
  21. data/lib/bpluser/engine.rb +5 -0
  22. data/lib/bpluser/routes.rb +37 -0
  23. data/lib/bpluser/version.rb +3 -0
  24. data/lib/generators/bpluser/bpluser_generator.rb +183 -0
  25. data/lib/generators/bpluser/templates/config/hydra-ldap.yml +33 -0
  26. data/lib/generators/bpluser/templates/config/initializers/devise.rb +252 -0
  27. data/lib/generators/bpluser/templates/config/omniauth-facebook.yml +14 -0
  28. data/lib/generators/bpluser/templates/config/omniauth-polaris.yml +20 -0
  29. data/lib/generators/bpluser/templates/controllers/users/omniauth_callbacks_controller.rb +3 -0
  30. data/lib/generators/bpluser/templates/controllers/users/registrations_controller.rb +3 -0
  31. data/lib/generators/bpluser/templates/controllers/users/sessions_controller.rb +3 -0
  32. data/lib/generators/bpluser/templates/migrations/add_fields_to_user.rb +22 -0
  33. data/lib/generators/bpluser/templates/migrations/add_folder_items_to_folder.rb +18 -0
  34. data/lib/generators/bpluser/templates/migrations/add_folders_to_user.rb +14 -0
  35. data/lib/generators/bpluser/templates/migrations/create_institutions_for_users.rb +16 -0
  36. data/lib/generators/bpluser/templates/models/ability.rb +4 -0
  37. data/lib/generators/bpluser/templates/models/user.rb +14 -0
  38. data/lib/generators/bpluser/templates/views/devise/registrations/edit.html.erb +0 -0
  39. data/lib/generators/bpluser/templates/views/devise/registrations/new.html.erb +24 -0
  40. data/lib/generators/bpluser/templates/views/devise/sessions/new.html.erb +17 -0
  41. data/lib/tasks/bpluser_tasks.rake +10 -0
  42. data/test/bpluser_test.rb +7 -0
  43. data/test/dummy/README.rdoc +261 -0
  44. data/test/dummy/Rakefile +7 -0
  45. data/test/dummy/app/assets/javascripts/application.js +15 -0
  46. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  47. data/test/dummy/app/controllers/application_controller.rb +3 -0
  48. data/test/dummy/app/helpers/application_helper.rb +2 -0
  49. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/test/dummy/config.ru +4 -0
  51. data/test/dummy/config/application.rb +59 -0
  52. data/test/dummy/config/boot.rb +10 -0
  53. data/test/dummy/config/environment.rb +5 -0
  54. data/test/dummy/config/environments/development.rb +37 -0
  55. data/test/dummy/config/environments/production.rb +67 -0
  56. data/test/dummy/config/environments/test.rb +37 -0
  57. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  58. data/test/dummy/config/initializers/inflections.rb +15 -0
  59. data/test/dummy/config/initializers/mime_types.rb +5 -0
  60. data/test/dummy/config/initializers/secret_token.rb +7 -0
  61. data/test/dummy/config/initializers/session_store.rb +8 -0
  62. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  63. data/test/dummy/config/locales/en.yml +5 -0
  64. data/test/dummy/config/routes.rb +4 -0
  65. data/test/dummy/public/404.html +26 -0
  66. data/test/dummy/public/422.html +26 -0
  67. data/test/dummy/public/500.html +25 -0
  68. data/test/dummy/public/favicon.ico +0 -0
  69. data/test/dummy/script/rails +6 -0
  70. data/test/integration/navigation_test.rb +10 -0
  71. data/test/test_helper.rb +15 -0
  72. metadata +241 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 71b514669c4cda23e927e192539a04751fccf195
4
+ data.tar.gz: 674482be6c1eb831d6e563e480410bf1aec5fc65
5
+ SHA512:
6
+ metadata.gz: f810437e8fe0eabf46acc3b62b0094859b3dd42f677e25c95951071b10699c1a42b3a7361eb335db4235c45a08cdd726f1f9835599a9fec433333ca1872082fc
7
+ data.tar.gz: bd65bb29bca8a56f4347c732fa95709b7391b56aada53c9a1e15a7bd6b6ce050dce08389d20dada05900ff128e41c6ceddda663c8d2592f20a7707f87bc307fa
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright 2013 Boston Public Library
2
+ git a
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Bpluser
2
+
3
+ This project rocks.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ Bundler::GemHelper.install_tasks
11
+
12
+ # load rake tasks defined in lib/tasks that are not loaded in lib/active_fedora.rb
13
+ load "tasks/bpluser_tasks.rake"
14
+
15
+
16
+ task :default => :test
@@ -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, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, 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
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
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
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module Bpluser
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,56 @@
1
+ module Bpluser::Users::OmniauthCallbacksController
2
+
3
+
4
+ def self.included(base)
5
+ base.send :include, InstanceMethods
6
+ end
7
+
8
+ module InstanceMethods
9
+
10
+
11
+ def ldap
12
+
13
+ puts request.env["omniauth.auth"]
14
+
15
+
16
+ @user = User.find_for_ldap_oauth(request.env["omniauth.auth"], current_user)
17
+
18
+ if @user.persisted?
19
+ puts 'persisted'
20
+ flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Ldap"
21
+ sign_in_and_redirect @user, :event => :authentication
22
+ else
23
+ session["devise.ldap_data"] = request.env["omniauth.auth"]
24
+ redirect_to new_user_registration_url
25
+ end
26
+ end
27
+
28
+ def polaris
29
+ @user = User.find_for_polaris_oauth(request.env["omniauth.auth"], current_user)
30
+ if @user.persisted?
31
+ flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Polaris"
32
+ sign_in_and_redirect @user, :event => :authentication
33
+ else
34
+ session["devise.polaris_data"] = request.env["omniauth.auth"]
35
+ redirect_to new_user_registration_url
36
+ end
37
+ end
38
+
39
+ def password
40
+ puts "here in local authentication!"
41
+ end
42
+
43
+ def facebook
44
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
45
+ @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
46
+
47
+ if @user.persisted?
48
+ sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
49
+ set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
50
+ else
51
+ session["devise.facebook_data"] = request.env["omniauth.auth"]
52
+ redirect_to new_user_registration_url
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,30 @@
1
+ module Bpluser::Users::RegistrationsController
2
+ #< Devise::RegistrationsController
3
+ def self.included(base)
4
+ base.send :before_filter, :update_sanitized_params, :if => :devise_controller?
5
+ base.send :include, InstanceMethods
6
+ end
7
+
8
+ module InstanceMethods
9
+ def update_sanitized_params
10
+ devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:provider, :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :display_name, :uid)}
11
+ devise_parameter_sanitizer.for(:account_update) {|u| u.permit(:provider, :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :display_name, :uid)}
12
+ end
13
+
14
+ # POST /resource
15
+ def create
16
+ #devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :first_name, :last_name, :provider, :display_name, :password, :password_confirmation, :uid) }
17
+ params[:user][:provider] = "local"
18
+ params[:user][:uid] = params[:user][:email]
19
+ params[:user][:username] = params[:user][:uid]
20
+ params[:user][:display_name] = params[:user][:first_name] + " " + params[:user][:last_name]
21
+ super
22
+ end
23
+
24
+
25
+ def resource_params
26
+ params.require(:user).permit(:username, :email, :first_name, :last_name, :provider, :display_name, :password, :password_confirmation, :uid)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ module Bpluser::Users::SessionsController
2
+ #< Devise::RegistrationsController
3
+ def self.included(base)
4
+ base.send :include, InstanceMethods
5
+ end
6
+
7
+ module InstanceMethods
8
+ # GET /resource/sign_in
9
+ def new
10
+ if params[:user]
11
+ #TODO: FIX THIS
12
+ params[:user][:provider] = "local"
13
+ end
14
+
15
+ super
16
+ end
17
+
18
+ def resource_params
19
+ params.require(:user).permit(:username, :email, :first_name, :last_name, :provider, :display_name, :password, :password_confirmation, :uid)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module Bpluser
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ module Bpluser::Ability
2
+
3
+ def self.included(base)
4
+ base.send :include, InstanceMethods
5
+ end
6
+
7
+ module InstanceMethods
8
+ def initialize(user)
9
+ #can :read, :all
10
+ if user.superuser?
11
+ can [:create, :show, :add_user, :edit, :remove_user, :index], Role
12
+ can [:create, :show, :add_user, :edit, :remove_user, :index], Institution
13
+ end
14
+
15
+
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,21 @@
1
+ module Bpluser
2
+ class Folder < ActiveRecord::Base
3
+
4
+ belongs_to :user
5
+ has_many :folder_items, :dependent => :destroy, :class_name => "Bpluser::FolderItem"
6
+
7
+ validates :user_id, :presence => true
8
+ validates :title, :presence => true, :length => {:maximum => 40}
9
+ validates :description, :length => {:maximum => 250}
10
+ validates :visibility, :inclusion => {:in => %w(public private)}
11
+
12
+ #attr_accessible :id, :title, :description, :visibility
13
+
14
+ def has_folder_item (document_id)
15
+ self.folder_items.find do |fldr_itm|
16
+ return fldr_itm if fldr_itm.document_id == document_id
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Bpluser
2
+ class FolderItem < ActiveRecord::Base
3
+ #attr_accessible :document_id
4
+
5
+ belongs_to :folder, :class_name => "Bpluser::Folder"
6
+
7
+ validates :folder_id, :presence => true
8
+ validates :document_id, :presence => true
9
+
10
+ def document
11
+ SolrDocument.new SolrDocument.unique_key => :document_id
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,196 @@
1
+ module Bpluser::User
2
+
3
+
4
+ def self.included(base)
5
+ base.send :devise, :database_authenticatable, :registerable,
6
+ :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:ldap, :polaris, :facebook]
7
+ #base.send :attr_accessible, :provider, :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :display_name, :uid
8
+ base.send :has_many, :user_institutions, :class_name => "Bpluser::UserInstitution"
9
+ base.send :has_many, :folders, :dependent => :destroy, :class_name => "Bpluser::Folder"
10
+ base.extend(ClassMethods)
11
+ base.send :include, InstanceMethods
12
+
13
+ end
14
+
15
+ module ClassMethods
16
+ def find_for_ldap_oauth(auth_response, signed_in_resource=nil)
17
+
18
+
19
+ ldap_raw_details = auth_response[:extra][:raw_info]
20
+ ldap_info_details = auth_response[:info]
21
+
22
+ puts 'IN LDAP OAUTH'
23
+ puts ldap_raw_details.samaccountname[0].downcase
24
+
25
+ user = User.where(:provider => auth_response.provider, :uid => ldap_raw_details.samaccountname[0].downcase).first
26
+
27
+ #first_name:ldap_info_details.first_name,
28
+ #last_name:ldap_info_details.last_name,
29
+ unless user
30
+ user = User.create(provider:auth_response.provider,
31
+ uid:ldap_raw_details.samaccountname[0].downcase,
32
+ username:ldap_raw_details.samaccountname[0].downcase,
33
+ email:ldap_raw_details.mail[0].to_s.downcase,
34
+ password:Devise.friendly_token[0,20],
35
+ display_name: ldap_info_details.first_name + " " + ldap_info_details.last_name,
36
+ first_name: ldap_info_details.first_name,
37
+ last_name: ldap_info_details.last_name
38
+ )
39
+ end
40
+ groups = user.ldap_groups
41
+ groups.each do |group|
42
+ if(group == "Repository Administrators")
43
+ superuser_role = Role.where(:name=>'superuser').first
44
+ if(superuser_role == nil)
45
+ superuser_role = Role.create(:name=>"superuser")
46
+ end
47
+ user.roles << superuser_role unless user.roles.include?(superuser_role)
48
+ user.save!
49
+
50
+ admin_role = Role.where(:name=>'admin').first
51
+ if(admin_role == nil)
52
+ admin_role = Role.create(:name=>"admin")
53
+ end
54
+ user.roles << admin_role unless user.roles.include?(admin_role)
55
+ user.save!
56
+ end
57
+
58
+ end
59
+
60
+ user
61
+ end
62
+
63
+ def find_for_polaris_oauth(auth_response, signed_in_resource=nil)
64
+ polaris_raw_details = auth_response[:extra][:raw_info]
65
+ polaris_info_details = auth_response[:info]
66
+
67
+ user = User.where(:provider => auth_response.provider, :uid => auth_response[:uid]).first
68
+
69
+ #first_name:ldap_info_details.first_name,
70
+ #last_name:ldap_info_details.last_name,
71
+ unless user
72
+ user = User.create(provider:auth_response.provider,
73
+ uid:auth_response[:uid],
74
+ username:polaris_info_details[:first_name],
75
+ email:polaris_info_details[:email],
76
+ password:Devise.friendly_token[0,20],
77
+ display_name:polaris_info_details[:first_name] + " " + polaris_info_details[:last_name],
78
+ first_name: polaris_info_details[:first_name],
79
+ last_name: polaris_info_details[:last_name]
80
+
81
+ )
82
+
83
+ end
84
+ user
85
+ end
86
+
87
+ def find_for_facebook_oauth(auth, signed_in_resource=nil)
88
+ user = User.where(:provider => auth.provider, :uid => auth.uid).first
89
+ unless user
90
+ user = User.create(display_name:auth.extra.raw_info.name,
91
+ uid:auth.uid,
92
+ provider:auth.provider,
93
+ username:auth.info.nickname,
94
+ email:auth.info.email,
95
+ password:Devise.friendly_token[0,20] ,
96
+ first_name:auth.extra.raw_info.first_name,
97
+ last_name:auth.extra.raw_info.last_name
98
+ )
99
+ end
100
+ user
101
+ end
102
+
103
+ def find_for_local_auth(auth, signed_in_resource=nil)
104
+ user = User.where(:provider => auth.provider, :uid => auth.uid).first
105
+ unless user
106
+ user = User.create(display_name:auth.extra.raw_info.name,
107
+ uid:auth.uid,
108
+ provider:auth.provider,
109
+ username:auth.info.nickname,
110
+ email:auth.info.email,
111
+ password:Devise.friendly_token[0,20] ,
112
+ first_name:auth.extra.raw_info.first_name,
113
+ last_name:auth.extra.raw_info.last_name
114
+ )
115
+ end
116
+ user
117
+ end
118
+
119
+
120
+ # This method should find User objects using the user_key you've chosen.
121
+ # By default, uses the unique identifier specified in by devise authentication_keys (ie. find_by_id, or find_by_email).
122
+ # You must have that find method implemented on your user class, or must override find_by_user_key
123
+ #def find_by_user_key(key)
124
+ #self.send("find_by_#{Devise.authentication_keys.first}".to_sym, key)
125
+ #end
126
+ end
127
+
128
+ #has_and_belongs_to_many :groups
129
+
130
+ # Method added by Blacklight; Blacklight uses #to_s on your
131
+ # user class to get a user-displayable login/identifier for
132
+ # the account.
133
+
134
+ # The following methods will be included in any active model object
135
+ # that calls "is_blacklight_user"
136
+ module InstanceMethods
137
+
138
+
139
+ def to_s
140
+ self.username
141
+ end
142
+
143
+ def name
144
+ return self.username rescue self.display_name.titleize
145
+ end
146
+
147
+ def user_key
148
+ send(Devise.authentication_keys.first)
149
+ end
150
+
151
+
152
+ def ldap_groups
153
+ #Hydra::LDAP.groups_for_user(username + ",dc=psu,dc=edu")
154
+ #['archivist', 'admin_policy_object_editor']
155
+
156
+ Hydra::LDAP.groups_for_user(Net::LDAP::Filter.eq('samaccountname', self.username), ['memberOf']) { |result| result.first[:memberOf].select{ |y| y.starts_with? 'CN=' }.map{ |x| x.sub(/^CN=/, '').sub(/,OU=Private Groups,DC=private,DC=bpl,DC=org/, '').sub(/,OU=Distribution Lists/, '').sub(/,OU=Security Groups/, '') } } rescue []
157
+ end
158
+
159
+ def populate_attributes
160
+
161
+ end
162
+
163
+ def default_user_groups
164
+ # # everyone is automatically a member of the group 'public'
165
+ #['public', 'test']
166
+ end
167
+
168
+ def get_uploads_collection
169
+ query="rightsMetadata_edit_access_machine_person_t:#{uid} AND title_s:Uploads AND has_model_s:info\\:fedora/afmodel\\:DILCollection"
170
+ ActiveFedora::SolrService.query(query, {:fl=>'id title_t'})
171
+ end
172
+
173
+ def get_details_collection
174
+ query="rightsMetadata_edit_access_machine_person_t:#{uid} AND title_s:Details AND has_model_s:info\\:fedora/afmodel\\:DILCollection"
175
+ ActiveFedora::SolrService.query(query, {:fl=>'id title_t'})
176
+ end
177
+
178
+ def collections
179
+ query="rightsMetadata_edit_access_machine_person_t:#{uid} AND NOT title_t:Uploads AND NOT title_t:Details AND has_model_s:info\\:fedora/afmodel\\:DILCollection"
180
+ ActiveFedora::SolrService.query(query, {:fl=>'id title_t'})
181
+ end
182
+
183
+ def existing_folder_item_for (document_id)
184
+ self.folders.find do |fldr|
185
+ fldr.folder_items.find do |fldr_itm|
186
+ return fldr_itm if fldr_itm.document_id == document_id
187
+ end
188
+ end
189
+ end
190
+
191
+ def superuser?
192
+ roles.where(name: 'superuser').exists?
193
+ end
194
+
195
+ end
196
+ end