Sha256: c060ea590015a1decc23aaad9003a4bc3e7763a3cccd23ee73c5975b20b8fd83

Contents?: true

Size: 1.36 KB

Versions: 13

Compression:

Stored size: 1.36 KB

Contents

module ThinkFeelDoDashboard
  module Concerns
    # Validations and association integrity for Participants in social Arms.
    module SocialParticipant
      extend ActiveSupport::Concern

      included do
        before_validation :ensure_display_name
        before_validation :prevent_is_admin_update, on: :update
        before_destroy :admin_is_not_destroyable?

        has_many :social_networking_shared_items,
                 class_name: "SocialNetworking::SharedItem",
                 dependent: :destroy

        has_many :social_networking_profiles,
                 class_name: "SocialNetworking::Profile",
                 dependent: :destroy
      end

      private

      def prevent_is_admin_update
        if changed.include?("is_admin")
          errors.add(
            :is_admin,
            "can't be updated."
          )
        end
      end

      def admin_is_not_destroyable?
        if is_admin
          errors.add(
            :is_admin,
            "can't be destroyed."
          )
          false
        end
      end

      def ensure_display_name
        if active_membership &&
           active_group.arm.social? &&
           display_name.blank?
          errors.add(
            :display_name,
            "is required because the arm of this intervention utilizes " \
            "social features."
          )
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
think_feel_do_dashboard-1.2.0.beta1 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.21 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.20 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.19 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.18 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.17 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.16 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.15 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.14 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.13 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.12 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.11 app/models/think_feel_do_dashboard/concerns/social_participant.rb
think_feel_do_dashboard-1.1.10 app/models/think_feel_do_dashboard/concerns/social_participant.rb