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.26.8 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.4 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.3 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.7 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.5 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.2 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.4 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.0 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.3 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.0.rc2 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.0.rc1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.2 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.0 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.0.rc2 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.0.rc1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.25.2 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.25.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.25.0 app/forms/decidim/invite_user_to_group_form.rb