feat(finance-permissions): implement permission checks for finance data editing

- Added permission checks for editing finance data, including fixed costs and rate cards.
- Introduced utility functions to determine user permissions based on roles (admin, project manager).
- Updated finance and rate card components to conditionally render UI elements based on user permissions.
- Displayed alerts for users with limited access to inform them of their editing capabilities.
This commit is contained in:
chamikaJ
2025-05-30 16:26:16 +05:30
parent aeed75ca31
commit 6a4bf4d672
4 changed files with 145 additions and 28 deletions

View File

@@ -0,0 +1,58 @@
import { ILocalSession } from '@/types/auth/local-session.types';
import { IProjectViewModel } from '@/types/project/projectViewModel.types';
/**
* Checks if the current user has permission to edit finance data
* Only users with project admin, admin or owner roles should be able to:
* - Change fixed cost values
* - Add members to rate cards
* - Change rate per hour values
*/
export const hasFinanceEditPermission = (
currentSession: ILocalSession | null,
currentProject?: IProjectViewModel | null
): boolean => {
if (!currentSession) return false;
// Team owner or admin always have permission
if (currentSession.owner || currentSession.is_admin) {
return true;
}
// Project manager has permission
if (currentProject?.project_manager?.id === currentSession.team_member_id) {
return true;
}
return false;
};
/**
* Checks if the current user can edit fixed costs
*/
export const canEditFixedCost = (
currentSession: ILocalSession | null,
currentProject?: IProjectViewModel | null
): boolean => {
return hasFinanceEditPermission(currentSession, currentProject);
};
/**
* Checks if the current user can edit rate card data
*/
export const canEditRateCard = (
currentSession: ILocalSession | null,
currentProject?: IProjectViewModel | null
): boolean => {
return hasFinanceEditPermission(currentSession, currentProject);
};
/**
* Checks if the current user can add members to rate cards
*/
export const canAddMembersToRateCard = (
currentSession: ILocalSession | null,
currentProject?: IProjectViewModel | null
): boolean => {
return hasFinanceEditPermission(currentSession, currentProject);
};