diff --git a/PivotSubscriptions/EventLog.cls b/PivotSubscriptions/EventLog.cls index 185e028..1135c45 100644 --- a/PivotSubscriptions/EventLog.cls +++ b/PivotSubscriptions/EventLog.cls @@ -3,7 +3,7 @@ Class PivotSubscriptions.EventLog Extends %Persistent { /// Event Type covers: create, update, delete, sendSubscription, and tableError -Property EventType As %String(VALUELIST = ",create,update,delete,sendSubscription,tableError"); +Property EventType As %String(VALUELIST = ",create,update,delete,sendSubscription,tableError,unsubscribe"); Property StartTime As %TimeStamp [ InitialExpression = {$zdt($h, 3, 1)} ]; @@ -27,13 +27,18 @@ Property Name As %String(MAXLEN = 100); Property Status As %Status; +Property Subscription As PivotSubscriptions.Subscription; + +Property GUID As %String [ InitialExpression = {$System.Util.CreateGUID()} ]; + /// Takes in info about an Alert Task and logs the information to the TaskLog -ClassMethod CreateEvent(pType, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, ByRef pEvent) As %Status +ClassMethod CreateEvent(pType, pSubscriptionId, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, ByRef pEvent) As %Status { Set tSC=$$$OK Set tEventLog=##class(PivotSubscriptions.EventLog).%New() Set tEventLog.EventType=pType + Do tEventLog.SubscriptionSetObjectId(pSubscriptionId) Set tEventLog.UserName=pUser Set tEventLog.Pivot=pPivot Set tEventLog.Name=pName @@ -90,9 +95,9 @@ ClassMethod DayOfWeekDisplay(pDayOfWeek) As %String [ SqlProc ] Quit pDayOfWeek } -Query GetEvents() As %SQLQuery +Query GetEventsForUI() As %SQLQuery { - SELECT StartTime,EndTime,EventType,Name,Pivot,UserName,PivotSubscriptions.EventLog_DayOfWeekDisplay(DayOfWeek) As DayOfWeek,Format,"Hour","Minute",Emails,Status + SELECT ID As Details,StartTime,EndTime,EventType,Username,Name,Emails,Status FROM PivotSubscriptions.EventLog ORDER BY ID DESC } @@ -142,6 +147,12 @@ Storage Default Status + +Subscription + + +GUID + ^PivotSubscriptions.EventLogD EventLogDefaultData diff --git a/PivotSubscriptions/Installer.cls b/PivotSubscriptions/Installer.cls index 65ae448..6a5f55e 100644 --- a/PivotSubscriptions/Installer.cls +++ b/PivotSubscriptions/Installer.cls @@ -18,10 +18,13 @@ ClassMethod RunInstaller(pRootDir) Set tItem.title="Pivot Subscriptions" Set tItem.bookCover="{background: {style:'background:white;',src:'covers/PivotSubscriptions_Cover.png'},header: {text:'$type',style:'display: none;'},title: {text:'$title',style:'display: none;'},image: {style:'display: none;',src:'deepsee/ds2_globe_44.png',imageStyle:'width:64px;height:64px;'},subtitle: {style:'display: none;'},footer: {text:'$owner',style:'display: none;'}}" Set tSC=tItem.%Save() - - If $$$ISERR(tSC) Quit + If $$$ISERR(tSC) Quit tSC Set tSC=##class(PivotSubscriptions.Task).ConfigureTask() + If $$$ISERR(tSC) Quit tSC + + Set tSC=##class(PivotSubscriptions.Installer).ConfigureUnsubscribeWebApp() + If $$$ISERR(tSC) Quit tSC Quit tSC } @@ -50,4 +53,29 @@ ClassMethod ImportImage(pDir) As %Status Quit tSC } +ClassMethod ConfigureUnsubscribeWebApp() As %Status +{ + Set tSC=$$$OK + + Set tNamespace=$Namespace + ZN "%SYS" + + Try { + If '##class(Security.Applications).Exists("/api/pivotsubscriptionsunsubscribe") { + Set tWebApp=##class(Security.Applications).%New() + Set tWebApp.Name="/api/pivotsubscriptionsunsubscribe" + Set tWebApp.NameSpace=tNamespace + Set tWebApp.DispatchClass="PivotSubscriptions.UI.Unsubscribe" + Set tWebApp.AutheEnabled=64 + Set tSC=tWebApp.%Save() + } + } Catch ex { + Set tSC=ex.AsStatus() + } + + ZN tNamespace + + Quit tSC +} + } diff --git a/PivotSubscriptions/Subscription.cls b/PivotSubscriptions/Subscription.cls index e15cfb4..571970c 100644 --- a/PivotSubscriptions/Subscription.cls +++ b/PivotSubscriptions/Subscription.cls @@ -25,6 +25,46 @@ Property CustomFilters As array Of %String(MAXLEN = ""); Property CustomEmailText As %String(MAXLEN = ""); +Method Unsubscribe(pEmail) As %Status +{ + Set tSC=$$$OK + + Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("unsubscribe",..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,pEmail,..Name,.tEvent) + + Set tEmailList=$LFS(..Emails,",") + + If $LL(tEmailList)=1 { + If ..Emails=pEmail { + // This is the only Email for the subscription, delete subscription + Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",,..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,..Emails,..Name,.tDeleteEvent) + Set tSC=##class(PivotSubscriptions.Subscription).%DeleteId(..%Id()) + Do tDeleteEvent.UpdateStatus(tSC) + Do tEvent.UpdateStatus(tSC) + Return tSC + } + } + + Set tPosition=$Listfind(tEmailList,pEmail) + If tPosition=0 { + Set tSC=$$$ERROR($$$GeneralError,"Not subscribed") + } ElseIf tPosition=1 { + Set tEmailList=$List(tEmailList,2,*) + } ElseIf tPosition=$LL(tEmailList) { + Set tEmailList=$List(tEmailList,1,*-1) + } Else { + Set tEmailList=$List(tEmailList,1,tPosition-1)_$List(tEmailList,tPosition+1,*) + } + + If tPosition'=0 { + Set ..Emails=$LTS(tEmailList,",") + Set tSC=..%Save() + } + + Do tEvent.UpdateStatus(tSC) + + Quit tSC +} + Storage Default { diff --git a/PivotSubscriptions/Task.cls b/PivotSubscriptions/Task.cls index 8d017d9..e3e149a 100644 --- a/PivotSubscriptions/Task.cls +++ b/PivotSubscriptions/Task.cls @@ -67,21 +67,23 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St For tCount=1:1:$l(pEmails,",") { Set tEmail=$p(pEmails,",",tCount) - Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("sendSubscription",$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,.pEvent) + Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("sendSubscription",pID,$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,.pEvent) If $$$ISERR(tSC) Quit tSC - Set tHasResults=0 + Try { + Set tHasResults=0 - Set tCustomFilter=tSubscription.CustomFilters.GetAt(tEmail) - Set tSC=##class(PivotSubscriptions.Utils).ExecuteForSubscription(mdx,tCustomFilter,.tHasResults) - - If tHasResults { - // Only generate file if requested pivot has results - Set tSC=##class(PivotSubscriptions.Utils).GenerateFileForSubscription("Excel",mdx,tCustomFilter,pName,pPivot,.tFilename) - } + Set tCustomFilter=tSubscription.CustomFilters.GetAt(tEmail) + Set tSC=##class(PivotSubscriptions.Utils).ExecuteForSubscription(mdx,tCustomFilter,.tHasResults) + If $$$ISERR(tSC) Quit + + If tHasResults { + // Only generate file if requested pivot has results + Set tSC=##class(PivotSubscriptions.Utils).GenerateFileForSubscription("Excel",mdx,tCustomFilter,pName,pPivot,.tFilename) + If $$$ISERR(tSC) Quit + } - // Generate email - If tSC { + // Generate email // check whether the table generated is too wide/truncated AND whether the table has data Set tableStatus=##class(PivotSubscriptions.Utils).CheckTable(pName) @@ -89,6 +91,7 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St Set server.smtpserver=##class(%SYS.Task.Config).GetData("MailServer") Set msg=##class(%Net.MailMessage).%New() Set msg.From="PivotSubscriptions" + Do msg.To.SetAt(tEmail,1) Set validAdminEmail=##class(PivotSubscriptions.Utils).CheckConfigurationGlobal("AdminEmail") @@ -100,45 +103,45 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St Set msg.Subject=pName Set msg.IsBinary=0 Set msg.IsHTML=1 // Set IsHTML to 1 if email uses HTML + + Set tUnsubscribeList=$LB(tSubscription.%Id(),tEmail,pEvent.GUID) If tHasResults { // Add attachment - Do ##class(PivotSubscriptions.Utils).WriteEmail(tSubscription, msg, tableStatus) + Do ##class(PivotSubscriptions.Utils).WriteEmail(tSubscription,msg,tableStatus,tUnsubscribeList) // if table is too large, then just attach Excel instead If ((pFormat = "PDF") && (tableStatus)) { Set tSC=##class(PivotSubscriptions.Utils).GenerateFileForSubscription("PDF",mdx,tCustomFilter,pName,pPivot,.tFilename) + If $$$ISERR(tSC) Quit } ElseIf 'tableStatus { // Check if both configuration settings for admin email is valid before sending error message If validAdminEmail { - Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"TooLarge") + Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"TooLarge",mdx) } } - Set status=msg.AttachFile("",tFilename) - - If $$$ISERR(status) { - Do $System.Status.DisplayError(status) - Quit $$$ERROR() - } + Set tSC=msg.AttachFile("",tFilename) + If $$$ISERR(tSC) Quit } Else { Do ##class(PivotSubscriptions.Utils).WriteEmailHeader(msg) Do msg.TextData.WriteLine(##class(PivotSubscriptions.Utils).GetSettings("NoDataMessage","No data for requested pivot.")) - Do ##class(PivotSubscriptions.Utils).WriteUnsubscribe(msg) + Do ##class(PivotSubscriptions.Utils).WriteUnsubscribe(msg,tUnsubscribeList) Do ##class(PivotSubscriptions.Utils).WriteEmailFooter(msg) - Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"NoResults") + Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"NoResults",mdx) + } + + // Send email + If tHasResults||##class(PivotSubscriptions.Utils).GetSettings("SendNoData",1) { + Set tSC=server.Send(msg) + If $$$ISERR(tSC) Quit } + } Catch ex { + Set tSC=ex.AsStatus() } - - Do msg.To.SetAt(tEmail,1) - // Send email - If tHasResults||##class(PivotSubscriptions.Utils).GetSettings("SendNoData",1) { - Set tSC=server.Send(msg) - Set tSC=pEvent.UpdateStatus(tSC) - If $$$ISERR(tSC) Quit tSC - } + Set tSC=pEvent.UpdateStatus(tSC) If tHasResults { // Delete file diff --git a/PivotSubscriptions/UI/Dialog/EditSubscription.cls b/PivotSubscriptions/UI/Dialog/EditSubscription.cls index 7caf634..e2b024d 100644 --- a/PivotSubscriptions/UI/Dialog/EditSubscription.cls +++ b/PivotSubscriptions/UI/Dialog/EditSubscription.cls @@ -160,7 +160,7 @@ Method EditSubscription(pSubscriptionId, pPivot, pDayOfWeek, pHour, pMinute, pEm Set tEventType="create" } - Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent(tEventType,$username,tSubscription.Pivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tSubscription.Emails,tSubscription.Name,.tEvent) + Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent(tEventType,pSubscriptionId,$username,tSubscription.Pivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tSubscription.Emails,tSubscription.Name,.tEvent) Set tSubscription.DayOfWeek=pDayOfWeek Set tSubscription.Hour=pHour diff --git a/PivotSubscriptions/UI/Dialog/EventDetails.cls b/PivotSubscriptions/UI/Dialog/EventDetails.cls new file mode 100644 index 0000000..3cf4fbb --- /dev/null +++ b/PivotSubscriptions/UI/Dialog/EventDetails.cls @@ -0,0 +1,112 @@ +Class PivotSubscriptions.UI.Dialog.EventDetails Extends %DeepSee.UI.Dialog.standardDialog +{ + +/// Class name of application this page belongs to. +Parameter APPLICATION; + +/// Displayed name of this page. +Parameter PAGENAME; + +Parameter DOMAIN = "PivotSubscriptions"; + +Property EventId As %ZEN.Datatype.integer(ZENURL = "EVENTID"); + +Parameter APPLYBUTTON = 0; + +/// This Style block contains page-specific CSS style definitions. +XData Style +{ + +} + +/// This XML block defines the contents of this page. +XData dialogBody [ XMLNamespace = "http://www.intersystems.com/zen" ] +{ + + + +} + +/// Get the (localized) title string for the dialog. +Method %OnGetTitle() As %String +{ + Quit "Event Details" +} + +Method %OnGetSubtitle() As %String +{ + Quit "" +} + +ClassMethod DrawDetails(pEventId) As %Status +{ + Set tSC=$$$OK + + Set tEvent=##class(PivotSubscriptions.EventLog).%OpenId(pEventId) + &html< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID#(pEventId)#
GUID#(tEvent.GUID)#
Type#(tEvent.EventType)#
Start Time#(tEvent.StartTime)#
End Time#(tEvent.EndTime)#
Name#(tEvent.Name)#
Pivot#(tEvent.Pivot)#
UserName#(tEvent.UserName)#
Format#(tEvent.Format)#
DayOfWeek#(##class(PivotSubscriptions.EventLog).DayOfWeekDisplay(tEvent.DayOfWeek))#
Time#(tEvent.Hour)#:#($replace($j(tEvent.Minute,2)," ",0))#
Email#(tEvent.Emails)#
Status#($Select(tEvent.Status:"OK",1:$system.Status.GetErrorText(tEvent.Status)))#
+ > + + Quit tSC +} + +ClientMethod getDialogValue() [ Language = javascript ] +{ + return ''; +} + +} diff --git a/PivotSubscriptions/UI/EventLogViewer.cls b/PivotSubscriptions/UI/EventLogViewer.cls index 2ffb95c..5c4d0c9 100644 --- a/PivotSubscriptions/UI/EventLogViewer.cls +++ b/PivotSubscriptions/UI/EventLogViewer.cls @@ -17,20 +17,27 @@ XData contentPane [ XMLNamespace = "http://www.intersystems.com/zen" ] cellSpacing="2" fixedHeaders="false" queryClass="PivotSubscriptions.EventLog" - queryName="GetEvents" + queryName="GetEventsForUI" useSnapshot="true" showQuery="false" showZebra="true" showRowNumbers="false" - pageSize="100" + pageSize="50" maxRows="1000" > + } +/// Creates edit popup. +ClientMethod viewDetails(pId, pPivot) [ Internal, Language = javascript ] +{ + zenLaunchPopupWindow('PivotSubscriptions.UI.Dialog.EventDetails.cls?EVENTID='+pId,'EventDetails','status,resizable=yes,width=700,height=575'); +} + /// Get the (localized) title string for the page. Method %OnGetTitle() As %String [ Internal ] { diff --git a/PivotSubscriptions/UI/SubscriptionManager.cls b/PivotSubscriptions/UI/SubscriptionManager.cls index 84a1ebb..a365e5d 100644 --- a/PivotSubscriptions/UI/SubscriptionManager.cls +++ b/PivotSubscriptions/UI/SubscriptionManager.cls @@ -133,7 +133,7 @@ Method Delete(pId As %Integer) As %String [ ZenMethod ] Set tMsg="Subscription Deleted." Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pId) - Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",$username,tSubscription.Pivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tSubscription.Emails,tSubscription.Name,.tEvent) + Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",pId,$username,tSubscription.Pivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tSubscription.Emails,tSubscription.Name,.tEvent) If $$$ISERR(tSC) Quit tSC diff --git a/PivotSubscriptions/UI/Unsubscribe.cls b/PivotSubscriptions/UI/Unsubscribe.cls new file mode 100644 index 0000000..8c9a433 --- /dev/null +++ b/PivotSubscriptions/UI/Unsubscribe.cls @@ -0,0 +1,33 @@ +Class PivotSubscriptions.UI.Unsubscribe Extends %CSP.REST +{ + +Parameter HandleCorsRequest = 1; + +XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ] +{ + + + +} + +ClassMethod Unsubscribe(pSubscriptionId, pEmail, pGUID) As %Status +{ + Set tSC=$$$OK + Set tResult={} + Do tResult.%Set("Status",$$$ERROR($$$GeneralError,"Invalid Request")) + + If ##class(PivotSubscriptions.Subscription).%ExistsId(pSubscriptionId)&&##class(PivotSubscriptions.Utils).CheckUnsubscribe(pSubscriptionId,pEmail,pGUID) { + Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pSubscriptionId) + Set tSC=tSubscription.Unsubscribe(pEmail) + If $$$ISERR(tSC) { + Do tResult.%Set("Status",$SYSTEM.Status.GetErrorText(tSC)) + } Else { + Do tResult.%Set("Status",pEmail_" unsubscribed from "_tSubscription.Name) + } + } + + Write tResult.%ToJSON() + Quit tSC +} + +} diff --git a/PivotSubscriptions/Utils.cls b/PivotSubscriptions/Utils.cls index 7be848b..bed25b3 100644 --- a/PivotSubscriptions/Utils.cls +++ b/PivotSubscriptions/Utils.cls @@ -3,7 +3,7 @@ Class PivotSubscriptions.Utils ClassMethod GetVersion() As %String { - Quit "v1.3.0" + Quit "v1.4.0" } /// Utility method for saving and updating global variables @@ -37,7 +37,7 @@ ClassMethod GetSettings(pSetting As %String, pDefaultValue As %String = "") As % Quit $G(^PivotSubscriptions.Settings(pSetting),pDefaultValue) } -ClassMethod GenerateLink(ByRef pLink As %String) As %Status +ClassMethod GenerateLink(ByRef pLink As %String = "") As %Status { Set tSC=$$$OK @@ -45,29 +45,24 @@ ClassMethod GenerateLink(ByRef pLink As %String) As %Status If $$$ISERR(tSC) Quit tSC If ..CheckConfigurationGlobal("Http") { - Set tWebServerPortUrl=##class(PivotSubscriptions.Utils).GetSettings("Http") + Set pLink=##class(PivotSubscriptions.Utils).GetSettings("Http") } Else { - Set tWebServerPortUrl="http://" + Set pLink="http://" } If ..CheckConfigurationGlobal("Server") { - Set tWebServerPortUrl=tWebServerPortUrl_##class(PivotSubscriptions.Utils).GetSettings("Server") + Set pLink=pLink_##class(PivotSubscriptions.Utils).GetSettings("Server") } Else { - Set tWebServerPortUrl=tWebServerPortUrl_h + Set pLink=pLink_h } If ..CheckConfigurationGlobal("Port") { - Set tWebServerPortUrl=tWebServerPortUrl_":"_##class(PivotSubscriptions.Utils).GetSettings("Port") + Set pLink=pLink_":"_##class(PivotSubscriptions.Utils).GetSettings("Port") } Else { If '..CheckConfigurationGlobal("Server") { - Set tWebServerPortUrl=tWebServerPortUrl_":"_p + Set pLink=pLink_":"_p } } - - Set tNamespace=$System.CSP.GetDefaultApp($Namespace) - Set tApplicationName="/PivotSubscriptions.UI.SubscriptionManager.zen" - - Set pLink=tWebServerPortUrl_tNamespace_tApplicationName Quit tSC } @@ -116,13 +111,15 @@ ClassMethod WriteEmailHeader(pMsg As %Net.MailMessage) Do pMsg.TextData.WriteLine("

") } -ClassMethod WriteUnsubscribe(pMsg As %Net.MailMessage) +ClassMethod WriteUnsubscribe(pMsg As %Net.MailMessage, pUnsubscribeList) { Do ##class(PivotSubscriptions.Utils).GenerateLink(.tLink) + Set tLink=tLink_"/api/pivotsubscriptionsunsubscribe/unsubscribe/" + Set tLink=tLink_$LTS(pUnsubscribeList,"/") Do pMsg.TextData.WriteLine("

") Do pMsg.TextData.WriteLine("") - Do pMsg.TextData.WriteLine("
 
 
You can manage your subscriptions here.
You can edit days of the week/time/format/recipients and delete in the Subscriptions Manager portal.
 
") + Do pMsg.TextData.WriteLine(" To Unsubscribe, click here.You can edit days of the week/time/format/recipients and delete in the Subscriptions Manager portal. ") } /// Write footer for any email, including link generation @@ -138,7 +135,7 @@ ClassMethod WriteEmailFooter(pMsg As %Net.MailMessage) } /// Write improved email format for subscription, including embeded pivot table -ClassMethod WriteEmail(pSubscription As PivotSubscriptions.Subscription, pMsg As %Net.MailMessage, pTableStatus) +ClassMethod WriteEmail(pSubscription As PivotSubscriptions.Subscription, pMsg As %Net.MailMessage, pTableStatus, pUnsubscribeList) { Do ##class(PivotSubscriptions.Utils).WriteEmailHeader(pMsg) @@ -180,14 +177,14 @@ ClassMethod WriteEmail(pSubscription As PivotSubscriptions.Subscription, pMsg As Do pMsg.TextData.WriteLine("Pivot table is too big to be embedded. Please see attachment.") } - Do ##class(PivotSubscriptions.Utils).WriteUnsubscribe(pMsg) + Do ##class(PivotSubscriptions.Utils).WriteUnsubscribe(pMsg,pUnsubscribeList) Do ##class(PivotSubscriptions.Utils).WriteEmailFooter(pMsg) } -ClassMethod TableErrorMessage(pSubscription As PivotSubscriptions.Subscription, pEmail As %String, pName As %String, pReason As %String) As %Status +ClassMethod TableErrorMessage(pSubscription As PivotSubscriptions.Subscription, pEmail As %String, pName As %String, pReason As %String, pMDX As %String) As %Status { Set tAdminEmail=##class(PivotSubscriptions.Utils).GetSettings("AdminEmail") - Set tLog=##class(PivotSubscriptions.EventLog).CreateEvent("tableError",$username,pSubscription.Pivot,pSubscription.DayOfWeek,pSubscription.Hour,pSubscription.Minute,pSubscription.Format,tAdminEmail,pName,.pEvent) + Set tLog=##class(PivotSubscriptions.EventLog).CreateEvent("tableError",pSubscription.%Id(),$username,pSubscription.Pivot,pSubscription.DayOfWeek,pSubscription.Hour,pSubscription.Minute,pSubscription.Format,tAdminEmail,pName,.pEvent) If $$$ISERR(tLog) Quit tLog @@ -211,6 +208,8 @@ ClassMethod TableErrorMessage(pSubscription As PivotSubscriptions.Subscription, Do tMsg.TextData.WriteLine("The pivot table is too large to be embedded.
") } Do tMsg.TextData.WriteLine("
Please check the Subscription Manager.") + Do tMsg.TextData.WriteLine("

MDX Executed:") + Do tMsg.TextData.WriteLine(pMDX) Do ##class(PivotSubscriptions.Utils).WriteEmailFooter(tMsg) // Set recipient of email @@ -282,4 +281,15 @@ ClassMethod GenerateFileForSubscription(pType = "Excel", pMDX, pCustomFilter, pN Quit tSC } +ClassMethod CheckUnsubscribe(pSubscriptionId, pEmail, pGUID) As %Boolean +{ + Set tConfirmed=0 + + Set tSQL="SELECT ID FROM PivotSubscriptions.EventLog WHERE Subscription=? AND Emails=? AND GUID=?" + Set tSQLRS=##class(%SQL.Statement).%ExecDirect(,tSQL,pSubscriptionId,pEmail,pGUID) + Set tConfirmed=tSQLRS.%Next() + + Quit tConfirmed +} + } diff --git a/README.md b/README.md index cb22439..e65c082 100644 --- a/README.md +++ b/README.md @@ -19,16 +19,18 @@ Once installation is complete, a new "Pivot Subscriptions" Link will be added to 5. Follow the Configuration steps ## Configuration steps -### Configure Default Namespace -To ensure that links to the SubscriptionManager page are correctly generated, the Default Application of the namespace you are working in is correctly configured. -1. Go to Management Portal -2. Go to System Administration > Security > Applications > Web Applications -3. Click on /csp/??? where ??? is the namespace you are working in -4. Check the checkbox next to Namespace Default Application and Save - ### Configure Task Manager Email Settings Subscriptions are delivered by Email. The Task Manager Email must be configured to allow alerts to be delivered by Email. At a minimum, the SMTP Server must be assigned in the Task Manager Email Settings (Management Portal -> System Administration -> Configuration -> Additional Settings -> Task Manager Email). For more information, please see the documentation. +### Unsubscribe Web Application +A new Web Application is created to allow users to manually unsubscribe to subscriptions by clicking on the unsubscribe link include in the subscription email. This new Web Application is "/api/pivotsubscriptionsunsubscribe". It allows unauthenticated access to a REST API that only allows users to unsubscribe if they have the specific URL. Depending on security settings, it may be necessary to give the application additional permissions. This can be accomplished in The Management Portal -> System Administration -> Security -> Applications -> Web Applications -> /api/pivotsubscriptionsunsubscribe -> Application Roles Tab. +These additional permissions include: +1) The Database Resource for the Database that contains the PivotSubscriptions Code +2) The Database Resource for the Database that contains the PivotSubscriptions Data +3) The Database Resource for the NameSpace's Default Globals Database where PivotSubscriptions is installed + +Depending on your security settings and mapping configuration, this may be between 0 and 3 resources that are needed. + ### Optional: Custom Action The Piovt List page gives access to a list of Pivot Tables available to the user. From there, a Pivot Subscription can be added. However, if you would like to add a Pivot Subscription directly from Analyzer or from a Dashboard, you will need to configure a new Custom Action. In order to add the Custom Action, an Action Class is first needed. For more information, please see the documentation for defining custom actions. In your Action KPI, define the new action as: ``` @@ -41,4 +43,4 @@ If (pAction="AddPivotSubscription") { } ``` -The ActionCommand Method will generate a command that will allow for the creation of the Pivot Subscription \ No newline at end of file +The ActionCommand Method will generate a command that will allow for the creation of the Pivot Subscription