Skip to content

Commit 1eeefef

Browse files
committed
prevent deletion in locked environment
1 parent 9fe0be6 commit 1eeefef

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

cls/SourceControl/Git/Extension.cls

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
4747
if Type = 1, Name = 5 {
4848
// reroute to Status menu option
4949
set Name = "%SourceMenu,Status"
50-
}
50+
}
5151

5252
#dim ec as %Status = $$$OK
5353
#dim menu as %Status = $piece(Name, ",", 1)
@@ -253,13 +253,21 @@ InternalName'="" && ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInt
253253
/// Called before an item is deleted.
254254
Method OnBeforeDelete(InternalName As %String) As %Status
255255
{
256-
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
257-
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
258-
set Filename = ##class(Utils).FullExternalName(InternalName)
259-
if ##class(Utils).IsInSourceControl(InternalName) {
260-
quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName)
256+
if ..IsReadOnly(InternalName) {
257+
set ^mtempVG("dbg",$i(^mtempVG)) = "readonly"
258+
// throw error if deleting readonly item
259+
Throw ##class(%Exception.General).%New("Can't delete in locked environment")
260+
} else {
261+
set ^mtempVG("dbg",$i(^mtempVG)) = "not readonly"
262+
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
263+
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
264+
set Filename = ##class(Utils).FullExternalName(InternalName)
265+
if ##class(Utils).IsInSourceControl(InternalName) {
266+
quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName)
267+
}
268+
quit $$$OK
261269
}
262-
quit $$$OK
270+
set ^mtempVG("dbg",$i(^mtempVG)) = "outside, after if readonly"
263271
}
264272

265273
/// Called after an item is deleted.

test/UnitTest/SourceControl/Git/AddRemove.cls

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ Import SourceControl.Git
33
Class UnitTest.SourceControl.Git.AddRemove Extends %UnitTest.TestCase
44
{
55

6+
Method TestReadonlyDelete()
7+
{
8+
new %SourceControl
9+
do ##class(%Studio.SourceControl.Interface).SourceControlCreate()
10+
do ##class(API).Lock()
11+
try {
12+
do %SourceControl.OnBeforeDelete("")
13+
do $$$AssertFailure("No error thrown when deleting in locked environment")
14+
} catch e {
15+
do $$$AssertEquals(e.Name,"Can't delete in locked environment")
16+
}
17+
do ##class(API).Unlock()
18+
}
19+
620
Method TestInit()
721
{
822
new %SourceControl

0 commit comments

Comments
 (0)