Sha256: 8c72902325109843543d702b67c3811dee664c8cd5cc5bd6f7c64b4d930d9e9d

Contents?: true

Size: 752 Bytes

Versions: 6

Compression:

Stored size: 752 Bytes

Contents

module Curupira::RelationshipSelectOptionsHelper
  def active_user_groups_select_options(user)
      [["Selecione um grupo", nil]] + groups_by(user).map { |g| [g.name, g.id] }
  end

  def active_features_select_options
    [["Selecione uma funcionalidade", nil]] + Feature.all.map { |f| [f.name, f.id] }
  end

  def active_roles_select_options
    [["Selecione um perfil", nil]] + Role.all.map { |r| [r.name, r.id] }
  end

  def active_role_groups_select_options(group)
    [["Selecione um perfil", nil]] + Role.joins(:groups).where(groups:{id:group}).map { |r| [r.name, r.id] }
  end

  private 

  def groups_by(user)
    if user.admin
      Group.all
    else
      Group.joins(:users).where(users: { id: user }, active: true)
    end 
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
curupira-0.1.7 app/helpers/curupira/relationship_select_options_helper.rb
curupira-0.1.6 app/helpers/curupira/relationship_select_options_helper.rb
curupira-0.1.4 app/helpers/curupira/relationship_select_options_helper.rb
curupira-0.1.3 app/helpers/curupira/relationship_select_options_helper.rb
curupira-0.1.2 app/helpers/curupira/relationship_select_options_helper.rb
curupira-0.1.1 app/helpers/curupira/relationship_select_options_helper.rb