cratus 0.4.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03546e33c0cbcd721059db8bee9f197fc831b55c
4
- data.tar.gz: 9880fb938e1a84cd89fc28d0f4d762a6b3d5371a
3
+ metadata.gz: 2a7f6ee41d2c3cb44be9ed8cb997b5f04d5863a3
4
+ data.tar.gz: 183f3884544b5e1849b381544c0cf483edb97795
5
5
  SHA512:
6
- metadata.gz: 0aeb98394522da853724b82fda06d2a429185c29115cb0b74f275362cc8ad738902a144dcf1da5861fc970f012309915927a76c3dee9da5771d160c3d4ce927c
7
- data.tar.gz: 80ecee4931f58e86b5cb497d1a34ac0699b9738f65f4734b4217b29273273f9f924af8a0968ba31696394d2d80f03b8eb50da28037498f7706835fea4805d1ae
6
+ metadata.gz: 6fbbd87ce2d16d4e9edb2f9e0103d3e52a6eb687839ca96e0507b3f8acbf1fbd1887aaff7dddd3fc1f29533e5550392efcfe41f213b0deb11cc6df34003d4184
7
+ data.tar.gz: 0332fbe4a461dd29ee3ce5fa17e81ab7aef9db17b95fd353d9fa459ffa2370f193bccfa7cc7b9c3951335f5cf695d0484cb2159d6780bc037812bcaaa2883ace
@@ -14,6 +14,7 @@ module Cratus
14
14
  user_dn_attribute: :samaccountname,
15
15
  user_objectclass: :user,
16
16
  user_basedn: 'ou=users,dc=example,dc=com',
17
+ user_account_control_attribute: :userAccountControl,
17
18
  user_department_attribute: :department,
18
19
  user_lockout_attribute: :lockouttime,
19
20
  user_mail_attribute: :mail,
@@ -7,11 +7,7 @@ module Cratus
7
7
  def initialize(username)
8
8
  @username = username
9
9
  @search_base = self.class.ldap_search_base
10
- @raw_ldap_data = Cratus::LDAP.search(
11
- "(#{self.class.ldap_dn_attribute}=#{@username})",
12
- basedn: @search_base,
13
- attrs: self.class.ldap_return_attributes
14
- ).last
10
+ refresh
15
11
  end
16
12
 
17
13
  # Add a user to a group
@@ -32,6 +28,25 @@ module Cratus
32
28
  @raw_ldap_data[Cratus.config.user_department_attribute].last
33
29
  end
34
30
 
31
+ # Disables an enabled user
32
+ def disable
33
+ if enabled?
34
+ Cratus::LDAP.replace_attribute(
35
+ dn,
36
+ Cratus.config.user_account_control_attribute,
37
+ ['514']
38
+ )
39
+ refresh
40
+ else
41
+ true
42
+ end
43
+ end
44
+
45
+ def disabled?
46
+ status = @raw_ldap_data[Cratus.config.user_account_control_attribute].last
47
+ status.to_s == '514'
48
+ end
49
+
35
50
  def dn
36
51
  @raw_ldap_data[:dn].last
37
52
  end
@@ -40,6 +55,25 @@ module Cratus
40
55
  @raw_ldap_data[Cratus.config.user_mail_attribute].last
41
56
  end
42
57
 
58
+ # Enables a disabled user
59
+ def enable
60
+ if disabled?
61
+ Cratus::LDAP.replace_attribute(
62
+ dn,
63
+ Cratus.config.user_account_control_attribute,
64
+ ['512']
65
+ )
66
+ refresh
67
+ else
68
+ true
69
+ end
70
+ end
71
+
72
+ def enabled?
73
+ status = @raw_ldap_data[Cratus.config.user_account_control_attribute].last
74
+ status.to_s == '512'
75
+ end
76
+
43
77
  def fullname
44
78
  @raw_ldap_data[Cratus.config.user_displayname_attribute].last
45
79
  end
@@ -90,6 +124,32 @@ module Cratus
90
124
 
91
125
  alias groups member_of
92
126
 
127
+ def refresh
128
+ @raw_ldap_data = Cratus::LDAP.search(
129
+ "(#{self.class.ldap_dn_attribute}=#{@username})",
130
+ basedn: @search_base,
131
+ attrs: self.class.ldap_return_attributes
132
+ ).last
133
+ end
134
+
135
+ # Unlocks a user
136
+ # @return `true` on success (or if user is already unlocked)
137
+ # @return `false` when the account is disabled (unlocking not permitted)
138
+ def unlock
139
+ if locked? && enabled?
140
+ Cratus::LDAP.replace_attribute(
141
+ dn,
142
+ Cratus.config.user_lockout_attribute,
143
+ ['0']
144
+ )
145
+ refresh
146
+ elsif disabled?
147
+ false
148
+ else
149
+ true
150
+ end
151
+ end
152
+
93
153
  def <=>(other)
94
154
  @username <=> other.username
95
155
  end
@@ -121,7 +181,8 @@ module Cratus
121
181
  Cratus.config.user_mail_attribute.to_s,
122
182
  Cratus.config.user_displayname_attribute.to_s,
123
183
  Cratus.config.user_memberof_attribute.to_s,
124
- Cratus.config.user_lockout_attribute.to_s
184
+ Cratus.config.user_lockout_attribute.to_s,
185
+ Cratus.config.user_account_control_attribute.to_s
125
186
  ]
126
187
  end
127
188
 
@@ -2,7 +2,7 @@
2
2
  module Cratus
3
3
  def self.version
4
4
  major = 0 # Breaking, incompatible releases
5
- minor = 4 # Compatible, but new features
5
+ minor = 5 # Compatible, but new features
6
6
  patch = 0 # Fixes to existing features
7
7
  [major, minor, patch].map(&:to_s).join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cratus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-04-06 00:00:00.000000000 Z
12
+ date: 2017-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize