Create system access levels

Asked

Viewed 398 times

-2

Guys, this question starts from scratch. I want to know how to determine system access rules where there are 3 types of profiles: general administrator, local administrator and maintainer, where there are different rules for profiles.

I would like to know how to register users in proper profiles and how to give permissions to them on a page!

  • 1

    This question seems to me too wide. And besides, you need to have at least one basis for us to be able to base ourselves here (for an eventual answer). From scratch it’s hard to help :D

  • Take a look at this response question.

1 answer

1


As you are using Rails, you can create these rules in Backend using Cancancan.

Read the documentation for installation and configuration. All access rules are carried out in the file ability.rb, for your case your setting would look something like this:

class Ability
  include CanCan::Ability

  def initialize(usuario)
    usuario ||= Usuario.new 

    if usuario.administrador_geral?
      can :manage, :all
    end
    if usuario.administrador_local?
      can :manage, LocalModelOne
      can :manage, LocalModelTwo
    end

    if usuario.mantenedor?
      can :manage, RestrictModelOne
      can :manage, RestrictModelTwo
      can :read, VeryRestrictModelOne
    end


  end
end

Well, I put up some fake rules just to give you an idea of the structure, but you’ll make up your own rules.

The methods administrador_geral?, administrador_local? and mantenedor? are verification methods you will create in your model Usuario, for example

def mantenedor?
  usuario.tipo == MANTENEDOR_TIPO 
end

Only one way it can be done, but as your question is very open, there is no way to give a closed solution, good luck.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.