Web: Added canChangeVersionHistory function.

This commit is contained in:
Tatiana Lopaeva 2022-11-17 16:05:59 +03:00
parent 3d09dc49b1
commit 6a87a8e6bd
8 changed files with 131 additions and 69 deletions

View File

@ -23,7 +23,7 @@ export default function withBadges(WrappedComponent) {
isTrashFolder,
} = this.props;
if (isTrashFolder) return;
fetchFileVersions(item.id + "");
fetchFileVersions(item.id + "", item.access);
setIsVerHistoryPanel(true);
};

View File

@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { inject } from "mobx-react";
import { ReactSVG } from "react-svg";
@ -9,14 +9,26 @@ import infoPanel from "@docspace/common/components/Section/sub-components/info-p
const CommentEditor = ({
t,
item,
editing,
setSelection,
isRecycleBinFolder,
isArchiveFolderRoot,
fetchFileVersions,
updateCommentVersion,
canChangeVersionHistory,
setVerHistoryFileId,
setVerHistoryFileAccess,
}) => {
const { id, comment, version } = item;
const { id, comment, version, access, folderType } = item;
const changeVersionHistoryAbility = canChangeVersionHistory({
access,
folderType,
editing,
});
useEffect(() => {
setVerHistoryFileId(id);
setVerHistoryFileAccess(access);
}, []);
const [isEdit, setIsEdit] = useState(false);
const [isLoading, setIsLoading] = useState(false);
@ -32,7 +44,7 @@ const CommentEditor = ({
const onSave = async () => {
setIsLoading(true);
await fetchFileVersions(id).catch((err) => {
await fetchFileVersions(id, access).catch((err) => {
toastr.error(err);
setIsLoading(false);
});
@ -61,7 +73,7 @@ const CommentEditor = ({
{comment}
</Text>
)}
{!isRecycleBinFolder && !isArchiveFolderRoot && (
{changeVersionHistoryAbility && (
<div className="edit_toggle" onClick={onOpenEditor}>
<ReactSVG
className="edit_toggle-icon"
@ -104,17 +116,29 @@ const CommentEditor = ({
);
};
export default inject(({ auth, versionHistoryStore, treeFoldersStore }) => {
export default inject(({ auth, versionHistoryStore, accessRightsStore }) => {
const { setSelection } = auth.infoPanelStore;
const { fetchFileVersions, updateCommentVersion } = versionHistoryStore;
const { isRecycleBinFolder, isArchiveFolderRoot } = treeFoldersStore;
const {
fetchFileVersions,
updateCommentVersion,
isEditingVersion,
isEditing,
fileId,
setVerHistoryFileId,
setVerHistoryFileAccess,
} = versionHistoryStore;
const { canChangeVersionHistory } = accessRightsStore;
const editing = isEditingVersion || isEditing;
return {
setSelection,
isRecycleBinFolder,
isArchiveFolderRoot,
fetchFileVersions,
updateCommentVersion,
canChangeVersionHistory,
editing,
setVerHistoryFileId,
setVerHistoryFileAccess,
};
})(CommentEditor);

View File

@ -42,16 +42,12 @@ const VersionRow = (props) => {
versionsListLength,
isEditing,
theme,
isArchiveFolderRoot,
canChangeVersionHistory,
} = props;
const [showEditPanel, setShowEditPanel] = useState(false);
const [commentValue, setCommentValue] = useState(info.comment);
const [isSavingComment, setIsSavingComment] = useState(false);
const { changeVersionHistory } = getFileRoleActions(info.access);
const canEdit = changeVersionHistory && !isEditing;
const title = `${new Date(info.updated).toLocaleString(
culture
)} ${Encoder.htmlDecode(info.updatedBy?.displayName)}`;
@ -95,15 +91,13 @@ const VersionRow = (props) => {
);
};
const isAvailableEdit = canEdit && !isArchiveFolderRoot;
const contextOptions = [
isAvailableEdit && {
canChangeVersionHistory && {
key: "edit",
label: t("EditComment"),
onClick: onEditComment,
},
isAvailableEdit && {
canChangeVersionHistory && {
key: "restore",
label: t("Common:Restore"),
onClick: onRestoreClick,
@ -115,7 +109,9 @@ const VersionRow = (props) => {
},
];
const onClickProp = isAvailableEdit ? { onClick: onVersionClick } : {};
const onClickProp = canChangeVersionHistory
? { onClick: onVersionClick }
: {};
useEffect(() => {
const newRowHeight = document.getElementsByClassName(
@ -129,7 +125,7 @@ const VersionRow = (props) => {
<StyledVersionRow
showEditPanel={showEditPanel}
contextOptions={contextOptions}
canEdit={isAvailableEdit}
canEdit={canChangeVersionHistory}
isTabletView={isTabletView}
isSavingComment={isSavingComment}
isEditing={isEditing}
@ -225,32 +221,42 @@ const VersionRow = (props) => {
);
};
export default inject(({ auth, versionHistoryStore, treeFoldersStore }) => {
const { user } = auth.userStore;
const { culture, isTabletView } = auth.settingsStore;
const language = (user && user.cultureName) || culture || "en";
export default inject(
({ auth, versionHistoryStore, accessRightsStore, selectedFolderStore }) => {
const { user } = auth.userStore;
const { culture, isTabletView } = auth.settingsStore;
const language = (user && user.cultureName) || culture || "en";
const {
markAsVersion,
restoreVersion,
updateCommentVersion,
isEditing,
isEditingVersion,
} = versionHistoryStore;
const {
markAsVersion,
restoreVersion,
updateCommentVersion,
isEditing,
isEditingVersion,
fileAccess,
} = versionHistoryStore;
const { isArchiveFolderRoot } = treeFoldersStore;
const { rootFolderType } = selectedFolderStore;
return {
theme: auth.settingsStore.theme,
culture: language,
isTabletView,
markAsVersion,
restoreVersion,
updateCommentVersion,
isEditing: isEditingVersion || isEditing,
isArchiveFolderRoot,
};
})(
const isEdit = isEditingVersion || isEditing;
const canChangeVersionHistory = accessRightsStore.canChangeVersionHistory({
access: fileAccess,
rootFolderType,
editing: isEdit,
});
return {
theme: auth.settingsStore.theme,
culture: language,
isTabletView,
markAsVersion,
restoreVersion,
updateCommentVersion,
isEditing: isEdit,
canChangeVersionHistory,
};
}
)(
withRouter(
withTranslation(["VersionHistory", "Common", "Translations"])(
observer(VersionRow)

View File

@ -24,15 +24,15 @@ class SectionBodyContent extends React.Component {
const fileId = match.params.fileId || this.props.fileId;
if (fileId && fileId !== this.props.fileId) {
this.getFileVersions(fileId);
this.getFileVersions(fileId, fileAccess);
setFirstLoad(false);
}
}
getFileVersions = (fileId) => {
getFileVersions = (fileId, fileAccess) => {
const { fetchFileVersions, setIsLoading } = this.props;
setIsLoading(true);
fetchFileVersions(fileId).then(() => setIsLoading(false));
fetchFileVersions(fileId, fileAccess).then(() => setIsLoading(false));
};
onSetRestoreProcess = (restoring) => {
@ -138,14 +138,19 @@ class SectionBodyContent extends React.Component {
export default inject(({ auth, filesStore, versionHistoryStore }) => {
const { setFirstLoad, setIsLoading, isLoading } = filesStore;
const { versions, fetchFileVersions, fileId } = versionHistoryStore;
const {
versions,
fetchFileVersions,
fileId,
fileAccess,
} = versionHistoryStore;
return {
culture: auth.settingsStore.culture,
isLoading,
versions,
fileId,
fileAccess,
setFirstLoad,
setIsLoading,
fetchFileVersions,

View File

@ -67,6 +67,20 @@ class AccessRightsStore {
return getFileRoleActions(access).block;
}
canChangeVersionHistory = (file) => {
const { rootFolderType, editing, providerKey, access } = file;
if (
rootFolderType === FolderType.Archive ||
rootFolderType === FolderType.TRASH ||
editing ||
providerKey
)
return false;
return getFileRoleActions(access).changeVersionHistory;
};
canArchiveRoom = (room) => {
const { archive } = getRoomRoleActions(room.access);

View File

@ -489,7 +489,7 @@ class ContextOptionsStore {
key: "show-version-history",
label: t("ShowVersionHistory"),
icon: "images/history.react.svg",
onClick: () => this.showVersionHistory(item.id),
onClick: () => this.showVersionHistory(item.id, item.access),
disabled: false,
},
]
@ -503,14 +503,15 @@ class ContextOptionsStore {
key: "finalize-version",
label: t("FinalizeVersion"),
icon: "images/history-finalized.react.svg",
onClick: () => this.finalizeVersion(item.id),
onClick: () => this.finalizeVersion(item.id, item.access),
disabled: false,
},
{
key: "show-version-history",
label: t("ShowVersionHistory"),
icon: "images/history.react.svg",
onClick: () => this.showVersionHistory(item.id),
onClick: () =>
this.showVersionHistory(item.id, item.access),
disabled: false,
},
],
@ -528,7 +529,7 @@ class ContextOptionsStore {
key: "show-version-history",
label: t("ShowVersionHistory"),
icon: "images/history.react.svg",
onClick: () => this.showVersionHistory(item.id),
onClick: () => this.showVersionHistory(item.id, item.access),
disabled: false,
},
]

View File

@ -1053,7 +1053,10 @@ class FilesStore {
if (isFile) {
const shouldFillForm = canFormFillingDocs(item.fileExst);
const isCanLockFile = this.accessRightsStore.canLockFile;
const canLockFile = this.accessRightsStore.canLockFile;
const canChangeVersionHistory = this.accessRightsStore.canChangeVersionHistory(
{ ...item, ...{ editing: isEditing } }
);
const isMasterForm = item.fileExst === ".docxf";
@ -1096,12 +1099,16 @@ class FilesStore {
"delete",
];
if (!isCanLockFile) {
if (!canLockFile) {
fileOptions = this.removeOptions(fileOptions, [
"block-unblock-version",
]);
}
if (!canChangeVersionHistory) {
fileOptions = this.removeOptions(fileOptions, ["finalize-version"]);
}
if (!filesRights.edit) {
fileOptions = this.removeOptions(fileOptions, ["edit"]);
}
@ -1116,9 +1123,9 @@ class FilesStore {
if (!filesRights.viewVersionHistory) {
fileOptions = this.removeOptions(fileOptions, ["show-version-history"]);
}
if (!filesRights.changeVersionHistory) {
fileOptions = this.removeOptions(fileOptions, ["finalize-version"]);
}
// if (!filesRights.changeVersionHistory) {
// fileOptions = this.removeOptions(fileOptions, ["finalize-version"]);
// }
if (!filesRights.deleteSelf || !filesRights.deleteAlien) {
fileOptions = this.removeOptions(fileOptions, ["delete"]);
}
@ -1161,7 +1168,7 @@ class FilesStore {
"rename",
"separator2",
"delete",
"finalize-version",
//"finalize-version",
]);
}
@ -1191,7 +1198,7 @@ class FilesStore {
if (isEditing) {
fileOptions = this.removeOptions(fileOptions, [
"finalize-version",
// "finalize-version",
"move-to",
"separator2",
"delete",
@ -1235,7 +1242,7 @@ class FilesStore {
"send-by-email",
//"block-unblock-version", //need split
"version", //category
"finalize-version",
//"finalize-version",
"copy-to",
"copy",
"mark-as-favorite",
@ -1276,8 +1283,8 @@ class FilesStore {
"send-by-email",
//"block-unblock-version", //need split
"version", //category
"finalize-version",
"show-version-history",
//"finalize-version",
//"show-version-history",
"move", //category
"move-to",
"copy-to",
@ -1311,7 +1318,7 @@ class FilesStore {
if (isThirdPartyItem) {
fileOptions = this.removeOptions(fileOptions, [
"owner-change",
"finalize-version",
//"finalize-version",
"copy",
]);
}

View File

@ -6,6 +6,7 @@ import { FileStatus } from "@docspace/common/constants";
class VersionHistoryStore {
isVisible = false;
fileId = null;
fileAccess = null;
versions = null;
filesStore = null;
showProgressBar = false;
@ -61,7 +62,9 @@ class VersionHistoryStore {
setVerHistoryFileId = (fileId) => {
this.fileId = fileId;
};
setVerHistoryFileAccess = (access) => {
this.fileAccess = access;
};
setVersions = (versions) => {
this.versions = versions;
};
@ -90,9 +93,11 @@ class VersionHistoryStore {
this.versions = versions;
};
fetchFileVersions = (fileId) => {
fetchFileVersions = (fileId, access) => {
if (this.fileId !== fileId || !this.versions) {
this.setVerHistoryFileId(fileId);
this.setVerHistoryFileAccess(access);
return api.files
.getFileVersionInfo(fileId)
.then((versions) => this.setVerHistoryFileVersions(versions));