Skip to content

Commit 081007d

Browse files
committed
delete-enable in settings file
1 parent 37edab2 commit 081007d

File tree

3 files changed

+152
-46
lines changed

3 files changed

+152
-46
lines changed

src/cls/ZPM/Registry.cls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ ClassMethod UnPublishPackageVersion(pkg As %String = "", version As %String = ""
177177
If ($$$ISERR(tSC)) {
178178
Return ..ReportHttpStatusCode(..#HTTP401UNAUTHORIZED, tSC)
179179
}
180+
Set settingsFile = ##class(ZPM.Settings).%New()
181+
If ('settingsFile.GetDeleteEnable()) {
182+
Return ..ReportHttpStatusCode(..#HTTP403FORBIDDEN, $$$ERROR(5001,"Delete not allowed for this registry"))
183+
}
180184
Set pkg = $$$lcase(pkg)
181185
Set tSC = ##class(ZPM.Owner).IsOwner(pkg)
182186
If ($$$ISERR(tSC)) {

src/cls/ZPM/Settings.cls

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/// class to work with zpm-registry.yaml - file with settings
2+
/// format of this file
3+
///
4+
/// uplinks:
5+
/// pm:
6+
/// url: https://pm.community.intersystems.com/
7+
/// allow_packages: dsw,zpm*,?u*
8+
/// delete-enabled: true
9+
///
10+
/// or use Namespace at first indent
11+
///
12+
/// USER:
13+
/// delete-enabled: true
14+
/// uplinks:
15+
/// pm:
16+
/// url: https://pm.community.intersystems.com/
17+
/// allow_packages: dsw,zpm*,?u*
18+
///
19+
Class ZPM.Settings Extends %RegisteredObject
20+
{
21+
22+
Parameter Filename = "zpm-registry.yaml";
23+
24+
Property Exists As %Boolean;
25+
26+
Property DateModified As %String;
27+
28+
Property JSON As %DynamicObject;
29+
30+
Method %OnNew() As %Status
31+
{
32+
Set ..Exists = 0
33+
If ##class(%File).Exists(..GetFilename()) {
34+
Set ..Exists = 1
35+
Set file = ##class(%File).%New(..GetFilename())
36+
Set ..DateModified = file.DateModified
37+
Set ..JSON = ##class(YAML.Utils).FileToJSON(..GetFilename(), .sc)
38+
Return sc
39+
} Else {
40+
Kill ^zpmregistry
41+
}
42+
Return $$$OK
43+
}
44+
45+
Method GetFilename() As %String [ CodeMode = expression ]
46+
{
47+
##class(%SYSTEM.Util).InstallDirectory()_..#Filename
48+
}
49+
50+
Method IsModified() As %Boolean
51+
{
52+
If ..Exists = 0 {
53+
Return 0
54+
}
55+
If ($Get(^zpmregistry("filemodified")) = ..DateModified) {
56+
Return 0
57+
}
58+
Return 1
59+
}
60+
61+
Method GetUplinks() As %DynamicObject
62+
{
63+
Set ns = $$$lcase($NAMESPACE)
64+
If ('..Exists) {
65+
Return {}
66+
}
67+
Try {
68+
Set links = {}
69+
Set obj = ..JSON
70+
Set iter = obj.%GetIterator()
71+
While iter.%GetNext(.key , .fns) {
72+
If (ns = $$$lcase(key)) {
73+
// check found object structure
74+
If (..IsUplinkSettingsObject(fns)) {
75+
Set links = fns."uplinks"
76+
Quit
77+
}
78+
}
79+
}
80+
If (links.%Size()=0) {
81+
If (..IsUplinkSettingsObject(obj)) {
82+
Set links = obj."uplinks"
83+
}
84+
}
85+
Return links
86+
} Catch ex {
87+
Do ex.Log()
88+
Set sc = ex.AsStatus()
89+
}
90+
}
91+
92+
Method IsUplinkSettingsObject(obj As %DynamicObject) As %Boolean [ Private ]
93+
{
94+
Try {
95+
If (obj.%GetTypeOf("uplinks")="object") {
96+
Set iter = obj.uplinks.%GetIterator()
97+
If iter.%GetNext(.key , .joOneUplink) {
98+
If (joOneUplink.%IsDefined("url")) {
99+
return 1
100+
}
101+
}
102+
}
103+
} Catch ex {
104+
return 0
105+
}
106+
return 0
107+
}
108+
109+
Method GetDeleteEnable() As %Boolean
110+
{
111+
Set ns = $$$lcase($NAMESPACE)
112+
If ('..Exists) {
113+
Return 0
114+
}
115+
If ( $Data(^zpmregistry(ns,"delete-enabled")) && '..IsModified() ) {
116+
Return $Get(^zpmregistry(ns,"delete-enabled"))
117+
}
118+
Try {
119+
Set obj = ..JSON
120+
Set delete = ""
121+
Set trueList = $ListBuild("y","Y","yes","Yes","YES","true","True","TRUE","on","On","ON","1")
122+
Set iter = obj.%GetIterator()
123+
While iter.%GetNext(.key , .fns) {
124+
If (ns = $$$lcase(key)) {
125+
Set delete = fns."delete-enabled"
126+
Quit
127+
}
128+
}
129+
If (delete = "") {
130+
Set delete = obj."delete-enabled"
131+
}
132+
If ($LISTFIND(trueList,delete)) {
133+
Return 1
134+
}
135+
} Catch ex {
136+
Do ex.Log()
137+
Set sc = ex.AsStatus()
138+
}
139+
Return 0
140+
}
141+
142+
}

src/cls/ZPM/UpLink.cls

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -324,40 +324,17 @@ Method AddPackage(pPackage As %DynamicObject) As %Status
324324
ClassMethod ReadUplinksFromFile() As %Status
325325
{
326326
Set sc = $$$OK
327-
Set tFilename = ##class(%SYSTEM.Util).InstallDirectory()_"zpm-registry.yaml"
328-
If '##class(%File).Exists(tFilename) {
327+
Set settingsFile = ##class(ZPM.Settings).%New()
328+
If ('settingsFile.Exists) {
329329
// if registry config file doesn't exists - remove all uplinks and related cached pakages
330330
&sql(TRUNCATE TABLE ZPM.UpLink)
331331
Return sc
332332
}
333-
Try {
334-
Set tFile = ##class(%File).%New(tFilename)
335-
If ($Get(^zpmregistry("filemodified")) = tFile.DateModified) {
336-
// DateTime hasn't changed - skip file
337-
Return sc
338-
}
339-
set obj = ##class(YAML.Utils).FileToJSON(tFilename, .sc)
340-
341-
$$$ThrowOnError(sc)
342-
Set filemodificationTS = tFile.DateModified
343-
If (..IsDefaultConfig(obj)) {
344-
// namespace doesn't specified
345-
Do ..SaveUplinks(obj."uplinks", filemodificationTS)
346-
} Else{
347-
// namespace specified - search for current ns settings
348-
Set iter = obj.%GetIterator()
349-
Set ns = $$$lcase($NAMESPACE)
350-
While iter.%GetNext(.key , .uplinks) {
351-
If (ns = $$$lcase(key)) {
352-
Do ..SaveUplinks(uplinks."uplinks", filemodificationTS)
353-
}
354-
}
355-
}
356-
} Catch ex {
357-
do ex.Log()
358-
Set sc = ex.AsStatus()
333+
If 'settingsFile.IsModified() {
334+
// File hasn't changed - skip file
335+
Return sc
359336
}
360-
Return sc
337+
Return ..SaveUplinks(settingsFile.GetUplinks(), settingsFile.DateModified)
361338
}
362339

363340
ClassMethod SaveUplinks(joUplinks As %DynamicObject, filemodificationTS As %String) As %Status
@@ -373,23 +350,6 @@ ClassMethod SaveUplinks(joUplinks As %DynamicObject, filemodificationTS As %Stri
373350
quit $$$OK
374351
}
375352

376-
ClassMethod IsDefaultConfig(obj As %DynamicObject) As %Boolean
377-
{
378-
Try {
379-
If (obj.%GetTypeOf("uplinks")="object") {
380-
Set iter = obj.uplinks.%GetIterator()
381-
If iter.%GetNext(.key , .joOneUplink) {
382-
If (joOneUplink.%IsDefined("url")) {
383-
return 1
384-
}
385-
}
386-
}
387-
} Catch ex {
388-
return 0
389-
}
390-
return 0
391-
}
392-
393353
ClassMethod AddUplink(name, url, allowList, position) As %Status
394354
{
395355
If (url = "") { return 0 }

0 commit comments

Comments
 (0)