app/models/concerns/memberships/base.rb in bullet_train-1.2.27 vs app/models/concerns/memberships/base.rb in bullet_train-1.3.0

- old
+ new

@@ -1,9 +1,11 @@ module Memberships::Base extend ActiveSupport::Concern included do + attr_accessor :user_profile_photo_removal + # See `docs/permissions.md` for details. include Roles::Support belongs_to :user, optional: true belongs_to :team @@ -14,19 +16,24 @@ has_many :scaffolding_completely_concrete_tangible_things_assignments, class_name: "Scaffolding::CompletelyConcrete::TangibleThings::Assignment", dependent: :destroy has_many :scaffolding_completely_concrete_tangible_things, through: :scaffolding_completely_concrete_tangible_things_assignments, source: :tangible_thing has_many :scaffolding_absolutely_abstract_creative_concepts_collaborators, class_name: "Scaffolding::AbsolutelyAbstract::CreativeConcepts::Collaborator", dependent: :destroy + # Image uploading + has_one_attached :user_profile_photo + after_destroy do # if we're destroying a user's membership to the team they have set as # current, then we need to remove that so they don't get an error. if user&.current_team == team user.current_team = nil user.save end end + after_validation :remove_user_profile_photo, if: :user_profile_photo_removal? + scope :excluding_platform_agents, -> { where(platform_agent_of: nil) } scope :platform_agents, -> { where.not(platform_agent_of: nil) } scope :current_and_invited, -> { includes(:invitation).where("user_id IS NOT NULL OR invitations.id IS NOT NULL").references(:invitation) } scope :current, -> { where("user_id IS NOT NULL") } scope :tombstones, -> { includes(:invitation).where("user_id IS NULL AND invitations.id IS NULL AND platform_agent IS FALSE").references(:invitation) } @@ -138,6 +145,16 @@ # TODO utilize this. # members shouldn't receive notifications unless they are either an active user or an outstanding invitation. def should_receive_notifications? invitation.present? || user.present? end + + def user_profile_photo_removal? + user_profile_photo_removal.present? + end + + def remove_user_profile_photo + user_profile_photo.purge + end + + ActiveSupport.run_load_hooks :bullet_train_memberships_base, self end