Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# frozen_string_literal: true

class ClientsController < ApplicationController
skip_after_action :verify_authorized, except: :create

def index
authorize :index, policy_class: ClientPolicy
render :index, locals: {
clients:,
new_client: Client.new,
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class ProjectsController < ApplicationController
skip_after_action :verify_authorized

def index
authorize Project
end
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ class RootController < ApplicationController
skip_after_action :verify_authorized

def index
path = if current_user.has_owner_or_admin_role?(current_company)
dashboard_index_path
else
time_tracking_index_path
end

path = current_user.has_role?(:book_keeper, current_company) ? payments_path : time_tracking_index_path
redirect_to path
end
end
2 changes: 1 addition & 1 deletion app/controllers/time_tracking_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class TimeTrackingController < ApplicationController
skip_after_action :verify_authorized

def index
is_admin = current_user.has_owner_or_admin_role?(current_company)
is_admin = current_user.has_role?(:owner, current_company) || current_user.has_role?(:admin, current_company)
user_id = current_user.id
employees = is_admin ? current_company.users.select(:id, :first_name, :last_name) : [current_user]

Expand Down
19 changes: 8 additions & 11 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# frozen_string_literal: true

class Users::SessionsController < Devise::SessionsController
def after_sign_in_path_for(resource)
return new_company_path if resource.companies.empty? && resource.has_role?(:owner)

time_tracking_index_path

# As per discussion we want to redirect all the users to time-tracking page as dashboard is blank.
# if resource.has_owner_or_admin_role?(current_company)
# dashboard_index_path
# else
# time_tracking_index_path
# end
def after_sign_in_path_for(user)
if user.has_role?(:owner) && user.companies.empty?
new_company_path
elsif user.has_role?(:book_keeper, current_company)
payments_path
else
time_tracking_index_path
end
end
end
6 changes: 0 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ def active_for_authentication?
super and self.kept?
end

def has_owner_or_admin_role?(company)
return false if company.nil?

self.has_cached_role?(:owner, company) || self.has_cached_role?(:admin, company)
end

def current_workspace(load_associations: [:logo_attachment])
@_current_workspace ||= Company.includes(load_associations).find_by(id: current_workspace_id)
end
Expand Down
15 changes: 10 additions & 5 deletions app/models/wise_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
#
# Table name: wise_accounts
#
# id :integer not null, primary key
# profile_id :string
# recipient_id :string
# id :bigint not null, primary key
# source_currency :string
# target_currency :string
# user_id :integer not null
# company_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# company_id :bigint not null
# profile_id :string
# recipient_id :string
# user_id :bigint not null
#
# Indexes
#
# index_wise_accounts_on_company_id (company_id)
# index_wise_accounts_on_user_id (user_id)
# index_wise_accounts_on_user_id_and_company_id (user_id,company_id) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (company_id => companies.id)
# fk_rails_... (user_id => users.id)
#

class WiseAccount < ApplicationRecord
belongs_to :user
Expand Down
7 changes: 5 additions & 2 deletions app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
class ApplicationPolicy
attr_reader :user, :record

ROLES = %i[owner admin employee book_keeper]
def initialize(user, record)
@user = user
@record = record
end

def user_owner_or_admin?(resource = user.current_workspace)
user.has_owner_or_admin_role?(resource)
ROLES.each do |role|
define_method "user_#{role}_role?" do |resource = user.current_workspace|
user.has_cached_role?("#{role}".to_sym, resource)
end
end
end
12 changes: 6 additions & 6 deletions app/policies/client_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ class ClientPolicy < ApplicationPolicy
attr_reader :error_message_key

def index?
true
user_employee_role? || user_owner_role? || user_admin_role?
end

def show?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def create?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def new_invoice_line_items?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def update?
Expand All @@ -25,7 +25,7 @@ def update?
return false
end

user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def destroy?
Expand All @@ -34,7 +34,7 @@ def destroy?
return false
end

user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def permitted_attributes
Expand Down
8 changes: 4 additions & 4 deletions app/policies/company_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def create?
end

def show?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def update?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def company_present?
Expand All @@ -33,7 +33,7 @@ def company_present?
end

def users?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def permitted_attributes
Expand All @@ -42,6 +42,6 @@ def permitted_attributes
end

def purge_logo?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
2 changes: 1 addition & 1 deletion app/policies/company_user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class CompanyUserPolicy < ApplicationPolicy
def index?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
2 changes: 1 addition & 1 deletion app/policies/dashboard_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class DashboardPolicy < ApplicationPolicy
def index?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
4 changes: 2 additions & 2 deletions app/policies/generate_invoice_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

class GenerateInvoicePolicy < ApplicationPolicy
def index?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def show?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
14 changes: 7 additions & 7 deletions app/policies/invoice_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

class InvoicePolicy < ApplicationPolicy
def index?
user_owner_or_admin?
user_owner_role? || user_admin_role? || user_book_keeper_role?
end

def create?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def update?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def show?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def destroy?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def edit?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def send_invoice?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def permitted_attributes
Expand Down
2 changes: 1 addition & 1 deletion app/policies/invoices/bulk_deletion_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class Invoices::BulkDeletionPolicy < ApplicationPolicy
def create?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
2 changes: 1 addition & 1 deletion app/policies/payment_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class PaymentPolicy < ApplicationPolicy
def index?
user_owner_or_admin?
user_book_keeper_role? || user_owner_role? || user_admin_role?
end
end
6 changes: 3 additions & 3 deletions app/policies/payment_settings_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

class PaymentSettingsPolicy < ApplicationPolicy
def index?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def connect_stripe?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def refresh_stripe_connect?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
6 changes: 3 additions & 3 deletions app/policies/payments/provider_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

class Payments::ProviderPolicy < ApplicationPolicy
def index?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def create?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def update?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
2 changes: 1 addition & 1 deletion app/policies/project_member_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class ProjectMemberPolicy < ApplicationPolicy
def update?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
10 changes: 5 additions & 5 deletions app/policies/project_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ class ProjectPolicy < ApplicationPolicy
attr_reader :error_message_key

def index?
true
user_owner_role? || user_admin_role? || user_employee_role?
end

def show?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def create?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def update?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def destroy?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def permitted_attributes
Expand Down
4 changes: 2 additions & 2 deletions app/policies/report_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

class ReportPolicy < ApplicationPolicy
def index?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end

def download?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
2 changes: 1 addition & 1 deletion app/policies/subscriptions_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class SubscriptionsPolicy < ApplicationPolicy
def index?
user_owner_or_admin?
user_owner_role? || user_admin_role?
end
end
Loading