Class: Decidim::NotificationsSettingsForm

Inherits:
Form
  • Object
show all
Defined in:
app/forms/decidim/notifications_settings_form.rb

Overview

The form object that handles the data behind updating a user’s notifications settings in her profile page.

Instance Method Summary collapse

Instance Method Details

#direct_message_typesObject



41
42
43
# File 'app/forms/decidim/notifications_settings_form.rb', line 41

def direct_message_types
  allow_public_contact ? "all" : "followed-only"
end

#map_model(user) ⇒ Object



16
17
18
19
20
21
# File 'app/forms/decidim/notifications_settings_form.rb', line 16

def map_model(user)
  self.newsletter_notifications = user.newsletter_notifications_at.present?
  self.notifications_from_followed = ["all", "followed-only"].include? user.notification_types
  self.notifications_from_own_activity = ["all", "own-only"].include? user.notification_types
  self.allow_public_contact = user.direct_message_types == "all"
end

#newsletter_notifications_atObject



23
24
25
26
27
# File 'app/forms/decidim/notifications_settings_form.rb', line 23

def newsletter_notifications_at
  return nil unless newsletter_notifications

  Time.current
end

#notification_typesObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/forms/decidim/notifications_settings_form.rb', line 29

def notification_types
  if notifications_from_followed && notifications_from_own_activity
    "all"
  elsif notifications_from_followed
    "followed-only"
  elsif notifications_from_own_activity
    "own-only"
  else
    "none"
  end
end

#user_is_moderator?(user) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'app/forms/decidim/notifications_settings_form.rb', line 45

def user_is_moderator?(user)
  Decidim.participatory_space_manifests.map do |manifest|
    participatory_space_type = manifest.model_class_name.constantize
    return true if participatory_space_type.moderators(user.organization).exists?(id: user.id)
  end
  false
end