-
Notifications
You must be signed in to change notification settings - Fork 68
Master lock sheet rar #7264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Master lock sheet rar #7264
Changes from all commits
a4e2446
a4ec9b9
b8de834
3c79c8e
93ba8f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { _t } from "../../translation"; | ||
| import { Command, CommandResult, lockedSheetAllowedCommands } from "../../types/commands"; | ||
| import { UIPlugin } from "../ui_plugin"; | ||
|
|
||
| export class LockSheetPlugin extends UIPlugin { | ||
| static getters = ["isCurrentSheetLocked"] as const; | ||
|
|
||
| allowDispatch(cmd: Command): CommandResult | CommandResult[] { | ||
| /** | ||
| * isDashboard() implies that the user is not connected | ||
| * to other users and can do any operation and can do core modifications that will only affect them | ||
| * It is acceptable to bypass the locked sheet restriction in this case | ||
| */ | ||
|
Comment on lines
+9
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't we way that we would add a commit to ensure that ? we can have a dashboard mode with still a collaborative session |
||
| if (lockedSheetAllowedCommands.has(cmd.type) || this.getters.isDashboard()) { | ||
| return CommandResult.Success; | ||
| } | ||
| if ( | ||
| ("sheetId" in cmd && this.getters.isSheetLocked(cmd.sheetId)) || | ||
| this.getters.isSheetLocked(this.getters.getActiveSheetId()) | ||
| ) { | ||
| this.ui.notifyUI({ | ||
| type: "info", | ||
| text: _t("This sheet is locked and cannot be modified. Please unlock it first."), | ||
| sticky: false, | ||
| }); | ||
| return CommandResult.SheetLocked; | ||
| } | ||
| return CommandResult.Success; | ||
| } | ||
|
|
||
| isCurrentSheetLocked() { | ||
| return this.getters.isSheetLocked(this.getters.getActiveSheetId()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,9 +59,7 @@ export interface SheetDependentCommand { | |
| sheetId: UID; | ||
| } | ||
|
|
||
| export function isSheetDependent( | ||
| cmd: CoreCommand | ||
| ): cmd is Extract<CoreCommand, SheetDependentCommand> { | ||
| export function isSheetDependent(cmd: Command): cmd is Extract<CoreCommand, SheetDependentCommand> { | ||
| return "sheetId" in cmd; | ||
| } | ||
|
|
||
|
|
@@ -221,6 +219,36 @@ export const readonlyAllowedCommands = new Set<CommandTypes>([ | |
| "UPDATE_PIVOT", | ||
| ]); | ||
|
|
||
| export const lockedSheetAllowedCommands = new Set<Command["type"]>([ | ||
| "LOCK_SHEET", | ||
| "UNLOCK_SHEET", | ||
| "UPDATE_LOCALE", | ||
| "MOVE_SHEET", | ||
| "DUPLICATE_SHEET", | ||
| "CREATE_SHEET", | ||
| "COPY", | ||
| "START", | ||
| "SCROLL_TO_CELL", | ||
| "ACTIVATE_SHEET", | ||
| "RESIZE_SHEETVIEW", | ||
| "SET_VIEWPORT_OFFSET", | ||
| "SET_FORMULA_VISIBILITY", | ||
| "SELECT_FIGURE", // not sure | ||
| "EVALUATE_CHARTS", | ||
| "EVALUATE_CELLS", | ||
| "UNDO", | ||
| "REDO", | ||
| "REQUEST_UNDO", | ||
| "REQUEST_REDO", | ||
| "REPLACE_SEARCH", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. allowing replace on a locked sheet is strange. Does the command contains the sheetId if we replace on all sheet?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the plugin computes all positions eligible for a replace and will skip the ones on a locked sheet, the same it skips the cells which contain a formula and for which we don't specify the |
||
| "HIDE_SHEET", | ||
| "SHOW_SHEET", | ||
| "UPDATE_PIVOT", | ||
| "INSERT_NEW_PIVOT", | ||
| "ADD_PIVOT", | ||
| "REMOVE_PIVOT", | ||
|
Comment on lines
+246
to
+249
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are those even sheet dependent ? |
||
| ]); | ||
|
|
||
| export const coreTypes = new Set<CoreCommandTypes>([ | ||
| /** CELLS */ | ||
| "UPDATE_CELL", | ||
|
|
@@ -255,6 +283,8 @@ export const coreTypes = new Set<CoreCommandTypes>([ | |
| "COLOR_SHEET", | ||
| "HIDE_SHEET", | ||
| "SHOW_SHEET", | ||
| "LOCK_SHEET", | ||
| "UNLOCK_SHEET", | ||
|
|
||
| /** RANGES MANIPULATION */ | ||
| "MOVE_RANGES", | ||
|
|
@@ -834,6 +864,14 @@ export interface RemoveDataValidationCommand extends SheetDependentCommand { | |
| id: string; | ||
| } | ||
|
|
||
| export interface LockSheetCommand extends SheetDependentCommand { | ||
| type: "LOCK_SHEET"; | ||
| } | ||
|
|
||
| export interface UnlockSheetCommand extends SheetDependentCommand { | ||
| type: "UNLOCK_SHEET"; | ||
| } | ||
|
|
||
| //#endregion | ||
|
|
||
| //#region Local Commands | ||
|
|
@@ -1164,6 +1202,8 @@ export type CoreCommand = | |
| | ColorSheetCommand | ||
| | HideSheetCommand | ||
| | ShowSheetCommand | ||
| | LockSheetCommand | ||
| | UnlockSheetCommand | ||
|
|
||
| /** RANGES MANIPULATION */ | ||
| | MoveRangeCommand | ||
|
|
@@ -1462,6 +1502,7 @@ export const enum CommandResult { | |
| InvalidPivotCustomField = "InvalidPivotCustomField", | ||
| MissingFigureArguments = "MissingFigureArguments", | ||
| InvalidCarouselItem = "InvalidCarouselItem", | ||
| SheetLocked = "SheetLocked", | ||
| } | ||
|
|
||
| export interface CommandHandler<T> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo in commit message