Sha256: fdcb1d5d1ad8cbad8cf150eab5e022eb9b6ffc5034aa212a9c3a3d04a179d98a

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

namespace :adeia do

  desc "Create the elements and a group with all the privileges"
  task permissions: :environment do
    elements =  %w(adeia/permissions adeia/tokens adeia/groups adeia/group_users)
    elements.concat(ENV["elements"].split(",").map { |e| e.strip }) if ENV["elements"].present?
    owner = Adeia::Group.find_or_create_by!(name: "superadmin")
    elements.each do |element|
      Adeia::Permission.find_or_add_by!(owner: owner, element: element, full: true)
    end
  end

  desc "Add an user to the group with all the privileges"
  task superuser: :environment do
    errors = []
    errors << "Please provide an `user_id`: `rake adeia:superuser user_id=1`" unless ENV["user_id"].present?
    group = Adeia::Group.find_by_name("superadmin")
    errors << "Please first run `rake adeia:permissions`" if group.nil?
    if errors.empty?
      Adeia::GroupUser.create!(user_id: ENV["user_id"], adeia_group_id: group.id)
    else
      errors.each { |message| puts message }
    end
  end

  desc "Create groups"
  task groups: :environment do
    groups = ENV["groups"].split(",").map { |e| e.strip } if ENV["groups"].present?
    if groups.present?
      groups.each { |group| Adeia::Group.create!(name: group) }
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
adeia-1.0.0 lib/tasks/init.rake
adeia-0.15.4 lib/tasks/init.rake
adeia-0.15.3 lib/tasks/init.rake
adeia-0.15.2 lib/tasks/init.rake
adeia-0.15.1 lib/tasks/init.rake
adeia-0.15.0 lib/tasks/init.rake
adeia-0.14.0 lib/tasks/init.rake
adeia-0.13.1 lib/tasks/init.rake
adeia-0.13.0 lib/tasks/init.rake