Skip to content

Commit

Permalink
Merge pull request 'fix/permissions' (#574) from fix/permissions into…
Browse files Browse the repository at this point in the history
… release/v8.3.0
  • Loading branch information
KirillovIlya committed Jan 28, 2025
2 parents 7fb3cae + 11bbc6e commit 48e907e
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 51 deletions.
31 changes: 30 additions & 1 deletion common/apiCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,6 @@ function (window, undefined) {
this.CanEditBlockCC = undefined !== obj.CanEditBlockCC ? obj.CanEditBlockCC : true;
this.CanDeleteInlineCC = undefined !== obj.CanDeleteInlineCC ? obj.CanDeleteInlineCC : true;
this.CanEditInlineCC = undefined !== obj.CanEditInlineCC ? obj.CanEditInlineCC : true;

}
else {
//ContextualSpacing : false, // Удалять ли интервал между параграфами одинакового стиля
Expand Down Expand Up @@ -6010,6 +6009,30 @@ function (window, undefined) {
CDocInfoProp.prototype.put_SymbolsWSCount = function (v) {
this.SymbolsWSCount = v;
};

/**
* @constructor
*/
function RangePermProp(obj) {
if (obj) {
this.editText = undefined !== obj.editText ? obj.editText : true;
this.editParagraph = undefined !== obj.editParagraph ? obj.editParagraph : true;
this.insertObject = undefined !== obj.insertObject ? obj.insertObject : true;
} else {
this.editText = true;
this.editParagraph = true;
this.insertObject = true;
}
}
RangePermProp.prototype.get_canEditText = function() {
return this.editText;
};
RangePermProp.prototype.get_canEditPara = function() {
return this.editParagraph;
};
RangePermProp.prototype.get_canInsObject = function() {
return this.insertObject;
};

/*
* Export
Expand Down Expand Up @@ -7039,6 +7062,12 @@ function (window, undefined) {
CDocInfoProp.prototype['get_SymbolsWSCount'] = CDocInfoProp.prototype.get_SymbolsWSCount;
CDocInfoProp.prototype['put_SymbolsWSCount'] = CDocInfoProp.prototype.put_SymbolsWSCount;

window["Asc"]["RangePermProp"] = window["Asc"].RangePermProp = RangePermProp;
prot = RangePermProp.prototype;
prot["get_canEditText"] = prot.get_canEditText;
prot["get_canEditPara"] = prot.get_canEditPara;
prot["get_canInsObject"] = prot.get_canInsObject;

window["AscCommon"]["pix2mm"] = window["AscCommon"].pix2mm = function(pix)
{
return pix * AscCommon.g_dKoef_pix_to_mm;
Expand Down
66 changes: 35 additions & 31 deletions common/commonDefines.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,21 +694,22 @@ window.AscCommon.g_cIsBeta = "false";
};

var c_oAscTypeSelectElement = {
Paragraph : 0,
Table : 1,
Image : 2,
Header : 3,
Hyperlink : 4,
SpellCheck : 5,
Shape : 6,
Slide : 7,
Chart : 8,
Math : 9,
MailMerge : 10,
ContentControl : 11,
Animation : 12,
Text : 13, // viewer
Annot : 14
Paragraph : 0,
Table : 1,
Image : 2,
Header : 3,
Hyperlink : 4,
SpellCheck : 5,
Shape : 6,
Slide : 7,
Chart : 8,
Math : 9,
MailMerge : 10,
ContentControl : 11,
Animation : 12,
Text : 13, // viewer
Annot : 14,
UnProtectedRegion : 15
};

var c_oAscLineDrawingRule = {
Expand Down Expand Up @@ -4732,22 +4733,25 @@ window.AscCommon.g_cIsBeta = "false";
prot['BringForward'] = prot.BringForward;
prot['SendBackward'] = prot.SendBackward;
window['Asc']['c_oAscTypeSelectElement'] = window['Asc'].c_oAscTypeSelectElement = c_oAscTypeSelectElement;
prot = c_oAscTypeSelectElement;
prot['Paragraph'] = prot.Paragraph;
prot['Table'] = prot.Table;
prot['Image'] = prot.Image;
prot['Header'] = prot.Header;
prot['Hyperlink'] = prot.Hyperlink;
prot['SpellCheck'] = prot.SpellCheck;
prot['Shape'] = prot.Shape;
prot['Slide'] = prot.Slide;
prot['Chart'] = prot.Chart;
prot['Math'] = prot.Math;
prot['MailMerge'] = prot.MailMerge;
prot['ContentControl'] = prot.ContentControl;
prot['Animation'] = prot.Animation;
prot['Text'] = prot.Text;
prot['Annot'] = prot.Annot;

prot = c_oAscTypeSelectElement;
prot['Paragraph'] = prot.Paragraph;
prot['Table'] = prot.Table;
prot['Image'] = prot.Image;
prot['Header'] = prot.Header;
prot['Hyperlink'] = prot.Hyperlink;
prot['SpellCheck'] = prot.SpellCheck;
prot['Shape'] = prot.Shape;
prot['Slide'] = prot.Slide;
prot['Chart'] = prot.Chart;
prot['Math'] = prot.Math;
prot['MailMerge'] = prot.MailMerge;
prot['ContentControl'] = prot.ContentControl;
prot['Animation'] = prot.Animation;
prot['Text'] = prot.Text;
prot['Annot'] = prot.Annot;
prot['UnProtectedRegion'] = prot.UnProtectedRegion;

window['Asc']['linerule_AtLeast'] = window['Asc'].linerule_AtLeast = linerule_AtLeast;
window['Asc']['linerule_Auto'] = window['Asc'].linerule_Auto = linerule_Auto;
window['Asc']['linerule_Exact'] = window['Asc'].linerule_Exact = linerule_Exact;
Expand Down
2 changes: 2 additions & 0 deletions common/errorCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
MustIntegerOrDecimalNumber: 1070,

DocumentAndChangeMismatch: 1080,
EditProtectedRange : 1081,


// pdf forms
Expand Down Expand Up @@ -442,6 +443,7 @@
prot['TracePrecedentsNoValidReference'] = prot.TracePrecedentsNoValidReference;
prot['MustIntegerOrDecimalNumber'] = prot.MustIntegerOrDecimalNumber;
prot['DocumentAndChangeMismatch'] = prot.DocumentAndChangeMismatch;
prot['EditProtectedRange'] = prot.EditProtectedRange;
prot['PDFFormsLocked'] = prot.PDFFormsLocked;


Expand Down
113 changes: 95 additions & 18 deletions word/Editor/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -12277,6 +12277,7 @@ CDocument.prototype.private_UpdateInterface = function(isSaveCurrentReviewChange
// Уберем из интерфейса записи о том где мы находимся (параграф, таблица, картинка или колонтитул)
oApi.ClearPropObjCallback();

this.UpdateInterfaceRangePermPr();
this.Controller.UpdateInterfaceState();

// Сообщаем, что список составлен
Expand All @@ -12290,6 +12291,23 @@ CDocument.prototype.private_UpdateInterface = function(isSaveCurrentReviewChange
this.UpdateStylePanel();
this.UpdateNumberingPanel();
};
CDocument.prototype.UpdateInterfaceRangePermPr = function()
{
if (!this.IsViewModeInEditor() && !this.IsEditCommentsMode())
return;

let api = this.GetApi();
if (!api)
return;

let pr = new Asc.RangePermProp();

pr.editText = this.IsPermRangeEditing(AscCommon.changestype_Paragraph_Content);
pr.editParagraph = this.IsPermRangeEditing(AscCommon.changestype_Paragraph_Properties);
pr.insertObject = this.IsPermRangeEditing(AscCommon.changestype_Paragraph_Content);

api.sync_RangePermPropCallback(pr);
};
CDocument.prototype.private_UpdateRulers = function()
{
if (true === this.TurnOffInterfaceEvents)
Expand Down Expand Up @@ -13425,11 +13443,19 @@ CDocument.prototype.IsCursorInHyperlink = function(bCheckEnd)
* @param [isIgnoreCanEditFlag=false]
* @param [checkType=undefined]
* @param [additionalData=undefined]
* @param [sendEvent=false]
* @returns {boolean}
*/
CDocument.prototype.CanPerformAction = function(isIgnoreCanEditFlag, checkType, additionalData)
CDocument.prototype.CanPerformAction = function(isIgnoreCanEditFlag, checkType, additionalData, sendEvent)
{
return (this.IsPermRangeEditing(checkType, additionalData) || !((!this.CanEdit() && true !== isIgnoreCanEditFlag) || (true === this.CollaborativeEditing.Get_GlobalLock())));
let isPermRange = this.IsPermRangeEditing(checkType, additionalData);
if (sendEvent)
{
if (!isPermRange && this.IsNeedNotificationOnEditProtectedRange(checkType, additionalData))
this.sendEvent("asc_onError", c_oAscError.ID.EditProtectedRange, c_oAscError.Level.NoCritical);
}

return (isPermRange || !((!this.CanEdit() && true !== isIgnoreCanEditFlag) || (true === this.CollaborativeEditing.Get_GlobalLock())));
};
/**
* Проверяем, что действие с заданным типом произойдет в разрешенной области
Expand Down Expand Up @@ -13472,8 +13498,11 @@ CDocument.prototype.IsPermRangeEditing = function(changesType, additionalData)
}
}

if (additionalData)
function checkAdditional(additionalData)
{
if (!additionalData)
return true;

if (AscCommon.changestype_2_InlineObjectMove === additionalData.Type)
{
// TODO: Надо проверить не целиком параграф, а только то место, куда происходит вставка
Expand Down Expand Up @@ -13530,7 +13559,29 @@ CDocument.prototype.IsPermRangeEditing = function(changesType, additionalData)
}
}

return true;
if (!additionalData)
return true;

if (Array.isArray(additionalData))
{
for (let i = 0; i < additionalData.length; ++i)
{
if (!checkAdditional(additionalData[i]))
return false;
}

return true;
}
else
{
return checkAdditional(additionalData);
}
};
CDocument.prototype.IsNeedNotificationOnEditProtectedRange = function(changesType, additionalData)
{
return (AscCommon.changestype_Document_SectPr === changesType
|| AscCommon.changestype_Document_Settings === changesType
|| AscCommon.changestype_HdrFtr === changesType);
};
CDocument.prototype._checkActionForPermRange = function(changesType, additionalData)
{
Expand Down Expand Up @@ -13576,24 +13627,38 @@ CDocument.prototype._checkChangesTypeForPermRangeForSelection = function(changes
};
CDocument.prototype._checkPermRangeForCurrentSelection = function()
{
// TODO: Пока запрещаем любые действия, связанные с выделением автофигур
if (this.IsTextSelectionUse())
let docPosType = this.GetDocPosType();

// TODO: Для сносок нужна отдельная проверка, что сама ссылка на сноску лежит в резрешенном диапазоне
// Диапазоны внутри самих сносок не учитываются
if (docpostype_Footnotes === docPosType || docpostype_Endnotes === docPosType)
return false;

let docContent = this;
if (docPosType === docpostype_HdrFtr)
{
if (true !== this.Selection.Use || this.Controller !== this.LogicDocumentController)
return;
let hdrftr = this.HdrFtr.CurHdrFtr;
if (!hdrftr)
return null;

docContent = hdrftr.GetContent();
}

// TODO: Пока запрещаем любые действия, связанные с выделением автофигур
if (this.IsTextSelectionUse() && this.Selection.Use)
{
// Надо проверить, что у нас начало и конец попали хотя бы в один общий промежуток
let startPos = this.GetContentPosition(true, true);
let endPos = this.GetContentPosition(true, false);
let startPos = docContent.GetContentPosition(true, true);
let endPos = docContent.GetContentPosition(true, false);

let startRanges = this.GetPermRangesByContentPos(startPos);
let endRanges = this.GetPermRangesByContentPos(endPos);
let startRanges = this.GetPermRangesByContentPos(startPos, docContent);
let endRanges = this.GetPermRangesByContentPos(endPos, docContent);
return AscWord.PermRangesManager.isInPermRange(startRanges, endRanges);
}
else if (!this.IsSelectionUse())
{
let currentPos = this.GetContentPosition();
return this.GetPermRangesByContentPos(currentPos).length > 0;
let currentPos = docContent.GetContentPosition();
return this.GetPermRangesByContentPos(currentPos, docContent).length > 0;
}

return false;
Expand All @@ -13613,7 +13678,7 @@ CDocument.prototype.Document_Is_SelectionLocked = function(CheckType, Additional
if (this.IsActionStarted() && this.IsPostActionLockCheck())
return false;

if (!this.CanPerformAction(isIgnoreCanEditFlag, CheckType, AdditionalData))
if (!this.CanPerformAction(isIgnoreCanEditFlag, CheckType, AdditionalData, true))
{
if (fCallback)
fCallback(true);
Expand Down Expand Up @@ -16152,6 +16217,18 @@ CDocument.prototype.SetContentPosition = function(DocPos, Depth, Flag)
if (this.Content[Pos])
this.Content[Pos].SetContentPosition(_DocPos, Depth + 1, _Flag);
};
CDocument.prototype.GetControllerContentPosition = function(isSelection, start, posArray)
{
return this.Controller.GetControllerContentPosition(isSelection, start, posArray);
};
CDocument.prototype.SetControllerContentPosition = function(docPos)
{
return this.Controller.SetControllerContentPosition(docPos);
};
CDocument.prototype.SetControllerContentSelection = function(startPos, endPos)
{
return this.Controller.SetControllerContentSelection(startPos, endPos);
};
CDocument.prototype.GetDocumentPositionFromObject = function(arrPos)
{
if (!arrPos)
Expand Down Expand Up @@ -23901,17 +23978,17 @@ CDocument.prototype.UpdateFields = function(isBySelection)
}

};
CDocument.prototype.GetPermRangesByContentPos = function(docPos)
CDocument.prototype.GetPermRangesByContentPos = function(docPos, docContent)
{
if (!docPos)
return [];

let state = this.SaveDocumentState();

this.SetContentPosition(docPos, 0, 0);
docContent.SetContentPosition(docPos, 0, 0);

let result = [];
let currentParagraph = this.controller_GetCurrentParagraph(true, null);
let currentParagraph = this.GetCurrentParagraph(true, null);
if (currentParagraph)
result = currentParagraph.GetCurrentPermRanges();

Expand Down
16 changes: 15 additions & 1 deletion word/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,9 @@
case c_oAscTypeSelectElement.Header:
oUnkTypeObj = new CHeaderProp(obj);
break;
case Asc.c_oAscTypeSelectElement.UnProtectedRegion:
oUnkTypeObj = new Asc.RangePermProp(obj);
break;
}

var _i = this.SelectedObjectsStack.length - 1;
Expand Down Expand Up @@ -1465,6 +1468,13 @@ background-repeat: no-repeat;\
{
return !!this.WordControl.m_oDrawingDocument.m_oDocumentRenderer;
};

asc_docs_api.prototype.canUndoRedoByRestrictions = function()
{
// В режиме вью можно редактировать в разрешенных областях
return (this.canEdit() || this.isRestrictionComments() || this.isRestrictionForms() || this.isRestrictionView());

};

asc_docs_api.prototype["asc_setViewerThumbnailsZoom"] = function(value) {
if (this.WordControl.m_oDrawingDocument.m_oDocumentRenderer &&
Expand Down Expand Up @@ -2261,7 +2271,6 @@ background-repeat: no-repeat;\
this.sync_PrAlignCallBack(ParaPr.Jc);
this.sync_PrPropCallback(ParaPr);
};

/*----------------------------------------------------------------*/
/*functions for working with clipboard, document*/
asc_docs_api.prototype._printDesktop = function (options)
Expand Down Expand Up @@ -4971,6 +4980,10 @@ background-repeat: no-repeat;\
{
this.sendEvent("asc_onSpaceBetweenPrg");
};
asc_docs_api.prototype.sync_RangePermPropCallback = function(pr)
{
this.sync_ChangeLastSelectedElement(Asc.c_oAscTypeSelectElement.UnProtectedRegion, pr);
};
asc_docs_api.prototype.sync_PrPropCallback = function(prProp)
{
var _len = this.SelectedObjectsStack.length;
Expand Down Expand Up @@ -14412,6 +14425,7 @@ background-repeat: no-repeat;\
asc_docs_api.prototype['sync_KeepLinesCallback'] = asc_docs_api.prototype.sync_KeepLinesCallback;
asc_docs_api.prototype['sync_ShowParaMarksCallback'] = asc_docs_api.prototype.sync_ShowParaMarksCallback;
asc_docs_api.prototype['sync_SpaceBetweenPrgCallback'] = asc_docs_api.prototype.sync_SpaceBetweenPrgCallback;
asc_docs_api.prototype['sync_RangePermPropCallback'] = asc_docs_api.prototype.sync_RangePermPropCallback;
asc_docs_api.prototype['sync_PrPropCallback'] = asc_docs_api.prototype.sync_PrPropCallback;
asc_docs_api.prototype['sync_MathPropCallback'] = asc_docs_api.prototype.sync_MathPropCallback;
asc_docs_api.prototype['sync_EndAddShape'] = asc_docs_api.prototype.sync_EndAddShape;
Expand Down

0 comments on commit 48e907e

Please sign in to comment.