Sha256: f50e11e01dc2bb04e1152428096ce7c4a3556f4e2f3b4da01d425b28885700f4

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Decidim
  module Assemblies
    module Admin
      # A form object used to create assembly user roles from the admin dashboard.
      #
      class AssemblyUserRoleForm < Form
        mimic :assembly_user_role

        attribute :name, String
        attribute :email, String
        attribute :role, String

        validates :name, :email, :role, presence: true
        validates :role, inclusion: { in: Decidim::AssemblyUserRole::ROLES }

        validates :name, format: { with: UserBaseEntity::REGEXP_NAME }
        validate :admin_uniqueness

        def roles
          Decidim::AssemblyUserRole::ROLES.map do |role|
            [
              I18n.t(role, scope: "decidim.admin.models.assembly_user_role.roles"),
              role
            ]
          end
        end

        def admin_uniqueness
          errors.add(:email, :taken) if context && context.current_organization && context.current_organization.admins.where(email: email).exists?
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-assemblies-0.23.1 app/forms/decidim/assemblies/admin/assembly_user_role_form.rb
decidim-assemblies-0.23.1.rc1 app/forms/decidim/assemblies/admin/assembly_user_role_form.rb
decidim-assemblies-0.23.0 app/forms/decidim/assemblies/admin/assembly_user_role_form.rb