Class: GoodData::Membership
- Inherits:
-
Rest::Resource
- Object
- Rest::Object
- Rest::Resource
- GoodData::Membership
- Defined in:
- lib/gooddata/models/membership.rb
Constant Summary collapse
- ASSIGNABLE_MEMBERS =
[ :email, :first_name, :last_name, :login, :phone, :status, :title ]
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Attributes inherited from Rest::Object
Class Method Summary collapse
-
.create(data, options = { client: GoodData.connection }) ⇒ GoodData::User
Apply changes to object.
- .diff_list(list1, list2) ⇒ Object
Instance Method Summary collapse
-
#!=(other) ⇒ Boolean
Checks objects for non-equality.
-
#==(other) ⇒ Boolean
Checks objects for equality.
- #content ⇒ Object
-
#contributor ⇒ String
Gets the contributor.
-
#created ⇒ DateTime
Gets date when created.
- #data ⇒ Object
-
#deleted? ⇒ Boolean
Is the member deleted?.
-
#diff(user) ⇒ Hash
Gets hash representing diff of users.
-
#disable ⇒ GoodData::Membership
Disables membership.
-
#disabled? ⇒ Boolean
Is the member enabled?.
-
#email ⇒ String
Gets the email.
-
#email=(new_email) ⇒ Object
Sets the email.
-
#enable ⇒ GoodData::Membership
Enables membership.
-
#enabled? ⇒ Boolean
Is the member enabled?.
-
#first_name ⇒ String
Gets the first name.
-
#first_name=(new_first_name) ⇒ Object
Sets the first name.
-
#full_name ⇒ Object
Get full name.
-
#initialize(json) ⇒ Membership
constructor
A new instance of Membership.
-
#invitations ⇒ Array<GoodData::Invitation>
Gets the invitations.
-
#last_name ⇒ String
Gets the last name.
-
#last_name=(new_last_name) ⇒ Object
Sets the last name.
- #links ⇒ Object
-
#login ⇒ String
Gets the login.
-
#login=(new_login) ⇒ Object
Sets the last name.
- #meta ⇒ Object
- #name ⇒ Object
-
#obj_id ⇒ String
Gets user raw object ID.
-
#permissions ⇒ Hash
Gets the permissions.
-
#phone ⇒ String
Gets the phone number.
-
#phone=(new_phone_number) ⇒ Object
Sets the phone number.
-
#profile ⇒ Object
Gets profile of this membership.
-
#profile_url ⇒ Object
Gets URL of profile membership.
-
#project_id ⇒ Object
Gets project id.
-
#project_url ⇒ Object
Gets project url.
-
#projects ⇒ Array<GoodData::Project>
Gets the projects of user.
-
#role ⇒ GoodData::ProjectRole
Gets first role.
-
#roles ⇒ Array<GoodData::ProjectRole>
Gets the project roles of user.
-
#status ⇒ String
Gets the status.
-
#title ⇒ String
Gets the title.
-
#title=(new_title) ⇒ Object
Sets the title.
- #to_hash ⇒ Object
-
#updated ⇒ DateTime
Gets the date when updated.
-
#uri ⇒ String
Gets the object URI.
- #user_groups ⇒ Object
Methods inherited from Rest::Object
client, default_client, #saved?
Methods included from GoodData::Mixin::DataPropertyReader
Methods included from GoodData::Mixin::DataPropertyWriter
Methods included from GoodData::Mixin::MetaPropertyReader
Methods included from GoodData::Mixin::MetaPropertyWriter
Methods included from GoodData::Mixin::RootKeyGetter
Constructor Details
#initialize(json) ⇒ Membership
Returns a new instance of Membership.
71 72 73 |
# File 'lib/gooddata/models/membership.rb', line 71 def initialize(json) @json = json end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
18 19 20 |
# File 'lib/gooddata/models/membership.rb', line 18 def json @json end |
Class Method Details
.create(data, options = { client: GoodData.connection }) ⇒ GoodData::User
Apply changes to object.
def apply(obj, changes) changes.each do |param, val| next unless ASSIGNABLE_MEMBERS.include? param obj.send("#param=", val) end obj end
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gooddata/models/membership.rb', line 43 def create(data, = { client: GoodData.connection }) c = client() json = { 'user' => { 'content' => { 'email' => data[:email] || data[:login], 'login' => data[:login], 'firstname' => data[:first_name], 'lastname' => data[:last_name], 'userRoles' => ['editor'], 'password' => data[:password], 'domain' => data[:domain], # And following lines are even much more ugly hack # 'authentication_modes' => ['sso', 'password'] }, 'links' => {}, 'meta' => {} } } json['user']['links']['self'] = data[:uri] if data[:uri] c.create(self, json) end |
Instance Method Details
#!=(other) ⇒ Boolean
Checks objects for non-equality
95 96 97 |
# File 'lib/gooddata/models/membership.rb', line 95 def !=(other) !(self == other) end |
#==(other) ⇒ Boolean
Checks objects for equality
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gooddata/models/membership.rb', line 79 def ==(other) return false unless other.respond_to?(:to_hash) to_hash == other.to_hash # res = true # ASSIGNABLE_MEMBERS.each do |k| # l_val = send("#{k}") # r_val = other.send("#{k}") # res = false if l_val != r_val # end # res end |
#content ⇒ Object
394 395 396 |
# File 'lib/gooddata/models/membership.rb', line 394 def content data['content'] || {} end |
#contributor ⇒ String
Gets the contributor
110 111 112 113 114 |
# File 'lib/gooddata/models/membership.rb', line 110 def contributor url = @json['user']['meta']['contributor'] data = client.get url client.create(GoodData::Membership, data) end |
#created ⇒ DateTime
Gets date when created
119 120 121 |
# File 'lib/gooddata/models/membership.rb', line 119 def created Time.parse(@json['user']['meta']['created']) end |
#data ⇒ Object
377 378 379 380 |
# File 'lib/gooddata/models/membership.rb', line 377 def data data = @json || {} data['user'] || {} end |
#deleted? ⇒ Boolean
Is the member deleted?
126 127 128 |
# File 'lib/gooddata/models/membership.rb', line 126 def deleted? !(login =~ /^deleted-/).nil? end |
#diff(user) ⇒ Hash
Gets hash representing diff of users
134 135 136 |
# File 'lib/gooddata/models/membership.rb', line 134 def diff(user) GoodData::User.diff(self, user) end |
#disable ⇒ GoodData::Membership
Disables membership
365 366 367 368 |
# File 'lib/gooddata/models/membership.rb', line 365 def disable self.status = 'DISABLED' self end |
#disabled? ⇒ Boolean
Is the member enabled?
373 374 375 |
# File 'lib/gooddata/models/membership.rb', line 373 def disabled? !enabled? end |
#email ⇒ String
Gets the email
141 142 143 |
# File 'lib/gooddata/models/membership.rb', line 141 def email @json['user']['content']['email'] || '' end |
#email=(new_email) ⇒ Object
Sets the email
148 149 150 |
# File 'lib/gooddata/models/membership.rb', line 148 def email=(new_email) @json['user']['content']['email'] = new_email end |
#enable ⇒ GoodData::Membership
Enables membership
350 351 352 353 |
# File 'lib/gooddata/models/membership.rb', line 350 def enable self.status = 'ENABLED' self end |
#enabled? ⇒ Boolean
Is the member enabled?
358 359 360 |
# File 'lib/gooddata/models/membership.rb', line 358 def enabled? status == 'ENABLED' end |
#first_name ⇒ String
Gets the first name
155 156 157 |
# File 'lib/gooddata/models/membership.rb', line 155 def first_name @json['user']['content']['firstname'] || '' end |
#first_name=(new_first_name) ⇒ Object
Sets the first name
162 163 164 |
# File 'lib/gooddata/models/membership.rb', line 162 def first_name=(new_first_name) @json['user']['content']['firstname'] = new_first_name end |
#full_name ⇒ Object
Get full name
NOTE: This can be tricky to implement correctly for i18n
170 171 172 |
# File 'lib/gooddata/models/membership.rb', line 170 def full_name "#{first_name} #{last_name}" end |
#invitations ⇒ Array<GoodData::Invitation>
Gets the invitations
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/gooddata/models/membership.rb', line 177 def invitations res = [] tmp = client.get @json['user']['links']['invitations'] tmp['invitations'].each do |_invitation| # TODO: Something is missing here end res end |
#last_name ⇒ String
Gets the last name
191 192 193 |
# File 'lib/gooddata/models/membership.rb', line 191 def last_name @json['user']['content']['lastname'] || '' end |
#last_name=(new_last_name) ⇒ Object
Sets the last name
198 199 200 |
# File 'lib/gooddata/models/membership.rb', line 198 def last_name=(new_last_name) @json['user']['content']['lastname'] = new_last_name end |
#links ⇒ Object
390 391 392 |
# File 'lib/gooddata/models/membership.rb', line 390 def links data['links'] || {} end |
#login ⇒ String
Gets the login
205 206 207 |
# File 'lib/gooddata/models/membership.rb', line 205 def login @json['user']['content']['login'] || '' end |
#login=(new_login) ⇒ Object
Sets the last name
212 213 214 |
# File 'lib/gooddata/models/membership.rb', line 212 def login=(new_login) @json['user']['content']['login'] = new_login end |
#meta ⇒ Object
386 387 388 |
# File 'lib/gooddata/models/membership.rb', line 386 def data['meta'] || {} end |
#name ⇒ Object
382 383 384 |
# File 'lib/gooddata/models/membership.rb', line 382 def name (first_name || '') + (last_name || '') end |
#obj_id ⇒ String
Gets user raw object ID
219 220 221 |
# File 'lib/gooddata/models/membership.rb', line 219 def obj_id uri.split('/').last end |
#permissions ⇒ Hash
Gets the permissions
226 227 228 229 230 231 232 233 234 235 |
# File 'lib/gooddata/models/membership.rb', line 226 def res = {} tmp = client.get @json['user']['links']['permissions'] tmp['associatedPermissions']['permissions'].each do |, | res[] = end res end |
#phone ⇒ String
Gets the phone number
240 241 242 |
# File 'lib/gooddata/models/membership.rb', line 240 def phone @json['user']['content']['phonenumber'] || '' end |
#phone=(new_phone_number) ⇒ Object
Sets the phone number
247 248 249 |
# File 'lib/gooddata/models/membership.rb', line 247 def phone=(new_phone_number) @json['user']['content']['phonenumber'] = new_phone_number end |
#profile ⇒ Object
Gets profile of this membership
252 253 254 255 |
# File 'lib/gooddata/models/membership.rb', line 252 def profile raw = client.get @json['user']['links']['self'] client.create(GoodData::Profile, raw) end |
#profile_url ⇒ Object
Gets URL of profile membership
258 259 260 |
# File 'lib/gooddata/models/membership.rb', line 258 def profile_url @json['user']['links']['self'] end |
#project_id ⇒ Object
Gets project id
269 270 271 |
# File 'lib/gooddata/models/membership.rb', line 269 def project_id @json['user']['links']['roles'].split('/')[3] end |
#project_url ⇒ Object
Gets project url
274 275 276 |
# File 'lib/gooddata/models/membership.rb', line 274 def project_url @json['user']['links']['roles'].split('/')[0..3].join('/') end |
#projects ⇒ Array<GoodData::Project>
Gets the projects of user
281 282 283 284 285 286 287 288 |
# File 'lib/gooddata/models/membership.rb', line 281 def projects tmp = client.get @json['user']['links']['projects'] tmp['projects'].map do || project_uri = ['project']['links']['self'] project = client.get project_uri client.create(GoodData::Project, project) end end |
#role ⇒ GoodData::ProjectRole
Gets first role
293 294 295 |
# File 'lib/gooddata/models/membership.rb', line 293 def role roles && roles.first end |
#roles ⇒ Array<GoodData::ProjectRole>
Gets the project roles of user
300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/gooddata/models/membership.rb', line 300 def roles # TODO: Implement getting roles in project and cache them there # See: https://jira.intgdc.com/browse/TMA-112 roles_link = GoodData::Helpers.get_path(@json, %w(user links roles)) return unless roles_link tmp = client.get roles_link tmp['associatedRoles']['roles'].pmap do |role_uri| role = client.get role_uri client.create(GoodData::ProjectRole, role) end end |
#status ⇒ String
Gets the status
315 316 317 |
# File 'lib/gooddata/models/membership.rb', line 315 def status @json['user']['content']['status'] || '' end |
#title ⇒ String
Gets the title
322 323 324 |
# File 'lib/gooddata/models/membership.rb', line 322 def title @json['user']['meta']['title'] || '' end |
#title=(new_title) ⇒ Object
Sets the title
329 330 331 |
# File 'lib/gooddata/models/membership.rb', line 329 def title=(new_title) @json['user']['content']['title'] = new_title end |
#to_hash ⇒ Object
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/gooddata/models/membership.rb', line 398 def to_hash tmp = GoodData::Helpers.symbolize_keys(content.merge().merge('uri' => uri)) [ [:userRoles, :role], [:companyName, :company_name], [:phoneNumber, :phone_number], [:firstname, :first_name], [:lastname, :last_name], [:authenticationModes, :authentication_modes] ].each do |vals| wire, rb = vals tmp[rb] = tmp[wire] tmp.delete(wire) end tmp end |
#updated ⇒ DateTime
Gets the date when updated
336 337 338 |
# File 'lib/gooddata/models/membership.rb', line 336 def updated DateTime.parse(@json['user']['meta']['updated']) end |
#uri ⇒ String
Gets the object URI
343 344 345 |
# File 'lib/gooddata/models/membership.rb', line 343 def uri links['self'] end |
#user_groups ⇒ Object
415 416 417 |
# File 'lib/gooddata/models/membership.rb', line 415 def user_groups project.user_groups(:all, user: obj_id) end |