Sha256: f7ffe6eb477285e0293e5285551d77de25040209e8349655b5184f34b0168f1f

Contents?: true

Size: 993 Bytes

Versions: 15

Compression:

Stored size: 993 Bytes

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)
    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

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
adeia-0.11.0 lib/tasks/init.rake
adeia-0.10.5 lib/tasks/init.rake
adeia-0.10.4 lib/tasks/init.rake
adeia-0.10.3 lib/tasks/init.rake
adeia-0.10.2 lib/tasks/init.rake
adeia-0.10.1 lib/tasks/init.rake
adeia-0.10.0 lib/tasks/init.rake
adeia-0.9.2 lib/tasks/init.rake
adeia-0.9.1 lib/tasks/init.rake
adeia-0.9.0 lib/tasks/init.rake
adeia-0.8.6 lib/tasks/init.rake
adeia-0.8.5 lib/tasks/init.rake
adeia-0.8.4 lib/tasks/init.rake
adeia-0.8.3 lib/tasks/init.rake
adeia-0.8.2 lib/tasks/init.rake