Skip to content

Instantly share code, notes, and snippets.

@philiplambok
Last active June 25, 2020 04:33
Show Gist options
  • Select an option

  • Save philiplambok/8ac0b3ba0641c7688f128fd6f37f5436 to your computer and use it in GitHub Desktop.

Select an option

Save philiplambok/8ac0b3ba0641c7688f128fd6f37f5436 to your computer and use it in GitHub Desktop.
fix-fix-spec
module Web
module JurnalPay
module Authenticable
extend ActiveSupport::Concern
included do
helper_method :current_jurnal_user
def require_authentication
access_token = params[:access_token] || session[:jurnal_pay_access_token]
find_user = FindUserForJurnalPay.new(access_token)
find_user.call
raise Errors::Forbidden if find_user.allowed_user.blank?
@current_jurnal_user = find_user.allowed_user
@current_jurnal_user.access_token = access_token
session[:jurnal_pay_access_token] = @current_jurnal_user.access_token
end
def current_jurnal_user
@current_jurnal_user
end
end
end
end
end
class Jurnal
module V2
module Model
class User
OWNER_ROLE_EN = 'owner'.freeze
OWNER_ROLE_ID = 'pemilik'.freeze
ULTIMATE_ROLE = 'ultimate'.freeze
ACCOUNTANT_ROLE_EN = 'accountant'.freeze
ACCOUNTANT_ROLE_ID = 'akuntan'.freeze
include ActiveModel::Model
attr_accessor :id,
:name,
:email,
:status,
:source,
:registered_at,
:view_link,
:ktp_info,
:model_name,
:is_owner,
:roles,
:active_company,
:access_token
def owner_role?
return false if roles.blank?
roles.downcase.include?(OWNER_ROLE_EN) || roles.downcase.include?(OWNER_ROLE_ID)
end
def ultimate_role?
return false if roles.blank?
roles.downcase.include?(ULTIMATE_ROLE)
end
def accountant_role?
return false if roles.blank?
roles.downcase.include?(ACCOUNTANT_ROLE_EN) || roles.downcase.include?(ACCOUNTANT_ROLE_ID)
end
def jurnal_pay_allowed_role?
owner_role? || ultimate_role? || accountant_role?
end
def jurnal_pay_not_allowed_role?
jurnal_pay_allowed_role?.eql?(false)
end
end
end
end
end
module Web
module JurnalPay
class WelcomesController < Web::JurnalPay::BaseController
before_action :require_authentication
def index
redirect_to jurnal_pay_dashboards_path if already_registered?(current_jurnal_user)
end
private
def already_registered?(jurnal_user)
find_user = FindUserForJurnalPay.new(jurnal_user.access_token)
find_user.call
find_user.already_registered?
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment