chore: Custom Roles to manage permissions [ UI ] (#9865)
In admin settings, this Pr will add the UI for managing custom roles ( ref: https://github.com/chatwoot/chatwoot/pull/9995 ). It also handles the routing logic changes to accommodate fine-tuned permissions. --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
module Enterprise::Api::V1::Accounts::AgentsController
|
||||
def account_user_attributes
|
||||
super + [:custom_role_id]
|
||||
def create
|
||||
super
|
||||
associate_agent_with_custom_role
|
||||
end
|
||||
|
||||
def allowed_agent_params
|
||||
super + [:custom_role_id]
|
||||
def update
|
||||
super
|
||||
associate_agent_with_custom_role
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def associate_agent_with_custom_role
|
||||
@agent.current_account_user.update!(custom_role_id: params[:custom_role_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
module Enterprise::Api::V2::Accounts::ReportsController
|
||||
def check_authorization
|
||||
return if Current.account_user.custom_role&.permissions&.include?('report_manage')
|
||||
|
||||
super
|
||||
end
|
||||
end
|
||||
29
enterprise/app/policies/enterprise/article_policy.rb
Normal file
29
enterprise/app/policies/enterprise/article_policy.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
module Enterprise::ArticlePolicy
|
||||
def index?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def update?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def show?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def edit?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def create?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def destroy?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def reorder?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
end
|
||||
25
enterprise/app/policies/enterprise/category_policy.rb
Normal file
25
enterprise/app/policies/enterprise/category_policy.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Enterprise::CategoryPolicy
|
||||
def index?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def update?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def show?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def edit?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def create?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def destroy?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
end
|
||||
33
enterprise/app/policies/enterprise/portal_policy.rb
Normal file
33
enterprise/app/policies/enterprise/portal_policy.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
module Enterprise::PortalPolicy
|
||||
def index?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def update?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def show?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def edit?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def create?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def destroy?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def add_members?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
|
||||
def logo?
|
||||
@account_user.custom_role&.permissions&.include?('knowledge_base_manage') || super
|
||||
end
|
||||
end
|
||||
5
enterprise/app/policies/enterprise/report_policy.rb
Normal file
5
enterprise/app/policies/enterprise/report_policy.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module Enterprise::ReportPolicy
|
||||
def view?
|
||||
@account_user.custom_role&.permissions&.include?('report_manage') || super
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
json.custom_role_id account_user&.custom_role_id
|
||||
json.custom_role account_user&.custom_role&.as_json(only: [:id, :name, :description, :permissions])
|
||||
Reference in New Issue
Block a user