Skip to content

Commit 68224aa

Browse files
committed
feat: allow editing of files via web application
First pass - probably needs a bit more work around the use case where a CSP file changes. (Theory: call OnBeforeTimestamp / OnBeforeLoad at end of AfterUserAction if the name is mapped?)
1 parent 9950f6a commit 68224aa

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

cls/SourceControl/Git/Settings.cls

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ Property defaultMergeBranch As %String [ InitialExpression = {##class(SourceCont
4747
/// Compile using the configured pull event handler when "Import All" is run
4848
Property compileOnImport As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).CompileOnImport()} ];
4949

50+
/// Define a namespace-level web application allowing access to multiple git repos across separate namespaces
51+
Property namespaceLevelGitWebApp As %Boolean [ InitialExpression = {##class(SourceControl.Git.Settings).HasNamespaceWebApp()} ];
52+
5053
Property Mappings [ MultiDimensional ];
5154

5255
Method %OnNew() As %Status
@@ -160,6 +163,75 @@ ClassMethod Configure() As %Boolean [ CodeMode = objectgenerator ]
160163
do %code.WriteLine(" quit 1")
161164
}
162165

166+
Method ConfigureNamespaceWebApplication()
167+
{
168+
Set root = ##class(%Library.File).NormalizeDirectory(##class(SourceControl.Git.Utils).TempFolder())
169+
Set deleteWebApp = ..HasNamespaceWebApp(.appDirectory) && '..namespaceLevelGitWebApp
170+
Set createWebApp = ..namespaceLevelGitWebApp && '..HasNamespaceWebApp()
171+
Do ..WebAppOperation("/git/"_$Namespace_"/", createWebApp, deleteWebApp, root)
172+
}
173+
174+
Method WebAppOperation(name, create As %Boolean, delete As %Boolean, root As %String) [ Private ]
175+
{
176+
Set namespace = $Namespace
177+
New $Namespace
178+
Set $Namespace = "%SYS"
179+
If $Extract(name) = "/" {
180+
Set name = $Extract(name,1,*-1)
181+
}
182+
If delete {
183+
If ##class(Security.Applications).Exists(name) {
184+
$$$ThrowOnError(##class(Security.Applications).Delete(name))
185+
Write !,"Removed web application "_name
186+
}
187+
Quit
188+
}
189+
190+
// These are the only things we want to coerce.
191+
Set props("AutheEnabled")=0 // No auth methods enabled = impossible to use
192+
Set props("InbndWebServicesEnabled")=0
193+
Set props("ServeFiles")=0
194+
Set props("Enabled")=1
195+
Set props("Name")=name
196+
Set props("NameSpace")=namespace
197+
Set props("Path")=root
198+
Set props("Type")=2
199+
Set props("Recurse")=1
200+
If create {
201+
Write !,"Creating web application: "_name_"... "
202+
$$$ThrowOnError(##class(Security.Applications).Create(name,.props))
203+
Write "done."
204+
} ElseIf ##class(Security.Applications).Exists(name) {
205+
Write !,"Web application '"_name_"' already exists."
206+
$$$ThrowOnError(##class(Security.Applications).Get(name,.existingProps))
207+
Set changes = 0
208+
Set key = ""
209+
For {
210+
Set key = $Order(props(key),1,value)
211+
Quit:key=""
212+
If (value '= $Get(existingProps(key))) {
213+
Write !,"Changing "_key_": "_$Get(existingProps(key))_" -> "_value
214+
Set changes = 1
215+
}
216+
}
217+
If changes {
218+
$$$ThrowOnError(##class(Security.Applications).Modify(name,.props))
219+
Write !,"Web application '"_name_"' updated."
220+
} Else {
221+
Write !,"No changes made to web application."
222+
}
223+
}
224+
}
225+
226+
ClassMethod HasNamespaceWebApp(Output webAppDirectory) As %Boolean
227+
{
228+
Set webAppDirectory = $System.CSP.GetFileName("/git/"_$Namespace_"/")
229+
If (webAppDirectory '= "") {
230+
Set webAppDirectory = ##class(%Library.File).NormalizeDirectory(webAppDirectory)
231+
}
232+
Quit (webAppDirectory '= "")
233+
}
234+
163235
Method OnAfterConfigure() As %Boolean
164236
{
165237
set defaultPromptFlag = $$$DisableBackupCharMask + $$$TrapCtrlCMask + $$$EnableQuitCharMask + $$$DisableHelpCharMask + $$$DisableHelpContextCharMask + $$$TrapErrorMask
@@ -186,6 +258,8 @@ Method OnAfterConfigure() As %Boolean
186258
}
187259
}
188260

261+
do ..ConfigureNamespaceWebApplication()
262+
189263
set gitDir = ##class(%File).NormalizeDirectory(..namespaceTemp)_".git"
190264
if '##class(%File).DirectoryExists(gitDir) {
191265
set list(1) = "Initialize empty repo"

cls/SourceControl/Git/Utils.cls

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,13 @@ ClassMethod NormalizeInternalName(ByRef name As %String) As %String
11321132
if ($extract(name) '= "/") && (type'="csp") {
11331133
quit $piece(name,".",1,*-1)_"."_$zconvert($piece(name,".",*),"U")
11341134
}
1135+
1136+
if (name [ "/") && (type = "csp") {
1137+
set cspFilename = $System.CSP.GetFileName(name)
1138+
if (cspFilename '= "") && (cspFilename [ ..TempFolder()) {
1139+
set name = ..NameToInternalName(cspFilename)
1140+
}
1141+
}
11351142

11361143
if (type = "inc") || (type = "mac") || (type = "int") {
11371144
set name = $extract($translate(name, "/", "."), 2, *)

0 commit comments

Comments
 (0)