TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.
TypeScript graphviewkanban-boardnodejsproductivityproject-managementself-hostedtasktask-managementtask-managertodoapp
fix: filter only allowed projects for api-tokens
Nikolai Giman35776d9eb5d2
diff --git a/api/src/tv-modules/goals/GoalsManager.ts b/api/src/tv-modules/goals/GoalsManager.tsindex 0d81ce1..0dd4a24 100644--- a/api/src/tv-modules/goals/GoalsManager.ts+++ b/api/src/tv-modules/goals/GoalsManager.ts@@ -142,20 +142,30 @@ export default class GoalsManager {const sharedGoals = await this.goalsRepository.fetchSharedGoalsForUser(this.user!);const ownGoals = await this.goalsRepository.fetchGoalsNew(this.user.getUserData()?.id!);+ const allowedGoalIds = this.user.getAllowedGoalIds();+ const filterByAllowed = allowedGoalIds && allowedGoalIds.length > 0;++ const filteredOwnGoals = filterByAllowed+ ? ownGoals.filter((g) => allowedGoalIds.includes(g.id))+ : ownGoals;+ const filteredSharedGoals = filterByAllowed+ ? sharedGoals.filter((g) => allowedGoalIds.includes(g.id))+ : sharedGoals;+let ownGoalsWithPermissions: GoalsItemForClientWithPermissions[] = [];let sharedGoalsWithPermissions: GoalsItemForClientWithPermissions[] = [];- if (ownGoals.length > 0) {+ if (filteredOwnGoals.length > 0) {const permChecker = await this.user.permissionsFetcher.getPermissionsForType(- ownGoals[0].id,+ filteredOwnGoals[0].id,GoalPermissionsFetcher.PERMISSION_TYPE_FOR_GOAL);- ownGoalsWithPermissions = ownGoals.map((g) => ({ ...g, permissions: permChecker.getAllPermissions() }));+ ownGoalsWithPermissions = filteredOwnGoals.map((g) => ({ ...g, permissions: permChecker.getAllPermissions() }));}- if (sharedGoals.length > 0) {+ if (filteredSharedGoals.length > 0) {sharedGoalsWithPermissions = await Promise.all(- sharedGoals.map(async (g) => {+ filteredSharedGoals.map(async (g) => {return {...g,permissions: (diff --git a/docs/2.features/8.api-tokens.md b/docs/2.features/8.api-tokens.mdnew file mode 100644index 0000000..9042f72--- /dev/null+++ b/docs/2.features/8.api-tokens.md@@ -0,0 +1,165 @@+---+title: API Tokens+description: Create API tokens for programmatic access to TaskView. Tokens support permission scoping, project-level restrictions, and optional expiration.+navigation:+ icon: i-lucide-key-round+---++API tokens let you access the TaskView API without a browser session. Use them for scripts, CI/CD pipelines, bots, and any programmatic integration.++## Token format++Tokens use the prefix `tvk_` followed by 64 hex characters:++```+tvk_a1b2c3d4e5f6...+```++The full token is shown **only once** at creation. TaskView stores only the SHA-256 hash - if you lose the token, you'll need to create a new one.++## Creating a token++1. Go to **Account Settings** → **API Tokens**+2. Click **"Create Token"**+3. Enter a name (e.g. "CI pipeline", "Slack bot")+4. Optionally restrict permissions and projects+5. Optionally set an expiration date+6. Click **"Create"**+7. Copy the token immediately - it will not be shown again++## Authentication++Send the token in the `Authorization` header:++```bash+curl -H "Authorization: Bearer tvk_a1b2c3d4..." \+ https://your-instance.com/module/tasks?goalId=1+```++## Permission scoping++By default a token inherits all permissions of its owner. You can restrict this at creation:++- **Permissions** - select which operations the token can perform (e.g. only read tasks, only create tasks)+- **Projects** - restrict the token to specific projects. If no projects are selected, the token has access to all projects the owner can access++Permissions are **intersected** with the user's RBAC role. A token cannot have more permissions than the user who created it. See [Roles and Permissions](/collaboration/roles-and-permissions) for details on how RBAC works.++### Available permission examples++| Permission | Description |+|---|---|+| `component_can_watch_content` | Read tasks and lists |+| `component_can_add_tasks` | Create new tasks |+| `task_can_edit_description` | Edit task descriptions |+| `task_can_edit_status` | Change task status |+| `task_can_delete` | Delete tasks |+| `task_can_assign_users` | Assign users to tasks |++The full list of available permissions is returned by `GET /module/api-tokens/permissions`.++## Expiration++Tokens can optionally have an expiration date. After expiration, the token returns `401 Unauthorized`. Tokens without an expiration date are valid until manually revoked.++## Security++- Tokens **cannot manage other tokens** - all token management endpoints reject API token authentication+- Only the SHA-256 hash is stored in the database+- `lastUsedAt` is updated on each use for audit purposes+- Tokens for blocked users are automatically rejected++## API reference++All endpoints require JWT authentication (not API token).++### List tokens++```+GET /module/api-tokens+```++Returns all tokens for the current user (without hashes).++### Create token++```+POST /module/api-tokens+```++```json+{+ "name": "CI pipeline",+ "allowedPermissions": ["component_can_watch_content"],+ "allowedGoalIds": [1, 2],+ "expiresAt": "2026-12-31T23:59:59Z"+}+```++All fields except `name` are optional. Returns the full plaintext token once.++### Delete token++```+DELETE /module/api-tokens+```++```json+{+ "id": 5+}+```++### List available permissions++```+GET /module/api-tokens/permissions+```++Returns permissions grouped by category.++## Usage example++Using the `taskview-api` package:++```bash+npm install taskview-api axios+```++```typescript+import axios from 'axios'+import { TvApi } from 'taskview-api'++const GOAL_ID = 1++const $axios = axios.create({+ baseURL: 'https://your-instance.com',+ headers: {+ Authorization: 'Bearer tvk_your_token_here',+ },+})++const api = new TvApi($axios)++// Fetch all tasks in a project+const tasks = await api.tasks.fetch({ goalId: GOAL_ID })+console.log(`Found ${tasks.length} tasks`)++// Create a new task+const newTask = await api.tasks.createTask({+ goalId: GOAL_ID,+ description: 'Task created via API',+})+console.log('Created task:', newTask.id)++// Update the task description+await api.tasks.updateTask({+ id: newTask.id,+ description: 'Updated via API',+})+console.log('Task updated')++// Fetch projects+const goals = await api.goals.fetchGoals()+console.log('Projects:', goals.map((g) => g.name))+```diff --git a/docs/2.features/9.sessions.md b/docs/2.features/9.sessions.mdnew file mode 100644index 0000000..814c66f--- /dev/null+++ b/docs/2.features/9.sessions.md@@ -0,0 +1,69 @@+---+title: Sessions & Devices+description: Manage active sessions in TaskView. View logged-in devices, close individual sessions, or sign out of all devices at once.+navigation:+ icon: i-lucide-monitor-smartphone+---++TaskView tracks every login as a separate session. You can see all active sessions, identify which device each session belongs to, and close sessions remotely.++## How sessions work++When you log in from any device (browser, mobile app), TaskView creates a session record with:++- **Device name** - automatically parsed from User-Agent (e.g. "Chrome 120, macOS", "Safari 17, iPhone")+- **IP address** - the IP used at login time+- **Created at** - when the session was created+- **Last used** - when the session was last active++The JWT token issued at login contains the session ID. On each request, TaskView verifies that the session still exists - if it's been revoked, the token is rejected.++## Viewing sessions++1. Go to **Account** → **Sessions**+2. See all active sessions with device name, IP, and timestamps+3. Your current session is marked++## Closing a session++Click the close button on any session to revoke it. The user on that device will be signed out on their next request.++You cannot close your current session from this page - use the regular logout instead.++## Closing all other sessions++Click **"Close all other sessions"** to sign out of every device except the one you're currently using. Useful if you suspect unauthorized access.++## API reference++All endpoints require JWT authentication. API tokens cannot manage sessions.++### List sessions++```+GET /module/sessions+```++Returns all active sessions for the current user. Each session includes an `isCurrent` flag.++### Close a session++```+DELETE /module/sessions+```++```json+{+ "id": 42+}+```++Returns `400` if you try to close the current session.++### Close all other sessions++```+DELETE /module/sessions/all+```++Closes all sessions except the current one.diff --git a/web/src/components/features/api-tokens/parts/CreateApiTokenModal.vue b/web/src/components/features/api-tokens/parts/CreateApiTokenModal.vueindex 7ad8aee..29436a4 100644--- a/web/src/components/features/api-tokens/parts/CreateApiTokenModal.vue+++ b/web/src/components/features/api-tokens/parts/CreateApiTokenModal.vue@@ -23,6 +23,20 @@class="w-full"/></UFormField>+ <UFormField :label="t('apiTokens.projects')">+ <p class="text-xs text-muted mb-2">+ {{ t('apiTokens.projectsHint') }}+ </p>+ <USelectMenu+ v-model="selectedGoalIds"+ :items="goalOptions"+ multiple+ value-key="value"+ :search-input="false"+ class="w-full"+ :placeholder="t('apiTokens.allProjects')"+ />+ </UFormField><UFormField :label="t('apiTokens.permissions')"><p class="text-xs text-muted mb-2"><a@@ -113,6 +127,7 @@ import { ref, computed, onMounted } from 'vue'import { useI18n } from 'vue-i18n'import { useClipboard } from '@vueuse/core'import { useApiTokensStore } from '@/stores/api-tokens.store'+import { useGoalsStore } from '@/stores/goals.store'import { useTaskView } from '@/composables/useTaskView'const isOpen = defineModel<boolean>('open', { default: false })@@ -125,10 +140,12 @@ const { t } = useI18n()const { isMobile } = useTaskView()const { copy } = useClipboard()const store = useApiTokensStore()+const goalsStore = useGoalsStore()const name = ref('')const expiration = ref('none')const selectedPermissions = ref<string[]>([])+const selectedGoalIds = ref<number[]>([])const saving = ref(false)const showToken = ref(false)const createdToken = ref('')@@ -141,6 +158,12 @@ const expirationOptions = [{ label: t('apiTokens.year1'), value: '365' },]+const goalOptions = computed(() =>+ goalsStore.goals+ .filter((g) => g.archive === 0)+ .map((g) => ({ label: g.name, value: g.id }))+)+const permissionGroupNames: Record<number, string> = {1: 'Application level',2: 'Project',@@ -183,6 +206,7 @@ async function handleCreate() {const result = await store.createToken({name: name.value,allowedPermissions: selectedPermissions.value.length > 0 ? selectedPermissions.value : undefined,+ allowedGoalIds: selectedGoalIds.value.length > 0 ? selectedGoalIds.value : undefined,expiresAt: getExpiresAt(),})@@ -192,6 +216,7 @@ async function handleCreate() {showToken.value = truename.value = ''selectedPermissions.value = []+ selectedGoalIds.value = []expiration.value = 'none'emit('created')}diff --git a/web/src/locales/en.ts b/web/src/locales/en.tsindex c5a1461..46bdcd2 100644--- a/web/src/locales/en.ts+++ b/web/src/locales/en.ts@@ -457,6 +457,9 @@ export default {days60: '60 days',days90: '90 days',year1: '1 year',+ projects: 'Projects',+ projectsHint: 'Restrict token to specific projects. Leave empty for access to all projects.',+ allProjects: 'All projects',permissions: 'Permissions',permissionsCount: 'permissions',permissionsDocs: 'Learn more about permissions',diff --git a/web/src/stores/api-tokens.store.ts b/web/src/stores/api-tokens.store.tsindex 9f25851..1ae511b 100644--- a/web/src/stores/api-tokens.store.ts+++ b/web/src/stores/api-tokens.store.ts@@ -22,7 +22,7 @@ export const useApiTokensStore = defineStore('apiTokens', {this.loading = false},- async createToken(data: { name: string; allowedPermissions?: string[]; expiresAt?: string | null }): Promise<{ token: string; item: ApiTokenItem } | null> {+ async createToken(data: { name: string; allowedPermissions?: string[]; allowedGoalIds?: number[]; expiresAt?: string | null }): Promise<{ token: string; item: ApiTokenItem } | null> {const result = await $tvApi.apiTokens.create(data)if (!result) return nullthis.tokens.push(result.item)