Skip to content

Commit 1e33bdd

Browse files
committed
Merge pull request #55 from intersystems-ru/roles-access-161
Websockets webapp now works on Cache 16.1+ Normal installs
2 parents 2b002a7 + 15661aa commit 1e33bdd

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

export/WebTerminal/Installer.xml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2016.2 (Build 559U)" ts="2016-02-06 20:50:57">
2+
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.1.1 (Build 505U)" ts="2016-02-15 12:28:08">
33
<Class name="WebTerminal.Installer">
44
<Description>
55
Importing this class will install Cache WEB Terminal properly.</Description>
66
<Super>%Projection.AbstractProjection</Super>
7-
<TimeChanged>63954,74786.153524</TimeChanged>
7+
<TimeChanged>63963,44872.55628</TimeChanged>
88
<TimeCreated>63890,71053.144208</TimeCreated>
99
<DependsOn>Common,Engine,Router,StaticContent,Autocomplete,Trace</DependsOn>
1010

@@ -72,6 +72,7 @@ This method is invoked when a class is compiled.</Description>
7272
write !, "Installing WebTerminal application to " _ $NAMESPACE
7373
set ns = $NAMESPACE // ought to be package home namespace!
7474
set ^WebTerminal("HomeNamespace") = ns
75+
set dbdir = $$$defdir
7576
zn:ns'="%SYS" "%SYS"
7677
do ##class(Security.System).GetInstallationSecuritySetting(.security)
7778
set cspProperties("AutheEnabled") = 32 // password by default, 64 for no password
@@ -83,6 +84,8 @@ This method is invoked when a class is compiled.</Description>
8384
set cspProperties("AutheEnabled") = 64
8485
set cspProperties("Description") = "An application representing the open socket for /terminal application. Required since 2016.* Cache versions changed WebSocket behavior. PLEASE LEAVE THIS APPLICATION UNAUTHENTICATED, but do not worry: the socket won't accept anyone without the key."
8586
set cspProperties("DispatchClass") = ""
87+
set role = ..GetDBRole(dbdir)
88+
set cspProperties("MatchRoles")=":%DB_CACHESYS" _ $case($get(role)'="", 1: ":"_role, :"")
8689
do ..RegisterWebApplication("/terminalsocket", .cspProperties)
8790
set status = ##Class(Config.Namespaces).Get("%All")
8891
if ($$$ISERR(status)) { // no namespace %All
@@ -131,8 +134,9 @@ This method is invoked when a class is 'uncompiled'.</Description>
131134
write !, "Uninstalling WebTerminal application from " _ $NAMESPACE
132135
set ns = $NAMESPACE // has to be package home namespace!
133136
if ($get(^WebTerminal("HomeNamespace")) = "") {
134-
write "Terminal home namespace is not defined! Uninstalling will be skipped."
135-
quit '$$$OK
137+
set msg = "Please, set ^WebTerminal(""HomeNamespace"") global equal to " _
138+
"the namespace WebTerminal was installed to before uninstalling."
139+
quit $$$ERROR($$$GeneralError, msg)
136140
} else {
137141
set ns = ^WebTerminal("HomeNamespace")
138142
}
@@ -157,5 +161,25 @@ This method is invoked when a class is 'uncompiled'.</Description>
157161
QUIT $$$OK
158162
]]></Implementation>
159163
</Method>
164+
165+
<Method name="GetDBRole">
166+
<ClassMethod>1</ClassMethod>
167+
<FormalSpec>directory:%String</FormalSpec>
168+
<ReturnType>%String</ReturnType>
169+
<Implementation><![CDATA[
170+
quit:'$d(directory) ""
171+
new $NAMESPACE
172+
set $Namespace = "%SYS"
173+
#dim db As SYS.Database
174+
set db=##class(SYS.Database).%OpenId(directory)
175+
if $Isobject(db) {
176+
set resource = db.ResourceName
177+
set role = resource // I'm assuming that default role exists
178+
} else {
179+
set role = ""
180+
}
181+
quit role
182+
]]></Implementation>
183+
</Method>
160184
</Class>
161185
</Export>

0 commit comments

Comments
 (0)