Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BDE-239: Skip api calls for non-admin user #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ selenium-standalone.txt
.env.chrome
.env.firefox
.env.local
app
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@rollup/plugin-inject": "^5.0.5",
"chai": "^5.1.1",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"cssnano": "^7.0.4",
"dotenv": "^16.4.5",
"eslint-config-airbnb-base": "^14.2.1",
Expand Down Expand Up @@ -63,13 +64,13 @@
"private": true,
"scripts": {
"env:build": "node vite.env.js",
"build:chrome:about": "BUILD_ENTRY=about vite build --mode=chrome",
"build:chrome:content": "BUILD_ENTRY=content vite build --mode=chrome",
"build:chrome:es-reindex": "BUILD_ENTRY=es-reindex vite build --mode=chrome",
"build:chrome:json": "BUILD_ENTRY=json vite build --mode=chrome",
"build:chrome:main": "BUILD_ENTRY=main vite build --mode=chrome",
"build:chrome:options": "BUILD_ENTRY=options vite build --mode=chrome",
"build:chrome:popup": "BUILD_ENTRY=popup vite build --mode=chrome",
"build:chrome:about": "cross-env BUILD_ENTRY=about vite build --mode=chrome",
"build:chrome:content": "cross-env BUILD_ENTRY=content vite build --mode=chrome",
"build:chrome:es-reindex": "cross-env BUILD_ENTRY=es-reindex vite build --mode=chrome",
"build:chrome:json": "cross-env BUILD_ENTRY=json vite build --mode=chrome",
"build:chrome:main": "cross-env BUILD_ENTRY=main vite build --mode=chrome",
"build:chrome:options": "cross-env BUILD_ENTRY=options vite build --mode=chrome",
"build:chrome:popup": "cross-env BUILD_ENTRY=popup vite build --mode=chrome",
"build:chrome": "pnpm run env:build chrome && concurrently --kill-others-on-fail 'npm:build:chrome:*'"
},
"type": "module",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 41 additions & 37 deletions src/main/server-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,43 +115,47 @@ This extension is only compatible with Nuxeo Platform servers.
return Promise.reject(this.connectionErrorOf(`Connection to ${serverUrl.host} is forbidden`, notification));
}

connect(serverUrl, tabInfo, connectOptions = { forceForbiddenDomains: false }) {
return this.checkOperableDomain(serverUrl, connectOptions)
.then(() => new Nuxeo({ baseURL: serverUrl })
.connect()
.then((nuxeo) => {
this.nuxeo = nuxeo;
this.serverUrl = serverUrl;
return Promise.all([
this.asInstalledAddons().catch(() => []), // Return empty array on error
this.asConnectRegistration().catch(() => ({})), // Return empty object on error
])
.then(([installedAddons, connectRegistration]) => ({
nuxeo,
serverUrl: nuxeo._baseURL,
installedAddons,
connectRegistration,
}))
.then((runtimeInfo) => {
this.disconnect = () => {
this.nuxeo = undefined;
this.runtimeInfo = undefined;
this.serverUrl = undefined;
this.worker.tabNavigationHandler.disableTabExtension(tabInfo);
};
this.nuxeo = nuxeo;
this.runtimeInfo = runtimeInfo;
this.worker.tabNavigationHandler.enableTabExtension(tabInfo);
});
})
.catch((cause) => {
this.disconnect = this.noop;
this.nuxeo = undefined;
this.runtimeInfo = undefined;
this.serverUrl = undefined;
const notification = this.notifyError(cause);
return Promise.reject(this.connectionErrorOf(`Cannot establish connection with ${serverUrl}`, notification));
}));
async connect(serverUrl, tabInfo, connectOptions = { forceForbiddenDomains: false }) {
await this.checkOperableDomain(serverUrl, connectOptions);

try {
this.nuxeo = await new Nuxeo({ baseURL: serverUrl }).connect();
this.serverUrl = serverUrl;
} catch (cause) {
this.disconnect = this.noop;
this.nuxeo = undefined;
this.runtimeInfo = undefined;
this.serverUrl = undefined;

const notification = this.notifyError(cause);
this.connectionErrorOf(`Cannot establish connection with ${serverUrl}`, notification);
return;
}

let installedAddons = [];
let connectRegistration = [];
if (this.nuxeo.user.isAdministrator) {
try {
installedAddons = await this.asInstalledAddons();
connectRegistration = await this.asConnectRegistration();
} catch (_) {
}
}

this.runtimeInfo = {
nuxeo: this.nuxeo,
serverUrl: this.nuxeo._baseURL,
installedAddons: installedAddons,
connectRegistration: connectRegistration
};
this.disconnect = () => {
this.nuxeo = undefined;
this.runtimeInfo = undefined;
this.serverUrl = undefined;
this.worker.tabNavigationHandler.disableTabExtension(tabInfo);
};

this.worker.tabNavigationHandler.enableTabExtension(tabInfo);
}

isConnected() {
Expand Down
10 changes: 5 additions & 5 deletions src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {
});
}
return Promise.all([
worker.serverConnector
.asConnectRegistration(),
worker.serverConnector
.asDevelopedStudioProjects()
nuxeo.user.isAdministrator ? worker.serverConnector
.asConnectRegistration() : Promise.resolve({}),
nuxeo.user.isAdministrator ? worker.serverConnector
.asDevelopedStudioProjects() : Promise.resolve([])
.then((projects) => {
// Remove any existing options
while (selectBox[0].firstChild) {
Expand Down Expand Up @@ -579,7 +579,7 @@ function loadPage(worker, options = { forceForbiddenDomains: false }) {
new URL(connectLocation),
registeredPackage
);
} else {
} else if (nuxeo.user.isAdministrator) {
noStudioPackageFound();
}
})
Expand Down
Loading