main

mattermost/focalboard

Last updated at: 29/12/2023 09:47

user.tsx

TLDR

This file contains interfaces and functions related to user data and preferences.

Interfaces

IUser

This interface represents the properties of a user. It includes fields such as id, username, email, nickname, firstname, lastname, and props, which is a record of key-value pairs. Other fields include create_at, update_at, is_bot, is_guest, permissions, and roles.

UserWorkspace

This interface represents a user workspace. It includes fields such as id, title, and boardCount.

UserConfigPatch

This interface represents a patch for updating user configuration. It includes optional fields updatedFields and deletedFields, which specify the updated and deleted fields respectively.

UserPreference

This interface represents a user preference. It includes fields such as user_id, category, name, and value.

Functions

parseUserProps

This function takes an array of UserPreference objects as input and returns a processed record of user preferences. It iterates over the input array, and if the name property of a UserPreference object is 'hiddenBoardIDs', it parses the value of that object as an array, and then creates a new key-value pair in the processed result for each value in the array, with the keys being the board IDs and the values being true.

Classes

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

interface IUser {
    id: string
    username: string
    email: string
    nickname: string
    firstname: string
    lastname: string
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    props: Record<string, any>
    create_at: number
    update_at: number
    is_bot: boolean
    is_guest: boolean
    permissions?: string[]
    roles: string
}

interface UserWorkspace {
    id: string
    title: string
    boardCount: number
}

interface UserConfigPatch {
    updatedFields?: Record<string, string>
    deletedFields?: string[]
}

function parseUserProps(props: UserPreference[]): Record<string, UserPreference> {
    const processedProps: Record<string, UserPreference> = {}

    props.forEach((prop) => {
        const processedProp = prop
        if (prop.name === 'hiddenBoardIDs') {
            const hiddenBoardIDs = JSON.parse(processedProp.value)
            processedProp.value = {}
            hiddenBoardIDs.forEach((boardID: string) => {
                processedProp.value[boardID] = true
            })
        }
        processedProps[processedProp.name] = processedProp
    })

    return processedProps
}

interface UserPreference {
    user_id: string
    category: string
    name: string
    value: any
}

export {
    IUser,
    UserWorkspace,
    UserConfigPatch,
    parseUserProps,
    UserPreference,
}