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: 2 additions & 1 deletion SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ The app knows when the decider is away — it manages their leave too:
own entitlement."), nor their own vacation days in the employees JSON (§6.5).
A bulk change and handing on a changed default (§6.1) leave the actor's own
entitlement out and answer `ownSkipped: true`. occ has no actor and changes
every entitlement.
every entitlement. Their own profile and their own row of the employees list
offer no entitlement editor and say "Somebody else from HR changes your own days."

### 5.6 HR-recorded leave (e.g. sick leave)

Expand Down
17 changes: 16 additions & 1 deletion src/utils/access.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { describe, expect, it } from 'vitest'
import { canOpenRoute } from './access.ts'
import { canEditEntitlementOf, canOpenRoute } from './access.ts'

describe('canOpenRoute', () => {
it('opens ordinary pages to everyone', () => {
Expand All @@ -22,3 +22,18 @@ describe('canOpenRoute', () => {
expect(canOpenRoute({ hr: true }, admin)).toBe(false)
})
})

describe('canEditEntitlementOf', () => {
it('lets HR change somebody else\'s days', () => {
expect(canEditEntitlementOf({ uid: 'alice', isHr: true }, 'bob')).toBe(true)
})

it('leaves the days of an HR member to somebody else from HR', () => {
expect(canEditEntitlementOf({ uid: 'alice', isHr: true }, 'alice')).toBe(false)
})

it('never lets anybody else change days', () => {
expect(canEditEntitlementOf({ uid: 'alice', isHr: false }, 'bob')).toBe(false)
expect(canEditEntitlementOf({ uid: null }, 'bob')).toBe(false)
})
})
11 changes: 11 additions & 0 deletions src/utils/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ export function canOpenRoute(meta: RouteAccess, session: AccessRoles): boolean {
}
return !!session.isHr || (!!meta.admin && !!session.isAdmin)
}

/**
* Whether this session may change someone's entitlement: HR may, except their
* own, which somebody else from HR changes (§5.5).
*
* @param session the current session
* @param uid whose entitlement it is
*/
export function canEditEntitlementOf(session: AccessRoles, uid: string): boolean {
return !!session.isHr && session.uid !== uid
}
24 changes: 15 additions & 9 deletions src/views/ProfileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@
<template v-else>
<BalanceCard v-for="row in balances" :key="row.typeId" :row="row" />
</template>
<NcButton
v-if="profile.canEditContract && balances.length"
class="profile__edit"
@click="editingDays = balances[0] ?? null">
<template #icon>
<Pencil :size="20" />
</template>
{{ t('absence', 'Edit vacation days') }}
</NcButton>
<template v-if="profile.canEditContract && balances.length">
<NcButton
v-if="canEditEntitlementOf(sessionStore.session, profileUid)"
class="profile__edit"
@click="editingDays = balances[0] ?? null">
<template #icon>
<Pencil :size="20" />
</template>
{{ t('absence', 'Edit vacation days') }}
</NcButton>
<p v-else class="profile__note">
{{ t('absence', 'Somebody else from HR changes your own days.') }}
</p>
</template>
<p v-if="profile.nextLeave" class="profile__note">
{{ n('absence', 'Next leave: {range}, {count} working day', 'Next leave: {range}, {count} working days', profile.nextLeave.workingDays, { range: formatRange(profile.nextLeave.startDate, profile.nextLeave.endDate), count: profile.nextLeave.workingDays }) }}
</p>
Expand Down Expand Up @@ -184,6 +189,7 @@ import RegionCodeField from '../components/RegionCodeField.vue'
import SkeletonList from '../components/SkeletonList.vue'
import api from '../services/api.ts'
import { useSessionStore } from '../stores/session.ts'
import { canEditEntitlementOf } from '../utils/access.ts'
import { patternSince } from '../utils/contract.ts'
import { formatDate, formatRange, toIso } from '../utils/dates.ts'
import { displayNameOf } from '../utils/displayName.ts'
Expand Down
27 changes: 20 additions & 7 deletions src/views/hr/HrEmployees.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,23 @@
</td>
<td>
<NcActions :ariaLabel="t('absence', 'Actions for {name}', { name: row.displayName }, undefined, { escape: false, sanitize: false })">
<NcActionButton
v-for="balance in row.balances"
:key="balance.typeId"
@click="editing = { row, balance }">
<template v-if="canEditEntitlementOf(sessionStore.session, row.uid)">
<NcActionButton
v-for="balance in row.balances"
:key="balance.typeId"
@click="editing = { row, balance }">
<template #icon>
<Pencil :size="20" />
</template>
{{ t('absence', 'Edit entitlement: {type}', { type: balance.typeLabel }, undefined, { escape: false, sanitize: false }) }}
</NcActionButton>
</template>
<NcActionText v-else>
<template #icon>
<Pencil :size="20" />
<InformationOutline :size="20" />
</template>
{{ t('absence', 'Edit entitlement: {type}', { type: balance.typeLabel }, undefined, { escape: false, sanitize: false }) }}
</NcActionButton>
{{ t('absence', 'Somebody else from HR changes your own days.') }}
</NcActionText>
</NcActions>
</td>
</tr>
Expand Down Expand Up @@ -246,6 +254,7 @@ import { generateUrl } from '@nextcloud/router'
import { computed, onMounted, ref, shallowRef, watch } from 'vue'
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
import NcActions from '@nextcloud/vue/components/NcActions'
import NcActionText from '@nextcloud/vue/components/NcActionText'
import NcAvatar from '@nextcloud/vue/components/NcAvatar'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcChip from '@nextcloud/vue/components/NcChip'
Expand All @@ -256,13 +265,16 @@ import AccountGroup from 'vue-material-design-icons/AccountGroup.vue'
import BellRingOutline from 'vue-material-design-icons/BellRingOutline.vue'
import CodeBraces from 'vue-material-design-icons/CodeBraces.vue'
import Download from 'vue-material-design-icons/Download.vue'
import InformationOutline from 'vue-material-design-icons/InformationOutline.vue'
import Magnify from 'vue-material-design-icons/Magnify.vue'
import Pencil from 'vue-material-design-icons/Pencil.vue'
import EmployeesJsonDialog from '../../components/EmployeesJsonDialog.vue'
import EntitlementDialog from '../../components/EntitlementDialog.vue'
import RegionReminderDialog from '../../components/RegionReminderDialog.vue'
import SkeletonList from '../../components/SkeletonList.vue'
import api from '../../services/api.ts'
import { useSessionStore } from '../../stores/session.ts'
import { canEditEntitlementOf } from '../../utils/access.ts'
import { balanceTone } from '../../utils/balance.ts'
import { formatDate } from '../../utils/dates.ts'
import { serverMessage } from '../../utils/errors.ts'
Expand Down Expand Up @@ -306,6 +318,7 @@ const filter = ref<FilterId>('all')
const limit = ref(PAGE)
const year = ref(currentYear)
const years = [currentYear - 1, currentYear, currentYear + 1]
const sessionStore = useSessionStore()
const editing = ref<EditedEntitlement | null>(null)
const editingJson = ref(false)
const reminding = ref(false)
Expand Down
Loading