Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Code changes for toolName and toolVersion constraints #411

Open
wants to merge 4 commits into
base: test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const changeMe = "me";
window.userale.options({
'userId': changeMe,
'logDetails': true,
'toolVersion': '2.3.0',
'toolName': 'Apache UserALE.js Example (Custom)'
});

Expand Down
9 changes: 9 additions & 0 deletions src/UserALEWebExtension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const defaultConfig = {
userId: 'pluginUser',
authHeader: null,
toolName: 'useralePlugin',
toolVersion: '2.4.0',
version: userale.version,
},
pluginConfig: {
Expand All @@ -41,6 +42,14 @@ const defaultConfig = {
var urlWhitelist;

function updateConfig(config) {
if ((config.toolName || "") === "") {
throw "Please set the tool name before use.";
}

if ((config.toolVersion || "") === "") {
throw "Please set the app version before use.";
}

urlWhitelist = new RegExp(config.pluginConfig.urlWhitelist);
userale.options(config.useraleConfig);
// TODO: tabs need a page load to apply this config change.
Expand Down
4 changes: 2 additions & 2 deletions src/UserALEWebExtension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function setConfig() {
url: document.getElementById("url").value,
userId: document.getElementById("user").value,
toolName: document.getElementById("tool").value,
version: document.getElementById("version").value
toolVersion: document.getElementById("version").value
};

// Set a basic auth header if given credentials.
Expand Down Expand Up @@ -58,7 +58,7 @@ function getConfig() {
document.getElementById("url").value = config.url;
document.getElementById("user").value = config.userId;
document.getElementById("tool").value = config.toolName;
document.getElementById("version").value = config.version;
document.getElementById("version").value = config.toolVersion;
});
browser.storage.local.get("pluginConfig", (res) => {
document.getElementById("filter").value = res.pluginConfig.urlWhitelist;
Expand Down
11 changes: 10 additions & 1 deletion src/getInitialSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function getInitialSettings() {
settings.transmitInterval = +get('data-interval') || 5000;
settings.logCountThreshold = +get('data-threshold') || 5;
settings.userId = get('data-user') || null;
settings.version = get('data-version') || null;
settings.toolVersion = get('data-version') || null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where I was referencing changing the script tag to match the setting name.

so it'd be:
get('data-tool-version')

This is a breaking change, because it changes the script-tag api. And since toolVersion is required, the script would throw if users did not set this field.

We should add a default besides null to keep it from breaking (e.g. '1.0').

settings.logDetails = get('data-log-details') === 'true' ? true : false;
settings.resolution = +get('data-resolution') || 500;
settings.toolName = get('data-tool') || null;
Expand All @@ -52,6 +52,15 @@ export function getInitialSettings() {
settings.authHeader = get('data-auth') || null;
settings.custIndex = get('data-index') || null;
settings.headers = get('data-headers') || null;

if ((settings.toolName || "") === "") {
throw "Please set the tool name before use.";
}

if ((settings.toolVersion || "") === "") {
throw "Please set the app version before use.";
}

return settings;
}

Expand Down