Skip to content

Commit

Permalink
prevent deletion in locked environment
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-vgao committed Dec 22, 2023
1 parent 9fe0be6 commit 1eeefef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
22 changes: 15 additions & 7 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
if Type = 1, Name = 5 {
// reroute to Status menu option
set Name = "%SourceMenu,Status"
}
}

#dim ec as %Status = $$$OK
#dim menu as %Status = $piece(Name, ",", 1)
Expand Down Expand Up @@ -253,13 +253,21 @@ InternalName'="" && ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInt
/// Called before an item is deleted.
Method OnBeforeDelete(InternalName As %String) As %Status
{
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
set Filename = ##class(Utils).FullExternalName(InternalName)
if ##class(Utils).IsInSourceControl(InternalName) {
quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName)
if ..IsReadOnly(InternalName) {
set ^mtempVG("dbg",$i(^mtempVG)) = "readonly"
// throw error if deleting readonly item
Throw ##class(%Exception.General).%New("Can't delete in locked environment")
} else {
set ^mtempVG("dbg",$i(^mtempVG)) = "not readonly"
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
set Filename = ##class(Utils).FullExternalName(InternalName)
if ##class(Utils).IsInSourceControl(InternalName) {
quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName)
}
quit $$$OK
}
quit $$$OK
set ^mtempVG("dbg",$i(^mtempVG)) = "outside, after if readonly"
}

/// Called after an item is deleted.
Expand Down
14 changes: 14 additions & 0 deletions test/UnitTest/SourceControl/Git/AddRemove.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ Import SourceControl.Git
Class UnitTest.SourceControl.Git.AddRemove Extends %UnitTest.TestCase
{

Method TestReadonlyDelete()
{
new %SourceControl
do ##class(%Studio.SourceControl.Interface).SourceControlCreate()
do ##class(API).Lock()
try {
do %SourceControl.OnBeforeDelete("")
do $$$AssertFailure("No error thrown when deleting in locked environment")
} catch e {
do $$$AssertEquals(e.Name,"Can't delete in locked environment")
}
do ##class(API).Unlock()
}

Method TestInit()
{
new %SourceControl
Expand Down

0 comments on commit 1eeefef

Please sign in to comment.