refactor(auth): centralize role checks into utility
Removed direct user role string checks and replaced with type-safe utils.
This commit is contained in:
@@ -17,7 +17,7 @@ const banError = ref('')
|
||||
const roleError = ref('')
|
||||
const pendingBanUser = ref<any | null>(null)
|
||||
const isUpdatingBan = ref(false)
|
||||
const parseRoles = (roles?: string) => roles ? roles.split(',').map((r) => r.trim().toUpperCase()).filter(Boolean) : []
|
||||
const parseRoles = (roles?: string) => roles ? roles.split(',').map(normalizeRole).filter(Boolean) : []
|
||||
const banConfirmMessage = computed(() =>
|
||||
pendingBanUser.value
|
||||
? `Vuoi ${pendingBanUser.value.banned ? 'sbloccare' : 'bannare'} utente ${pendingBanUser.value.first_name} ${pendingBanUser.value.last_name}?`
|
||||
|
||||
@@ -10,24 +10,21 @@ import OperatorDashboard from '~/components/dashboard/OperatorDashboard.vue'
|
||||
import AdminDashboard from '~/components/dashboard/AdminDashboard.vue'
|
||||
|
||||
const currentDashboard = computed(() => {
|
||||
const role = user.value?.role?.toUpperCase()
|
||||
if (role === 'CITIZEN') return CitizenDashboard
|
||||
if (role === 'OPERATOR') return OperatorDashboard
|
||||
if (role === 'ADMIN') return AdminDashboard
|
||||
if (isCitizen(user.value?.role)) return CitizenDashboard
|
||||
if (isOperator(user.value?.role)) return OperatorDashboard
|
||||
if (isAdmin(user.value?.role)) return AdminDashboard
|
||||
return null
|
||||
})
|
||||
|
||||
const heroTitle = computed(() => {
|
||||
const role = user.value?.role?.toUpperCase()
|
||||
if (role === 'ADMIN') return 'Pannello Admin'
|
||||
if (role === 'OPERATOR') return 'Gestione Operativa'
|
||||
if (isAdmin(user.value?.role)) return 'Pannello Admin'
|
||||
if (isOperator(user.value?.role)) return 'Gestione Operativa'
|
||||
return 'Dashboard'
|
||||
})
|
||||
|
||||
const heroSubtitle = computed(() => {
|
||||
const role = user.value?.role?.toUpperCase()
|
||||
if (role === 'ADMIN') return 'Accesso amministrativo per configurazioni, utenti e moderazione'
|
||||
if (role === 'OPERATOR') return 'Prendi in carico e gestisci le segnalazioni in corso'
|
||||
if (isAdmin(user.value?.role)) return 'Accesso amministrativo per configurazioni, utenti e moderazione'
|
||||
if (isOperator(user.value?.role)) return 'Prendi in carico e gestisci le segnalazioni in corso'
|
||||
return 'Riepilogo rapido delle tue segnalazioni e dei punti cittadino'
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -129,7 +129,9 @@ const handleStatusUpdate = async () => {
|
||||
}
|
||||
|
||||
const handleAssignTeam = async () => {
|
||||
if (isAdmin(user.value?.role)) return
|
||||
if (!selectedTeamId.value) return
|
||||
|
||||
isAssigning.value = true
|
||||
try {
|
||||
const res = await assignTeam(reportId, {
|
||||
@@ -229,6 +231,8 @@ const handleSendMessage = async (msgText: string, files: File[]) => {
|
||||
|
||||
const canFlagMessage = (message: Message) => {
|
||||
if (!user.value) return false
|
||||
if (isAdmin(user.value?.role)) return false
|
||||
|
||||
const isCitizenMessage = message.user_id !== user.value.id && message.user_id === report.value?.user_id
|
||||
const isAlreadyFlagged = flaggedMessageIds.value.includes(message.id)
|
||||
return isCitizenMessage && !isAlreadyFlagged
|
||||
@@ -408,7 +412,7 @@ const formattedInterventionLinkExpiry = computed(() =>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body pt-0">
|
||||
<div v-if="!isAdmin(user?.role)" class="card-body pt-0">
|
||||
<button class="btn btn-outline-primary w-100" @click="isAssignModalOpen = true" :disabled="teams.length === 0">
|
||||
Assegna team
|
||||
</button>
|
||||
|
||||
@@ -71,7 +71,7 @@ const formatDate = (dateString: string) =>
|
||||
</div>
|
||||
<div class="col-md-6 mb-0">
|
||||
<small class="text-muted d-block">Ruolo</small>
|
||||
<span class="badge bg-info">{{ user?.role }}</span>
|
||||
<span class="badge bg-info">{{ normalizeRole(user?.role) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user