wobauth 4.0.0 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 036ba4d2f604909cb8d224f27fc1570723520ddcdbe0f830e26f3f2eecdb93ae
4
- data.tar.gz: 781621423c2cccdff5f9c1477eae55cfe9517d6e21f814bfbe67f8c4b0e04d6a
3
+ metadata.gz: ece99ba3c367db93f0174e65b7322eee6b8eb14ce78ef81e1b954672833fb56a
4
+ data.tar.gz: 2eb7759dd766870f95cdfd7ed18f712e650dd364ab4a8179cb789ce65a644618
5
5
  SHA512:
6
- metadata.gz: c2615f3b762673ab9697f2d2619d2965269f2763daa246517c0039e63e52e7309f2b71cab759e5900e843401f88eee5e71994f43d209bbfa44cacbf817640b43
7
- data.tar.gz: 0af1198085fb8ef517204d41990cfb64b9d280b85b478d0ea3ca4b36b804e11075a4e3b129dbe480c4f90ebe26add903bf20ed88a10b85b6e79ccd5e17a93af2
6
+ metadata.gz: fbd648f6565680dd3f3d2f344b7c7b39bbe2ddadea2285828e18bc803ba1cfbc1146fddd740cc6c5d26b352b04444295890bad1aa6d7ab936a7f0f1dd855454e
7
+ data.tar.gz: e75e32b2f84fbf4b0c4405769c154c65cff5d88b6d6a9b40001dfae05f6ae33e4d4a649654da472821f8a3b02dce0673e4641cd3443cd4c3eee5d82062d62c0f
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License (MIT)
2
2
 
3
- Copyright (c) 2014-2019 Wolfgang Barth
3
+ Copyright (c) 2014-2020 Wolfgang Barth
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -29,13 +29,22 @@ wobauth 1.x is for Rails 4, wobauth 2.x will support Rails 5.
29
29
  wobauth 3.x uses bootstrap v4 and font-awesome, starting with Rails 5.1
30
30
  (may work with Rails 5.0, but not tested)
31
31
  wobauth 4.x works with sprockets v4.
32
+ wobauth 5.x works with rails 6.x and is designed for autoloading via zeitwerk.
32
33
 
33
34
  Requirements
34
35
  ------------
35
36
 
37
+ ### Rails >= 6.0, autoload = :zeitwerk
38
+
39
+ | branch | rails | ruby | bootstrap | icons | wobapphelpers |
40
+ |------------|-------|--------|-----------|-----------------|---------------|
41
+ | master(5.x)| >=6.0 | >= 2.6 | v4 | fontawesome 5.x | master (4.x) |
42
+
43
+ ### Rails <= 5.2, autoload = :classic
44
+
36
45
  | branch | rails | ruby | bootstrap | icons | wobapphelpers |
37
46
  |------------|-------|--------|-----------|-----------------|---------------|
38
- | master(4.x)| >=5.1 | >= 2.3 | v4 | fontawesome 5.x | master (4.x) |
47
+ | 4-0-stable | >=5.1 | >= 2.3 | v4 | fontawesome 5.x | master (4.x) |
39
48
  | 3-0-stable | >=5.1 | >= 2.3 | v4 | fontawesome 4.7 | 3-0-stable |
40
49
  | 2-0-stable | 5.0 | >= 2.2 | v3 | glyphicons | 2-0-stable |
41
50
  | 1-0-stable | 4.2 | >= 2.0 | v3 | glyphicons | 1-0-stable |
@@ -48,6 +57,7 @@ Installation
48
57
  Add wobauth to your Gemfile:
49
58
 
50
59
  ```ruby
60
+ gem 'wobauth', '~> 5.0.0'
51
61
  gem 'wobauth', '~> 4.0.0'
52
62
  gem 'wobauth', '~> 3.4.8'
53
63
  gem 'wobauth', git: 'https://github.com/swobspace/wobauth.git', branch: '3-0-stable'
@@ -171,7 +181,7 @@ included in this rails engine.
171
181
  Licence
172
182
  -------
173
183
 
174
- wobauth Copyright (C) 2014-2019 Wolfgang Barth
184
+ wobauth Copyright (C) 2014-2020 Wolfgang Barth
175
185
 
176
186
  MIT license, see [LICENSE](LICENSE)
177
187
 
@@ -4,14 +4,14 @@
4
4
 
5
5
  # - start with given values
6
6
  auth_types = $('#authority_authorizable_type').find("option:selected").val()
7
- $('#authority_authorizable_id optgroup').find('option').addBack().hide()
8
- $("#authority_authorizable_id optgroup[label=\"#{auth_types}\"]").find('option').addBack().show()
7
+ $('#authority_authorizable_id optgroup').find('option').addBack().attr("disabled", true)
8
+ $("#authority_authorizable_id optgroup[label=\"#{auth_types}\"]").find('option').addBack().attr("disabled", false)
9
9
 
10
10
  # - redisplay on change
11
11
  $(document).on('click', '#authority_authorizable_type', ->
12
12
  type = $(this).find("option:selected").val()
13
- $('#authority_authorizable_id optgroup').find('option').addBack().hide()
14
- $("#authority_authorizable_id optgroup[label=\"#{type}\"]").find('option').addBack().show()
13
+ $('#authority_authorizable_id optgroup').find('option').addBack().attr("disabled", true)
14
+ $("#authority_authorizable_id optgroup[label=\"#{type}\"]").find('option').addBack().attr("disabled", false)
15
15
  )
16
16
 
17
17
  #
@@ -20,12 +20,12 @@ $(document).on('click', '#authority_authorizable_type', ->
20
20
 
21
21
  # - start with given values
22
22
  authfor_type = $('#authority_authorized_for_type').find("option:selected").val()
23
- $('#authority_authorized_for_id optgroup').find('option').addBack().hide()
24
- $("#authority_authorized_for_id optgroup[label=\"#{authfor_type}\"]").find('option').addBack().show()
23
+ $('#authority_authorized_for_id optgroup').find('option').addBack().attr("disabled", true)
24
+ $("#authority_authorized_for_id optgroup[label=\"#{authfor_type}\"]").find('option').addBack().attr("disabled", false)
25
25
 
26
26
  # - redisplay on change
27
27
  $(document).on('click', '#authority_authorized_for_type', ->
28
28
  type = $(this).find("option:selected").val()
29
- $('#authority_authorized_for_id optgroup').find('option').addBack().hide()
30
- $("#authority_authorized_for_id optgroup[label=\"#{type}\"]").find('option').addBack().show()
29
+ $('#authority_authorized_for_id optgroup').find('option').addBack().attr("disabled", true)
30
+ $("#authority_authorized_for_id optgroup[label=\"#{type}\"]").find('option').addBack().attr("disabled", false)
31
31
  )
@@ -1,19 +1,7 @@
1
1
  module Wobauth
2
2
  module ApplicationHelper
3
3
  include Wobapphelpers::Helpers::All
4
-
5
- def polymorphic_selector(form, poly, types, group_method = :all)
6
- msg = ""
7
- # -- object available?
8
- if form.object.send(poly).present?
9
- msg += poly_type_display(form, poly)
10
- msg += poly_id_select(form, poly, form.object.send("#{poly}_type"), :all)
11
- else
12
- msg += poly_type_select(form, poly, types)
13
- msg += poly_id_select(form, poly, types, group_method)
14
- end
15
- msg.html_safe
16
- end
4
+ include Wobapphelpers::Helpers::PolymorphicHelper
17
5
 
18
6
  def navigation_admin_links
19
7
  render partial: 'wobauth/shared/admin'
@@ -29,25 +17,5 @@ module Wobauth
29
17
  end
30
18
  end
31
19
 
32
- private
33
-
34
- def poly_type_select(f, poly, types)
35
- f.input "#{poly}_type".to_sym, collection: types,
36
- label_method: lambda {|x| t('activerecord.models.' + x.underscore)}
37
- end
38
-
39
- def poly_type_display(f, poly)
40
- f.input("#{poly}_type".to_sym, collection: Array(f.object.send("#{poly}_type")),
41
- label_method: lambda {|x| t('activerecord.models.' + x.underscore)},
42
- disabled: true) +
43
- f.hidden_field("#{poly}_type".to_sym, value: f.object.send("#{poly}_type"))
44
- end
45
-
46
- def poly_id_select(f, poly, types, group_method)
47
- collections = Array(types).map {|t| t.constantize}
48
- f.input "#{poly}_id".to_sym, collection: collections,
49
- as: :grouped_select, group_method: group_method
50
- end
51
-
52
20
  end
53
21
  end
@@ -8,8 +8,7 @@ module Wobauth
8
8
  source: :user
9
9
  # -- configuration
10
10
  # -- validations and callbacks
11
- validates :name, :presence => true, :uniqueness => true
12
-
11
+ validates :name, presence: true, uniqueness: {case_sensitive: true}
13
12
 
14
13
  def to_s
15
14
  name
@@ -10,7 +10,7 @@ module Wobauth
10
10
  source_type: Wobauth::Group
11
11
  # -- configuration
12
12
  # -- validations and callbacks
13
- validates :name, :presence => true, :uniqueness => true
13
+ validates :name, presence: true, uniqueness: {case_sensitive: true}
14
14
 
15
15
  def to_s
16
16
  name
@@ -1,7 +1,8 @@
1
+ require_dependency 'wobauth/concerns/models/user_concerns'
1
2
  module Wobauth
2
3
  class User < ActiveRecord::Base
3
4
  # dependencies within wobauth models
4
-   include Wobauth::Concerns::Models::User
5
+   include UserConcerns
5
6
 
6
7
  # Include default devise modules. Others available are:
7
8
  # :confirmable, :lockable, :timeoutable and :omniauthable
@@ -17,17 +17,27 @@ module Wobauth
17
17
  return Result.new(success: false, error_messages: ["no query given"], ad_users: [])
18
18
  end
19
19
 
20
- ldap = Wobaduser::LDAP.new(ldap_options: ldap_options)
21
- if ldap.errors.any?
22
- return Result.new(success: false, error_messages: ldap.errors, ad_users: [])
20
+ errors = []
21
+ ad_users = []
22
+ ldap_options.each do |ldapopts|
23
+ ldap = Wobaduser::LDAP.new(ldap_options: ldapopts)
24
+ if ldap.errors.any?
25
+ errors += ldap.errors
26
+ next
27
+ end
28
+ search = Wobaduser::User.search(ldap: ldap, filter: user_filter(query))
29
+ if search.success?
30
+ ad_users += search.entries
31
+ else
32
+ errors += search.errors
33
+ end
23
34
  end
24
35
 
25
- search = Wobaduser::User.search(ldap: ldap, filter: user_filter(query))
26
- if search.success?
27
- result = Result.new(success: true, error_messages: [], ad_users: search.entries)
36
+ if errors.any?
37
+ return Result.new(success: false, error_messages: errors, ad_users: ad_users)
28
38
  else
29
- result = Result.new(success: false, error_messages: search.errors, ad_users: [])
30
- end
39
+ result = Result.new(success: true, error_messages: errors, ad_users: ad_users)
40
+ end
31
41
  end
32
42
 
33
43
  private
@@ -50,5 +60,13 @@ module Wobauth
50
60
  filter += ")"
51
61
  filter = Net::LDAP::Filter.construct(filter)
52
62
  end
63
+
64
+ def ldap_options
65
+ if @ldap_options.kind_of? Hash
66
+ [@ldap_options]
67
+ else
68
+ @ldap_options
69
+ end
70
+ end
53
71
  end
54
- end
72
+ end
@@ -11,12 +11,16 @@
11
11
  <%= polymorphic_selector(f,
12
12
  'authorizable',
13
13
  Wobauth.authorizable_types,
14
- Wobauth.authorizable_group_method) %>
14
+ Wobauth.authorizable_group_method,
15
+ {class: 'select2'})
16
+ %>
15
17
  <%= f.association :role %>
16
18
  <%= polymorphic_selector(f,
17
19
  'authorized_for',
18
20
  Wobauth.authorized_for_types,
19
- Wobauth.authorized_for_group_method) %>
21
+ Wobauth.authorized_for_group_method,
22
+ {class: 'select2'})
23
+ %>
20
24
 
21
25
  <%= f.input :valid_from, as: :string, class: 'datepicker'
22
26
  %>
@@ -3,33 +3,33 @@
3
3
  <h4><%= t('activerecord.models.wobauth/authority') %></h4>
4
4
  </div>
5
5
  <div class="card-body">
6
- <table class="table table-bordered table-hover autowidth">
6
+ <table class="table table-sm table-borderless">
7
7
  <tr>
8
- <th><%= t('attributes.authorizable')%>:</th>
8
+ <th class="w-25 text-right"><%= t('attributes.authorizable')%>:</th>
9
9
  <td><%= @authority.authorizable %></td>
10
10
  </tr>
11
11
  <tr>
12
- <th><%= t('attributes.authorizable_type')%>:</th>
12
+ <th class="w-25 text-right"><%= t('attributes.authorizable_type')%>:</th>
13
13
  <td><%= @authority.authorizable_type %></td>
14
14
  </tr>
15
15
  <tr>
16
- <th><%= t('attributes.role')%>:</th>
16
+ <th class="w-25 text-right"><%= t('attributes.role')%>:</th>
17
17
  <td><%= @authority.role %></td>
18
18
  </tr>
19
19
  <tr>
20
- <th><%= t('attributes.authorized_for')%>:</th>
20
+ <th class="w-25 text-right"><%= t('attributes.authorized_for')%>:</th>
21
21
  <td><%= @authority.authorized_for %></td>
22
22
  </tr>
23
23
  <tr>
24
- <th><%= t('attributes.authorized_for_type')%>:</th>
24
+ <th class="w-25 text-right"><%= t('attributes.authorized_for_type')%>:</th>
25
25
  <td><%= @authority.authorized_for_type %></td>
26
26
  </tr>
27
27
  <tr>
28
- <th><%= t('attributes.valid_from')%>:</th>
28
+ <th class="w-25 text-right"><%= t('attributes.valid_from')%>:</th>
29
29
  <td><%= @authority.valid_from %></td>
30
30
  </tr>
31
31
  <tr>
32
- <th><%= t('attributes.valid_until')%>:</th>
32
+ <th class="w-25 text-right"><%= t('attributes.valid_until')%>:</th>
33
33
  <td><%= @authority.valid_until %></td>
34
34
  </tr>
35
35
  </table>
@@ -3,17 +3,17 @@
3
3
  <h4><%= t('attributes.membership') %></h4>
4
4
  </div>
5
5
  <div class="card-body">
6
- <table class="table table-bordered table-hover autowidth">
6
+ <table class="table table-sm table-borderless ">
7
7
  <tr>
8
- <th><%= t('attributes.user')%>:</th>
8
+ <th class="w-25 text-right"><%= t('attributes.user')%>:</th>
9
9
  <td><%= @membership.user %></td>
10
10
  </tr>
11
11
  <tr>
12
- <th><%= t('attributes.group')%>:</th>
12
+ <th class="w-25 text-right"><%= t('attributes.group')%>:</th>
13
13
  <td><%= @membership.group %></td>
14
14
  </tr>
15
15
  <tr>
16
- <th><%= t('attributes.auto')%>:</th>
16
+ <th class="w-25 text-right"><%= t('attributes.auto')%>:</th>
17
17
  <td><%= @membership.auto %></td>
18
18
  </tr>
19
19
  </table>
@@ -49,4 +49,4 @@
49
49
 
50
50
  <%= back_link %>
51
51
  <%= new_link [wobauth, Wobauth::User] %>
52
- <%= link_to t('wobauth.new_user_from_ad'), wobauth.ad_users_path, class: 'btn btn-secondary' %>
52
+ <%= link_to(t('wobauth.new_user_from_ad'), wobauth.ad_users_path, class: 'btn btn-secondary') if can? :create, Wobauth::User %>
@@ -94,7 +94,7 @@
94
94
  <%= edit_link([wobauth, @user]) %>
95
95
  <%= delete_link([wobauth, @user]) %>
96
96
  <%= new_link [wobauth, Wobauth::User] %>
97
- <%= link_to t('wobauth.new_user_from_ad'), wobauth.ad_users_path, class: 'btn btn-secondary' %>
97
+ <%= link_to(t('wobauth.new_user_from_ad'), wobauth.ad_users_path, class: 'btn btn-secondary') if can? :create, Wobauth::User %>
98
98
  </div>
99
99
 
100
100
  </div>
@@ -0,0 +1,41 @@
1
+ # simple
2
+ ldap_options:
3
+ host: 1.2.3.4
4
+ port: 3268
5
+ base: dc=example,dc=com
6
+ auth:
7
+ method: :simple
8
+ username: myusername
9
+ password: mysecretpassword
10
+
11
+ # redundant: 1 directory with 2 redundant servers
12
+ ldap_options:
13
+ hosts:
14
+ - [1.2.3.4, 3269]
15
+ - [5.6.7.8, 3269]
16
+ encryption: :simple_tls
17
+ base: dc=example,dc=com
18
+ auth:
19
+ method: :simple
20
+ username: myusername
21
+ password: mysecretpassword
22
+
23
+ # multiple directories
24
+ ldap_options:
25
+ - host: 1.2.3.4
26
+ port: 3268
27
+ base: dc=example,dc=com
28
+ auth:
29
+ method: :simple
30
+ username: myusername
31
+ password: mysecretpassword
32
+ - host: 5.6.7.8
33
+ port: 3269
34
+ base: dc=example,dc=com
35
+ encryption: :simple_tls
36
+ auth:
37
+ method: :simple
38
+ username: myusername
39
+ password: mysecretpassword
40
+
41
+
@@ -1,10 +1,14 @@
1
1
  de:
2
2
  wobapphelpers:
3
3
  helpers:
4
- back: "Zurück"
5
- cancel: "Abbrechen"
6
- controller:
7
- new: "%{name} erstellen"
8
- create: "%{name} erstellen"
9
- edit: "%{name} bearbeiten"
10
- update: "%{name} bearbeiten"
4
+ back: Zurück
5
+ cancel: Abbrechen
6
+ actions:
7
+ new: "%{model} erstellen"
8
+ create: "%{model} erstellen"
9
+ show: "%{model} anzeigen"
10
+ edit: "%{model} bearbeiten"
11
+ copy: "%{model} kopieren"
12
+ update: "%{model} bearbeiten"
13
+ destroy: "%{model} löschen"
14
+ destroy_confirm: "Der Datensatz kann nicht wieder hergestellt werden!"
@@ -3,6 +3,12 @@ en:
3
3
  helpers:
4
4
  back: Back
5
5
  cancel: Cancel
6
- controller:
7
- new: "create %{name}"
8
- edit: "update %{name}"
6
+ actions:
7
+ new: "create %{model}"
8
+ create: "create %{model}"
9
+ show: "show %{model}"
10
+ edit: "update %{model}"
11
+ update: "update %{model}"
12
+ copy: "copy %{model}"
13
+ destroy: "destroy %{model}"
14
+ destroy_confirm: "record would be finally destroyed, no recovery possible!"
@@ -45,13 +45,18 @@ module Wobauth
45
45
  config ||= Hash.new
46
46
 
47
47
  if config['ldap_options'].present?
48
- opts = config['ldap_options'].symbolize_keys
49
- opts.each do |k,v|
50
- opts[k] = opts[k].symbolize_keys if opts[k].kind_of? Hash
48
+ ldapopts = config['ldap_options']
49
+ if ldapopts.kind_of? Hash
50
+ ldapopts = [ldapopts]
51
+ end
52
+ ldapopts.each do |opts|
53
+ opts.symbolize_keys!
54
+ opts.each do |k,v|
55
+ opts[k] = opts[k].symbolize_keys if opts[k].kind_of? Hash
56
+ end
51
57
  end
52
58
  else
53
59
  nil
54
60
  end
55
61
  end
56
-
57
62
  end
@@ -0,0 +1,40 @@
1
+ module UserConcerns
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :authorities, as: :authorizable, dependent: :destroy
6
+ has_many :roles, through: :authorities
7
+ has_many :memberships, dependent: :destroy
8
+ has_many :groups, -> { distinct }, through: :memberships
9
+ has_many :group_roles, through: :groups, source: :roles
10
+ has_many :group_authorities, through: :groups, source: :authorities
11
+
12
+ validates :username, presence: true, uniqueness: { case_sensitive: false }
13
+ end
14
+
15
+
16
+ def to_s
17
+ if sn.blank? and givenname.blank?
18
+ "#{username}"
19
+ elsif title.blank?
20
+ "#{sn}, #{givenname} (#{username})"
21
+ else
22
+ "#{sn}, #{title} #{givenname} (#{username})"
23
+ end
24
+ end
25
+
26
+ def name
27
+ to_s
28
+ end
29
+
30
+ def is_admin?
31
+ role?(:admin)
32
+ end
33
+
34
+ def role?(role)
35
+ (self.authorities.joins(:role)
36
+ .where("wobauth_roles.name = ?", role.to_s.camelize).present?) ||
37
+ (self.group_authorities.joins(:role)
38
+ .where("wobauth_roles.name = ?", role.to_s.camelize).present?)
39
+ end
40
+ end
@@ -1,4 +1,4 @@
1
1
  module Wobauth
2
- VERSION = "4.0.0".freeze
3
- RELEASEDATE = "2019-11-28".freeze
2
+ VERSION = "5.1.1".freeze
3
+ RELEASEDATE = "2020-10-03".freeze
4
4
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wobauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wolfgang Barth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-28 00:00:00.000000000 Z
11
+ date: 2020-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
33
+ version: '4.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
40
+ version: '4.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: wobaduser
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -636,6 +636,7 @@ files:
636
636
  - config/initializers/simple_form.rb
637
637
  - config/initializers/simple_form_bootstrap.rb
638
638
  - config/initializers/wobapphelpers.rb
639
+ - config/ldap.yml.example
639
640
  - config/locales/de.yml
640
641
  - config/locales/devise.de.yml
641
642
  - config/locales/devise.en.yml
@@ -650,7 +651,6 @@ files:
650
651
  - db/migrate/20140504143328_create_wobauth_authorities.rb
651
652
  - db/migrate/20140508120810_devise_create_wobauth_users.rb
652
653
  - db/migrate/20171231084355_additional_fields_to_wobauth_user.rb
653
- - lib/concerns/models/user.rb
654
654
  - lib/generators/templates/initializers/wobauth.rb
655
655
  - lib/generators/wobauth/install_generator.rb
656
656
  - lib/tasks/wobauth_tasks.rake
@@ -661,6 +661,7 @@ files:
661
661
  - lib/templates/erb/scaffold/show.html.erb
662
662
  - lib/templates/rails/scaffold_controller/controller.rb
663
663
  - lib/wobauth.rb
664
+ - lib/wobauth/concerns/models/user_concerns.rb
664
665
  - lib/wobauth/engine.rb
665
666
  - lib/wobauth/version.rb
666
667
  - spec/factories.rb
@@ -1,44 +0,0 @@
1
- module Wobauth
2
- module Concerns
3
- module Models::User
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- has_many :authorities, as: :authorizable, dependent: :destroy
8
- has_many :roles, through: :authorities
9
- has_many :memberships, dependent: :destroy
10
- has_many :groups, -> { distinct }, through: :memberships
11
- has_many :group_roles, through: :groups, source: :roles
12
- has_many :group_authorities, through: :groups, source: :authorities
13
-
14
- validates :username, presence: true, uniqueness: true
15
- end
16
-
17
-
18
- def to_s
19
- if sn.blank? and givenname.blank?
20
- "#{username}"
21
- elsif title.blank?
22
- "#{sn}, #{givenname} (#{username})"
23
- else
24
- "#{sn}, #{title} #{givenname} (#{username})"
25
- end
26
- end
27
-
28
- def name
29
- to_s
30
- end
31
-
32
- def is_admin?
33
- role?(:admin)
34
- end
35
-
36
- def role?(role)
37
- (self.authorities.joins(:role)
38
- .where("wobauth_roles.name = ?", role.to_s.camelize).present?) ||
39
- (self.group_authorities.joins(:role)
40
- .where("wobauth_roles.name = ?", role.to_s.camelize).present?)
41
- end
42
- end
43
- end
44
- end