From 7a13dffc9b29e89525b9a6e37a38714d53fa9993 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 23 Mar 2023 17:21:05 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20establecer=20un=20par=C3=A1metro=20por?= =?UTF-8?q?=20defecto=20#12754?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/usuaries_controller.rb | 12 ++++++------ app/models/rol.rb | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index 6d02a35a..746ee822 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -72,6 +72,8 @@ class UsuariesController < ApplicationController site_usuarie = SiteUsuarie.new(@site, current_usuarie) authorize site_usuarie + params[:invite_as] = invited_as :invite_as + @policy = policy(site_usuarie) end @@ -155,12 +157,10 @@ class UsuariesController < ApplicationController # El tipo de invitación que tenemos que enviar, si alguien mandó # cualquier cosa, usamos el privilegio menor. - def invited_as - if Rol::ROLES.include?(params[:invited_as]) - params[:invited_as] - else - 'invitade' - end + # + # @return [String] + def invited_as(param_key = :invited_as) + Rol.role?(params[param_key]) ? params[param_key] : Rol::INVITADE end def site diff --git a/app/models/rol.rb b/app/models/rol.rb index 5879d666..fcd07037 100644 --- a/app/models/rol.rb +++ b/app/models/rol.rb @@ -21,4 +21,8 @@ class Rol < ApplicationRecord def usuarie? rol == USUARIE end + + def self.role?(rol) + ROLES.include? rol + end end