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.29.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.28.4 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.9 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.29.0 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.28.3 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.8 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.29.0.rc4 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.29.0.rc3 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.29.0.rc2 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.29.0.rc1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.28.2 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.7 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.28.1 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.6 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.10 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.26.9 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.28.0 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.27.5 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.28.0.rc5 app/forms/decidim/invite_user_to_group_form.rb
decidim-core-0.28.0.rc4 app/forms/decidim/invite_user_to_group_form.rb