Skip to content

Commit 7930ca3

Browse files
committed
Support staff login in ArchivesSpace v2.8.0
1 parent ac284e4 commit 7930ca3

2 files changed

Lines changed: 65 additions & 18 deletions

File tree

Aeon-ArchivesSpace-Addon/Aeon-ArchivesSpace.lua

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ local currentRecordUri = "";
4343

4444
local gridColumns = {};
4545

46+
local performedAutoSearch = false;
47+
local transactionNumber = 0;
48+
4649
local archiveSpaceAddonScript = [[
4750
function buildObjectUrl(currentTreeId) {
4851
var archivalObjectId = /archival_object_(\d+)/.exec(currentTreeId);
@@ -139,25 +142,17 @@ function Init()
139142
-- After we add all of our buttons and form elements, we can show the form.
140143
catalogSearchForm.Form:Show();
141144
catalogSearchForm.Form:LoadLayout("layout.xml");
145+
146+
transactionNumber = GetFieldValue("Transaction", "TransactionNumber");
142147

143-
local transactionNumber = GetFieldValue("Transaction", "TransactionNumber");
144148
--set the pagehandler if the user manually searches on the Browser interface directly
145149
InitializeLoginPageHandler();
146150

147-
if ((settings.AutoSearch) and (transactionNumber ~= nil) and (transactionNumber > 0)) then
148-
LogDebug("Performing AutoSearch");
149-
local autoSearchPriority = ParseCSVLine(settings.AutoSearchPriority, ',');
150-
for _, v in ipairs(autoSearchPriority) do
151-
-- Keep performing searches until successful
152-
if(PerformSuccessfulSearch(v)) then
153-
return;
154-
end
155-
end
156-
else
157-
LogDebug("Navigating to BaseURL because AutoSearch is disabled or invalid.");
158-
catalogSearchForm.Browser:Navigate(settings.BaseURL);
159-
end
160-
151+
--We need to navigate to the main page first to detect if the user is already signed in
152+
--AutoSearch will occur after the initial sign in attempt
153+
LogDebug("Navigating to BaseURL first");
154+
catalogSearchForm.Browser:Navigate(settings.BaseURL);
155+
161156
end
162157

163158
function ShowDevTools()
@@ -166,6 +161,12 @@ end
166161

167162
function InitializeLoginPageHandler()
168163
LogDebug("Initializing Login Page Handler");
164+
catalogSearchForm.Browser:RegisterPageHandler("custom", "IsNotSignedIn", "NavigateToLogin", true);
165+
if (settings.AutoSearch) then
166+
catalogSearchForm.Browser:RegisterPageHandler("custom", "IsSignedIn", "AutoSearchAfterLogin", true);
167+
else
168+
LogDebug("AutoSearch is disabled. Skipping page page handler registration to perform autosearch functionality.")
169+
end
169170
catalogSearchForm.Browser:RegisterPageHandler("custom", "LoginPageLoaded", "PerformLogin", true);
170171
catalogSearchForm.Browser:RegisterPageHandler("custom", "AlwaysTrue", "InjectScriptBridge", false);
171172
end
@@ -776,6 +777,52 @@ function WebClientGet(webClient, apiPath)
776777
return webClient:DownloadData(PathCombine(settings.ApiBaseURL, apiPath));
777778
end
778779

780+
function IsSignedIn()
781+
return CheckIfUserSignedIn();
782+
end
783+
784+
function IsNotSignedIn()
785+
return not CheckIfUserSignedIn();
786+
end
787+
788+
function CheckIfUserSignedIn()
789+
LogDebug("Checking if user is signed in");
790+
791+
local jsResult = catalogSearchForm.Browser:EvaluateScript(10000, [[document.getElementsByClassName('user-container').length > 0]]);
792+
793+
if (jsResult.Success) then
794+
LogDebug("IsUserSignedIn() result: " .. tostring(jsResult.Result));
795+
return jsResult.Result;
796+
else
797+
LogDebug("Error determining if user is signed in: " .. jsResult.Message);
798+
return false;
799+
end
800+
end
801+
802+
function NavigateToLogin()
803+
LogDebug("Navigating to login page");
804+
local loginUrl = PathCombine(settings.BaseURL,"?login")
805+
catalogSearchForm.Browser:Navigate(loginUrl);
806+
end
807+
808+
function AutoSearchAfterLogin()
809+
LogDebug("Checking if we need to autosearch");
810+
811+
if ((settings.AutoSearch) and (not performedAutoSearch) and (transactionNumber ~= nil) and (transactionNumber > 0)) then
812+
LogDebug("Performing AutoSearch");
813+
local autoSearchPriority = ParseCSVLine(settings.AutoSearchPriority, ',');
814+
for _, v in ipairs(autoSearchPriority) do
815+
-- Keep performing searches until successful
816+
if(PerformSuccessfulSearch(v)) then
817+
performedAutoSearch = true;
818+
return;
819+
end
820+
end
821+
else
822+
LogDebug("AutoSearch is disabled or already perfored");
823+
end
824+
end
825+
779826
function LoginPageLoaded()
780827
LogDebug("Checking if Login Page is loaded");
781828

@@ -793,7 +840,7 @@ end
793840
function PerformLogin()
794841
--Reregister login page handler
795842
catalogSearchForm.Browser:RegisterPageHandler("custom", "LoginPageLoaded", "PerformLogin", true);
796-
843+
797844
LogDebug("Attempting to log in.");
798845

799846
--Anonymous function invoked with params

Aeon-ArchivesSpace-Addon/Config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
33
<Name>ArchivesSpace Interface</Name>
44
<Author>Atlas Systems, Inc.</Author>
5-
<Version>2.0.0</Version>
5+
<Version>2.1.0</Version>
66
<Active>True</Active>
77
<Type>Addon</Type>
8-
<Description>This addon performs searches in ArchivesSpace using the staff interface. This addon supports ArchivesSpace versions v2.0.0 and later.</Description>
8+
<Description>This addon performs searches in ArchivesSpace using the staff interface. This addon supports ArchivesSpace versions v2.8.0 and later.</Description>
99
<Forms>
1010
<Form>FormRequest</Form>
1111
</Forms>

0 commit comments

Comments
 (0)