Class: Credentials::Builder::ExternalSources::Child
- Inherits:
-
Base
- Object
- Base
- Credentials::Builder::ExternalSources::Child
- Defined in:
- app/services/credentials/builder/external_sources/child.rb
Instance Method Summary collapse
-
#changeable_for(type) ⇒ Object
private
Checks if specific credential changed by user or by external_source.
-
#child_user_updatable_for?(credential) ⇒ Boolean
private
Checks if specific student credential could be updated.
-
#performable_credential?(credential, type) ⇒ Boolean
private
Checks if specific credential could be updated.
-
#update_or_create_credential(object, type, value) ⇒ Object
private
Updates or creates credential for specific object.
Instance Method Details
#changeable_for(type) ⇒ Object (private)
Checks if specific credential changed by user or by external_source
14 15 16 17 |
# File 'app/services/credentials/builder/external_sources/child.rb', line 14 def changeable_for(type) previous_credential = send("external_source_#{type}_previous") previous_credential.blank? || child_credentials.public_send(type).first&.credential == previous_credential end |
#child_user_updatable_for?(credential) ⇒ Boolean (private)
Checks if specific student credential could be updated. Student should exists Student should be invitee or suspended or connected to SIS with active users update enabled Credential should not be taken by another User
65 66 67 68 69 |
# File 'app/services/credentials/builder/external_sources/child.rb', line 65 def child_user_updatable_for?(credential) child_user.present? && (child_user.invitee? || child_user.suspended? || sis_connector&.update_active_users?) && !exists_by_credential?(credential) end |
#performable_credential?(credential, type) ⇒ Boolean (private)
Checks if specific credential could be updated.
42 43 44 45 46 47 |
# File 'app/services/credentials/builder/external_sources/child.rb', line 42 def performable_credential?(credential, type) child_performable = credential.present? && changeable_for(type) student_performable = child_performable && child_user_updatable_for?(credential) child_performable && (child_user.blank? || student_performable) end |
#update_or_create_credential(object, type, value) ⇒ Object (private)
Updates or creates credential for specific object
76 77 78 79 80 81 82 83 |
# File 'app/services/credentials/builder/external_sources/child.rb', line 76 def update_or_create_credential(object, type, value) scope = object.is_a?(Child) ? :child_credentials : :user_credentials credential = object.public_send(scope).public_send(type).take return process_credential_update(credential, value) if credential.present? object.update("#{scope}_attributes": [{ credential: value }]) end |