Skip to content

Commit

Permalink
N21-1298 tool context restrictions (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
MBergCap authored Dec 1, 2023
1 parent 439bec3 commit ee5d896
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 42 deletions.
61 changes: 19 additions & 42 deletions controllers/ctltools.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const sanitizeToolInputs = (id, body) => {
body.openNewTab = !!body.openNewTab;
body.isHidden = !!body.isHidden;
body.config.baseUrl = body.config.baseUrl || undefined;
body.restrictToContexts = [].concat(body.restrictToContexts || []);

switch (body.config.type) {
case 'oauth2':
Expand Down Expand Up @@ -217,15 +218,20 @@ const showTools = (req, res) => {
}
}

api(req, { version: 'v3' }).get('/tools/external-tools', {
qs: {
name: req.query.q,
limit: itemsPerPage,
skip: itemsPerPage * (currentPage - 1),
sortOrder,
sortBy,
},
}).then((tools) => {
Promise.all([
api(req, {version: 'v3'}).get('/tools/context-types'),
api(req, {version: 'v3'}).get('/tools/external-tools', {
qs: {
name: req.query.q,
limit: itemsPerPage,
skip: itemsPerPage * (currentPage - 1),
sortOrder,
sortBy,
},
})
]).then(([contextTypes, tools]) => {
const toolContextTypes = contextTypes.data;

const body = tools.data.map(item => {
return [
item.id || "",
Expand Down Expand Up @@ -265,40 +271,11 @@ const showTools = (req, res) => {
toolTypes,
customParameterTypes,
customParameterScopes,
customParameterLocations
});
}).catch(() => {
res.render('ctltools/ctltools', {
title: 'Tools',
head,
body: [],
user: res.locals.currentUser,
limit: true,
themeTitle: process.env.SC_NAV_TITLE || 'Schul-Cloud',
messageTypes,
privacies,
authMethods,
toolTypes,
customParameterTypes,
customParameterScopes,
customParameterLocations
});
}).catch(() => {
res.render('ctltools/ctltools', {
title: 'Tools',
head,
body: [],
user: res.locals.currentUser,
limit: true,
themeTitle: process.env.SC_NAV_TITLE || 'Schul-Cloud',
messageTypes,
privacies,
authMethods,
toolTypes,
customParameterTypes,
customParameterScopes,
customParameterLocations
customParameterLocations,
toolContextTypes
});
}).catch(err => {
next(err);
});
};

Expand Down
8 changes: 8 additions & 0 deletions views/ctltools/forms/add-ctl-tool.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
Ja, es soll es ausgeblendet werden
</label>
</div>
<div class="form-group">
<label class="control-label" for="restrictToContexts">Nutzung des Tools auf folgende Kontexte beschränken:</label>
<select id="restrictToContexts" name="restrictToContexts" multiple>
{{#each toolContextTypes}}
<option value="{{this}}">{{this}}</option>
{{/each}}
</select>
</div>
<h3>Konfiguration</h3>
<div class="form-group">
<label class="control-label" for="baseUrl">BaseURL *</label>
Expand Down

0 comments on commit ee5d896

Please sign in to comment.