diff --git a/rsconcept/frontend/src/app/backendAPI.ts b/rsconcept/frontend/src/app/backendAPI.ts index f78cb7d6..ba0145f4 100644 --- a/rsconcept/frontend/src/app/backendAPI.ts +++ b/rsconcept/frontend/src/app/backendAPI.ts @@ -7,21 +7,7 @@ import { toast } from 'react-toastify'; import { type ErrorData } from '@/components/info/InfoError'; import { ILexemeData, IResolutionData, ITextRequest, ITextResult, IWordFormPlain } from '@/models/language'; -import { - ICurrentUser, - ILibraryItem, - ILibraryUpdateData, - IPasswordTokenData, - IRequestPasswordData, - IResetPasswordData as IResetPasswordData, - IUserInfo, - IUserLoginData, - IUserProfile, - IUserSignupData, - IUserUpdateData, - IUserUpdatePassword, - IVersionData -} from '@/models/library'; +import { ILibraryItem, ILibraryUpdateData, IVersionData } from '@/models/library'; import { IConstituentaList, IConstituentaMeta, @@ -30,7 +16,6 @@ import { ICstMovetoData, ICstRenameData, ICstSubstituteData, - ICstTarget, ICstUpdateData, IInlineSynthesisData, IProduceStructureResponse, @@ -38,9 +23,24 @@ import { IRSFormCreateData, IRSFormData, IRSFormUploadData, + ITargetCst, IVersionCreatedResponse } from '@/models/rsform'; import { IExpressionParse, IRSExpression } from '@/models/rslang'; +import { + ICurrentUser, + IPasswordTokenData, + IRequestPasswordData, + IResetPasswordData, + ITargetUser, + ITargetUsers, + IUserInfo, + IUserLoginData, + IUserProfile, + IUserSignupData, + IUserUpdateData, + IUserUpdatePassword +} from '@/models/user'; import { buildConstants } from '../utils/constants'; @@ -246,6 +246,34 @@ export function deleteLibraryItem(target: string, request: FrontAction) { }); } +export function patchSetOwner(target: string, request: FrontPush) { + AxiosPatch({ + endpoint: `/api/library/${target}/set-owner`, + request: request + }); +} + +export function patchEditorsAdd(target: string, request: FrontPush) { + AxiosPatch({ + endpoint: `/api/library/${target}/editors-add`, + request: request + }); +} + +export function patchEditorsRemove(target: string, request: FrontPush) { + AxiosPatch({ + endpoint: `/api/library/${target}/editors-remove`, + request: request + }); +} + +export function patchEditorsSet(target: string, request: FrontPush) { + AxiosPatch({ + endpoint: `/api/library/${target}/editors-set`, + request: request + }); +} + export function postSubscribe(target: string, request: FrontAction) { AxiosPost({ endpoint: `/api/library/${target}/subscribe`, @@ -304,7 +332,7 @@ export function patchRenameConstituenta(schema: string, request: FrontExchange) { +export function patchProduceStructure(schema: string, request: FrontExchange) { AxiosPatch({ endpoint: `/api/rsforms/${schema}/cst-produce-structure`, request: request diff --git a/rsconcept/frontend/src/components/info/BadgeHelp.tsx b/rsconcept/frontend/src/components/info/BadgeHelp.tsx index 67767e41..078e5e47 100644 --- a/rsconcept/frontend/src/components/info/BadgeHelp.tsx +++ b/rsconcept/frontend/src/components/info/BadgeHelp.tsx @@ -3,9 +3,9 @@ import Tooltip, { PlacesType } from '@/components/ui/Tooltip'; import { useConceptOptions } from '@/context/OptionsContext'; import { HelpTopic } from '@/models/miscellaneous'; +import TopicPage from '../../pages/ManualsPage/TopicPage'; import { IconHelp } from '../Icons'; import { CProps } from '../props'; -import TopicPage from '../../pages/ManualsPage/TopicPage'; interface BadgeHelpProps extends CProps.Styling { topic: HelpTopic; diff --git a/rsconcept/frontend/src/components/info/InfoError.tsx b/rsconcept/frontend/src/components/info/InfoError.tsx index b6cf1b99..4fc55d9c 100644 --- a/rsconcept/frontend/src/components/info/InfoError.tsx +++ b/rsconcept/frontend/src/components/info/InfoError.tsx @@ -40,7 +40,7 @@ function DescribeError({ error }: { error: ErrorData }) { ); } - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const isHtml = isResponseHtml(error.response); return (
diff --git a/rsconcept/frontend/src/components/select/SelectMatchMode.tsx b/rsconcept/frontend/src/components/select/SelectMatchMode.tsx index 7e355190..8ebfeb12 100644 --- a/rsconcept/frontend/src/components/select/SelectMatchMode.tsx +++ b/rsconcept/frontend/src/components/select/SelectMatchMode.tsx @@ -10,7 +10,7 @@ import { CstMatchMode } from '@/models/miscellaneous'; import { prefixes } from '@/utils/constants'; import { describeCstMatchMode, labelCstMatchMode } from '@/utils/labels'; -import { IconAlias, IconTerm, IconFilter, IconFormula, IconText } from '../Icons'; +import { IconAlias, IconFilter, IconFormula, IconTerm, IconText } from '../Icons'; import DropdownButton from '../ui/DropdownButton'; function MatchModeIcon(mode: CstMatchMode, size: string, color?: string) { diff --git a/rsconcept/frontend/src/context/AuthContext.tsx b/rsconcept/frontend/src/context/AuthContext.tsx index f6df8fa3..5ac715bf 100644 --- a/rsconcept/frontend/src/context/AuthContext.tsx +++ b/rsconcept/frontend/src/context/AuthContext.tsx @@ -14,12 +14,17 @@ import { postValidatePasswordToken } from '@/app/backendAPI'; import { type ErrorData } from '@/components/info/InfoError'; -import { IPasswordTokenData, IRequestPasswordData, IResetPasswordData, IUserLoginData } from '@/models/library'; -import { ICurrentUser } from '@/models/library'; -import { IUserSignupData } from '@/models/library'; -import { IUserProfile } from '@/models/library'; -import { IUserInfo } from '@/models/library'; -import { IUserUpdatePassword } from '@/models/library'; +import { + ICurrentUser, + IPasswordTokenData, + IRequestPasswordData, + IResetPasswordData, + IUserInfo, + IUserLoginData, + IUserProfile, + IUserSignupData, + IUserUpdatePassword +} from '@/models/user'; import { useUsers } from './UsersContext'; diff --git a/rsconcept/frontend/src/context/RSFormContext.tsx b/rsconcept/frontend/src/context/RSFormContext.tsx index dff6d045..98b5e440 100644 --- a/rsconcept/frontend/src/context/RSFormContext.tsx +++ b/rsconcept/frontend/src/context/RSFormContext.tsx @@ -36,12 +36,12 @@ import { ICstMovetoData, ICstRenameData, ICstSubstituteData, - ICstTarget, ICstUpdateData, IInlineSynthesisData, IRSForm, IRSFormData, - IRSFormUploadData + IRSFormUploadData, + ITargetCst } from '@/models/rsform'; import { useAuth } from './AuthContext'; @@ -69,7 +69,7 @@ interface IRSFormContext { resetAliases: (callback: () => void) => void; restoreOrder: (callback: () => void) => void; - produceStructure: (data: ICstTarget, callback?: DataCallback) => void; + produceStructure: (data: ITargetCst, callback?: DataCallback) => void; inlineSynthesis: (data: IInlineSynthesisData, callback?: DataCallback) => void; cstCreate: (data: ICstCreateData, callback?: DataCallback) => void; @@ -269,7 +269,7 @@ export const RSFormState = ({ schemaID, versionID, children }: RSFormStateProps) ); const produceStructure = useCallback( - (data: ICstTarget, callback?: DataCallback) => { + (data: ITargetCst, callback?: DataCallback) => { setError(undefined); patchProduceStructure(schemaID, { data: data, diff --git a/rsconcept/frontend/src/context/UserProfileContext.tsx b/rsconcept/frontend/src/context/UserProfileContext.tsx index 8d69a336..fa7fcbc8 100644 --- a/rsconcept/frontend/src/context/UserProfileContext.tsx +++ b/rsconcept/frontend/src/context/UserProfileContext.tsx @@ -4,8 +4,7 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'rea import { DataCallback, getProfile, patchProfile } from '@/app/backendAPI'; import { ErrorData } from '@/components/info/InfoError'; -import { IUserProfile } from '@/models/library'; -import { IUserUpdateData } from '@/models/library'; +import { IUserProfile, IUserUpdateData } from '@/models/user'; import { useUsers } from './UsersContext'; diff --git a/rsconcept/frontend/src/context/UsersContext.tsx b/rsconcept/frontend/src/context/UsersContext.tsx index 736de198..50f83cc1 100644 --- a/rsconcept/frontend/src/context/UsersContext.tsx +++ b/rsconcept/frontend/src/context/UsersContext.tsx @@ -3,7 +3,7 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'react'; import { getActiveUsers } from '@/app/backendAPI'; -import { type IUserInfo } from '@/models/library'; +import { IUserInfo } from '@/models/user'; interface IUsersContext { users: IUserInfo[]; diff --git a/rsconcept/frontend/src/hooks/useCheckExpression.ts b/rsconcept/frontend/src/hooks/useCheckExpression.ts index 79fd52d5..89ebfc5e 100644 --- a/rsconcept/frontend/src/hooks/useCheckExpression.ts +++ b/rsconcept/frontend/src/hooks/useCheckExpression.ts @@ -2,12 +2,12 @@ import { useCallback, useState } from 'react'; +import { DataCallback, postCheckExpression } from '@/app/backendAPI'; import { type ErrorData } from '@/components/info/InfoError'; import { CstType, IConstituenta, type IRSForm } from '@/models/rsform'; import { getDefinitionPrefix } from '@/models/rsformAPI'; import { IArgumentInfo, IExpressionParse } from '@/models/rslang'; import { RSErrorType } from '@/models/rslang'; -import { DataCallback, postCheckExpression } from '@/app/backendAPI'; import { PARAMETER } from '@/utils/constants'; function useCheckExpression({ schema }: { schema?: IRSForm }) { diff --git a/rsconcept/frontend/src/hooks/useRSFormDetails.ts b/rsconcept/frontend/src/hooks/useRSFormDetails.ts index 2e1e8a1d..dd2c532b 100644 --- a/rsconcept/frontend/src/hooks/useRSFormDetails.ts +++ b/rsconcept/frontend/src/hooks/useRSFormDetails.ts @@ -2,10 +2,10 @@ import { useCallback, useEffect, useState } from 'react'; +import { getRSFormDetails } from '@/app/backendAPI'; import { type ErrorData } from '@/components/info/InfoError'; import { IRSForm, IRSFormData } from '@/models/rsform'; import { RSFormLoader } from '@/models/RSFormLoader'; -import { getRSFormDetails } from '@/app/backendAPI'; function useRSFormDetails({ target, version }: { target?: string; version?: string }) { const [schema, setInnerSchema] = useState(undefined); diff --git a/rsconcept/frontend/src/hooks/useResolveText.ts b/rsconcept/frontend/src/hooks/useResolveText.ts index a4f962b0..2926d330 100644 --- a/rsconcept/frontend/src/hooks/useResolveText.ts +++ b/rsconcept/frontend/src/hooks/useResolveText.ts @@ -2,10 +2,10 @@ import { useCallback, useState } from 'react'; +import { DataCallback, postResolveText } from '@/app/backendAPI'; import { ErrorData } from '@/components/info/InfoError'; import { IResolutionData } from '@/models/language'; import { IRSForm } from '@/models/rsform'; -import { DataCallback, postResolveText } from '@/app/backendAPI'; function useResolveText({ schema }: { schema?: IRSForm }) { const [loading, setLoading] = useState(false); diff --git a/rsconcept/frontend/src/models/library.ts b/rsconcept/frontend/src/models/library.ts index 89801f28..3faa72a3 100644 --- a/rsconcept/frontend/src/models/library.ts +++ b/rsconcept/frontend/src/models/library.ts @@ -1,83 +1,7 @@ /** - * Module: Models for Library entities and Users. + * Module: Models for LibraryItem. */ -/** - * Represents user detailed information. - * Some information should only be accessible to authorized users - */ -export interface IUser { - id: number | null; - username: string; - is_staff: boolean; - email: string; - first_name: string; - last_name: string; -} - -/** - * Represents CurrentUser information. - */ -export interface ICurrentUser extends Pick { - subscriptions: number[]; -} - -/** - * Represents login data, used to authenticate users. - */ -export interface IUserLoginData extends Pick { - password: string; -} - -/** - * Represents password reset data. - */ -export interface IResetPasswordData { - password: string; - token: string; -} - -/** - * Represents password token data. - */ -export interface IPasswordTokenData extends Pick {} - -/** - * Represents password reset request data. - */ -export interface IRequestPasswordData extends Pick {} - -/** - * Represents signup data, used to create new users. - */ -export interface IUserSignupData extends Omit { - password: string; - password2: string; -} - -/** - * Represents user data, intended to update user profile in persistent storage. - */ -export interface IUserUpdateData extends Omit {} - -/** - * Represents user profile for viewing and editing {@link IUser}. - */ -export interface IUserProfile extends Omit {} - -/** - * Represents user reference information. - */ -export interface IUserInfo extends Omit {} - -/** - * Represents data needed to update password for current user. - */ -export interface IUserUpdatePassword { - old_password: string; - new_password: string; -} - /** * Represents type of library items. */ diff --git a/rsconcept/frontend/src/models/rsform.ts b/rsconcept/frontend/src/models/rsform.ts index 22d363ab..801874bc 100644 --- a/rsconcept/frontend/src/models/rsform.ts +++ b/rsconcept/frontend/src/models/rsform.ts @@ -85,7 +85,7 @@ export interface IConstituentaMeta { /** * Represents target {@link IConstituenta}. */ -export interface ICstTarget { +export interface ITargetCst { target: ConstituentaID; } @@ -156,7 +156,7 @@ export interface ICstUpdateData /** * Represents data, used in renaming {@link IConstituenta}. */ -export interface ICstRenameData extends ICstTarget, Pick {} +export interface ICstRenameData extends ITargetCst, Pick {} /** * Represents data, used in merging single {@link IConstituenta}. diff --git a/rsconcept/frontend/src/models/user.ts b/rsconcept/frontend/src/models/user.ts new file mode 100644 index 00000000..f3e26f08 --- /dev/null +++ b/rsconcept/frontend/src/models/user.ts @@ -0,0 +1,93 @@ +/** + * Module: Models for Users. + */ + +/** + * Represents user detailed information. + * Some information should only be accessible to authorized users + */ +export interface IUser { + id: number; + username: string; + is_staff: boolean; + email: string; + first_name: string; + last_name: string; +} + +/** + * Represents CurrentUser information. + */ +export interface ICurrentUser extends Pick { + subscriptions: number[]; +} + +/** + * Represents login data, used to authenticate users. + */ +export interface IUserLoginData extends Pick { + password: string; +} + +/** + * Represents password reset data. + */ +export interface IResetPasswordData { + password: string; + token: string; +} + +/** + * Represents password token data. + */ +export interface IPasswordTokenData extends Pick {} + +/** + * Represents password reset request data. + */ +export interface IRequestPasswordData extends Pick {} + +/** + * Represents signup data, used to create new users. + */ +export interface IUserSignupData extends Omit { + password: string; + password2: string; +} + +/** + * Represents user data, intended to update user profile in persistent storage. + */ +export interface IUserUpdateData extends Omit {} + +/** + * Represents user profile for viewing and editing {@link IUser}. + */ +export interface IUserProfile extends Omit {} + +/** + * Represents user reference information. + */ +export interface IUserInfo extends Omit {} + +/** + * Represents data needed to update password for current user. + */ +export interface IUserUpdatePassword { + old_password: string; + new_password: string; +} + +/** + * Represents target {@link User}. + */ +export interface ITargetUser { + user: number; +} + +/** + * Represents target multiple {@link User}. + */ +export interface ITargetUsers { + users: number[]; +} diff --git a/rsconcept/frontend/src/pages/LibraryPage/ItemIcons.tsx b/rsconcept/frontend/src/pages/LibraryPage/ItemIcons.tsx index ac5eb486..e854b683 100644 --- a/rsconcept/frontend/src/pages/LibraryPage/ItemIcons.tsx +++ b/rsconcept/frontend/src/pages/LibraryPage/ItemIcons.tsx @@ -1,7 +1,8 @@ import clsx from 'clsx'; import { IconImmutable, IconPublic } from '@/components/Icons'; -import { ICurrentUser, ILibraryItem } from '@/models/library'; +import { ILibraryItem } from '@/models/library'; +import { ICurrentUser } from '@/models/user'; import { prefixes } from '@/utils/constants'; interface ItemIconsProps { diff --git a/rsconcept/frontend/src/pages/LoginPage.tsx b/rsconcept/frontend/src/pages/LoginPage.tsx index c2465f7e..e422373c 100644 --- a/rsconcept/frontend/src/pages/LoginPage.tsx +++ b/rsconcept/frontend/src/pages/LoginPage.tsx @@ -14,7 +14,7 @@ import ExpectedAnonymous from '@/components/wrap/ExpectedAnonymous'; import { useAuth } from '@/context/AuthContext'; import { useConceptNavigation } from '@/context/NavigationContext'; import useQueryStrings from '@/hooks/useQueryStrings'; -import { IUserLoginData } from '@/models/library'; +import { IUserLoginData } from '@/models/user'; import { resources } from '@/utils/constants'; function ProcessError({ error }: { error: ErrorData }): React.ReactElement { diff --git a/rsconcept/frontend/src/pages/ManualsPage/ViewTopic.tsx b/rsconcept/frontend/src/pages/ManualsPage/ViewTopic.tsx index 00870c36..130e86ce 100644 --- a/rsconcept/frontend/src/pages/ManualsPage/ViewTopic.tsx +++ b/rsconcept/frontend/src/pages/ManualsPage/ViewTopic.tsx @@ -1,6 +1,6 @@ -import TopicPage from '@/pages/ManualsPage/TopicPage'; import AnimateFade from '@/components/wrap/AnimateFade'; import { HelpTopic } from '@/models/miscellaneous'; +import TopicPage from '@/pages/ManualsPage/TopicPage'; interface ViewTopicProps { topic: HelpTopic; diff --git a/rsconcept/frontend/src/pages/PasswordChangePage.tsx b/rsconcept/frontend/src/pages/PasswordChangePage.tsx index edd1a7e7..e6128010 100644 --- a/rsconcept/frontend/src/pages/PasswordChangePage.tsx +++ b/rsconcept/frontend/src/pages/PasswordChangePage.tsx @@ -12,7 +12,7 @@ import DataLoader from '@/components/wrap/DataLoader'; import { useAuth } from '@/context/AuthContext'; import { useConceptNavigation } from '@/context/NavigationContext'; import useQueryStrings from '@/hooks/useQueryStrings'; -import { IPasswordTokenData, IResetPasswordData } from '@/models/library'; +import { IPasswordTokenData, IResetPasswordData } from '@/models/user'; function ProcessError({ error }: { error: ErrorData }): React.ReactElement { if (axios.isAxiosError(error) && error.response && error.response.status === 404) { diff --git a/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx b/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx index 344e7f67..888f8064 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx @@ -38,10 +38,10 @@ import { ICstMovetoData, ICstRenameData, ICstSubstituteData, - ICstTarget, ICstUpdateData, IInlineSynthesisData, IRSForm, + ITargetCst, TermForm } from '@/models/rsform'; import { generateAlias } from '@/models/rsformAPI'; @@ -447,7 +447,7 @@ export const RSEditState = ({ if (isModified && !promptUnsaved()) { return; } - const data: ICstTarget = { + const data: ITargetCst = { target: activeCst.id }; model.produceStructure(data, cstList => { diff --git a/rsconcept/frontend/src/pages/RegisterPage.tsx b/rsconcept/frontend/src/pages/RegisterPage.tsx index 24b3d363..ef45b3bf 100644 --- a/rsconcept/frontend/src/pages/RegisterPage.tsx +++ b/rsconcept/frontend/src/pages/RegisterPage.tsx @@ -19,7 +19,7 @@ import AnimateFade from '@/components/wrap/AnimateFade'; import ExpectedAnonymous from '@/components/wrap/ExpectedAnonymous'; import { useAuth } from '@/context/AuthContext'; import { useConceptNavigation } from '@/context/NavigationContext'; -import { type IUserSignupData } from '@/models/library'; +import { IUserSignupData } from '@/models/user'; import { globals, patterns } from '@/utils/constants'; function RegisterPage() { diff --git a/rsconcept/frontend/src/pages/RestorePasswordPage.tsx b/rsconcept/frontend/src/pages/RestorePasswordPage.tsx index 8e477742..5bb74b94 100644 --- a/rsconcept/frontend/src/pages/RestorePasswordPage.tsx +++ b/rsconcept/frontend/src/pages/RestorePasswordPage.tsx @@ -10,7 +10,7 @@ import TextInput from '@/components/ui/TextInput'; import TextURL from '@/components/ui/TextURL'; import AnimateFade from '@/components/wrap/AnimateFade'; import { useAuth } from '@/context/AuthContext'; -import { IRequestPasswordData } from '@/models/library'; +import { IRequestPasswordData } from '@/models/user'; function ProcessError({ error }: { error: ErrorData }): React.ReactElement { if (axios.isAxiosError(error) && error.response && error.response.status === 400) { diff --git a/rsconcept/frontend/src/pages/UserProfilePage/EditorPassword.tsx b/rsconcept/frontend/src/pages/UserProfilePage/EditorPassword.tsx index abbff2b8..07df7f73 100644 --- a/rsconcept/frontend/src/pages/UserProfilePage/EditorPassword.tsx +++ b/rsconcept/frontend/src/pages/UserProfilePage/EditorPassword.tsx @@ -12,7 +12,7 @@ import SubmitButton from '@/components/ui/SubmitButton'; import TextInput from '@/components/ui/TextInput'; import { useAuth } from '@/context/AuthContext'; import { useConceptNavigation } from '@/context/NavigationContext'; -import { IUserUpdatePassword } from '@/models/library'; +import { IUserUpdatePassword } from '@/models/user'; function ProcessError({ error }: { error: ErrorData }): React.ReactElement { if (axios.isAxiosError(error) && error.response && error.response.status === 400) { diff --git a/rsconcept/frontend/src/pages/UserProfilePage/EditorProfile.tsx b/rsconcept/frontend/src/pages/UserProfilePage/EditorProfile.tsx index 27c2f0ce..f5c88bc2 100644 --- a/rsconcept/frontend/src/pages/UserProfilePage/EditorProfile.tsx +++ b/rsconcept/frontend/src/pages/UserProfilePage/EditorProfile.tsx @@ -8,7 +8,7 @@ import SubmitButton from '@/components/ui/SubmitButton'; import TextInput from '@/components/ui/TextInput'; import { useBlockNavigation } from '@/context/NavigationContext'; import { useUserProfile } from '@/context/UserProfileContext'; -import { IUserUpdateData } from '@/models/library'; +import { IUserUpdateData } from '@/models/user'; function EditorProfile() { const { updateUser, user, processing } = useUserProfile();