Sha256: 10eb3b0bb9d029118777dcef24ad677e21d1050472e87c00a0b278d7d7e97c3e

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 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)
    elements.concat(ENV["elements"].split(",")) if ENV["elements"].present?
    owner = Adeia::Group.find_or_create_by!(name: "superadmin")
    elements.each do |element|
      element = Adeia::Element.find_or_create_by!(name: element)
      Adeia::Permission.find_or_create_by!(adeia_element_id: element.id, owner_id: owner.id, owner_type: "Adeia::Group",
       permission_type: "all_entries", read_right: true, create_right: true, update_right: true, destroy_right: 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

8 entries across 8 versions & 1 rubygems

Version Path
adeia-0.8.1 lib/tasks/init.rake
adeia-0.8.0 lib/tasks/init.rake
adeia-0.7.1 lib/tasks/init.rake
adeia-0.7.0 lib/tasks/init.rake
adeia-0.6.2 lib/tasks/init.rake
adeia-0.6.1 lib/tasks/init.rake
adeia-0.6.0 lib/tasks/init.rake
adeia-0.5.6 lib/tasks/init.rake