Sha256: 35656464fcd04783ff2d2aca5a680d8524b99044e5d4a7b92b448fc7c9d1c574

Contents?: true

Size: 584 Bytes

Versions: 74

Compression:

Stored size: 584 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # The form object that handles the data behind creating a user group.
  class InviteUserToGroupForm < Form
    mimic :invite

    attribute :nickname, String

    validates :nickname, presence: true
    validate :user_exists

    def user
      @user ||= Decidim::User.find_by(nickname: clean_nickname, organization: current_organization)
    end

    private

    def clean_nickname
      nickname.to_s.tr("@", "")
    end

    def user_exists
      return true if user.present?

      errors.add :nickname, :invalid
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
decidim-core-0.20.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.20.0 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.19.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.18.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.19.0 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.17.2 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.18.0 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.17.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.16.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.17.0 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.16.0 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.15.2 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.15.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.15.0 app/forms/decidim/invite_user_to_group_form.rb