Sha256: 2745db2c69e29e7cb201d69547f0e1e1dfc3b74b7b3d36f884a690c9adf62878

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Decidim
  # The form object that handles the data behind updating a user's
  # notifications settings in her profile page.
  class NotificationsSettingsForm < Form
    mimic :user

    attribute :email_on_notification, Boolean
    attribute :newsletter_notifications, Boolean
    attribute :notifications_from_followed, Boolean
    attribute :notifications_from_own_activity, Boolean

    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
    end

    def newsletter_notifications_at
      return nil unless newsletter_notifications
      Time.current
    end

    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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-core-0.18.1 app/forms/decidim/notifications_settings_form.rb
decidim-core-0.17.2 app/forms/decidim/notifications_settings_form.rb
decidim-core-0.18.0 app/forms/decidim/notifications_settings_form.rb
decidim-core-0.17.1 app/forms/decidim/notifications_settings_form.rb
decidim-core-0.16.1 app/forms/decidim/notifications_settings_form.rb
decidim-core-0.17.0 app/forms/decidim/notifications_settings_form.rb
decidim-core-0.16.0 app/forms/decidim/notifications_settings_form.rb