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

Website: Move query generator out of Admin section #25301

Open
wants to merge 5 commits into
base: main
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
6 changes: 6 additions & 0 deletions website/api/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ without necessarily having a billing card.`
description: 'A JS timestamp of when this user\'s Fleet Premium trial license key expires.',
},

canUseQueryGenerator: {
type: 'boolean',
description: 'Whether or not this user can access the query generator page',
defaultsTo: false,
},

// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝
Expand Down
37 changes: 37 additions & 0 deletions website/api/policies/has-query-generator-access.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* has-query-generator-access
*
* A simple policy that blocks requests from users who have not been granted access to the query generator.
*
* For more about how to use policies, see:
* https://sailsjs.com/config/policies
* https://sailsjs.com/docs/concepts/policies
* https://sailsjs.com/docs/concepts/policies/access-control-and-permissions
*/
module.exports = async function (req, res, proceed) {

// First, check whether the request comes from a logged-in user.
// > For more about where `req.me` comes from, check out this app's
// > custom hook (`api/hooks/custom/index.js`).
if (!req.me) {
// Rather than use the standard res.unauthorized(), if the request did not come from a logged-in user,
// we'll redirect them to an generic version of the customer login page.
if (req.wantsJSON) {
return res.sendStatus(401);
} else {
return res.redirect('/login');
}
}//•

// Check if this user can access the query generator.
if (!req.me.canUseQueryGenerator) {
return res.forbidden();
// Then check that this user is a "super admin".
} else if (!req.me.canUseQueryGenerator && !req.me.isSuperAdmin) {
return res.forbidden();
}

// IWMIH, this user can access the query generator.
return proceed();

};
2 changes: 1 addition & 1 deletion website/assets/js/cloud.setup.js

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

1 change: 1 addition & 0 deletions website/config/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports.policies = {

'*': 'is-logged-in',
'admin/*': 'is-super-admin',
'query-generator/*': 'has-query-generator-access',

// Bypass the `is-logged-in` policy for:
'entrance/*': true,
Expand Down
9 changes: 7 additions & 2 deletions website/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,12 @@ module.exports.routes = {
}
},

'GET /admin/query-generator': { action: 'admin/view-query-generator' },
'GET /query-generator': {
action: 'query-generator/view-query-generator',
locals: {
showAdminLinks: true,
}
},

// ╦ ╔═╗╔═╗╔═╗╔═╗╦ ╦ ╦═╗╔═╗╔╦╗╦╦═╗╔═╗╔═╗╔╦╗╔═╗
// ║ ║╣ ║ ╦╠═╣║ ╚╦╝ ╠╦╝║╣ ║║║╠╦╝║╣ ║ ║ ╚═╗
Expand Down Expand Up @@ -908,5 +913,5 @@ module.exports.routes = {
'POST /api/v1/deliver-deal-registration-submission': { action: 'deliver-deal-registration-submission' },
'/api/v1/unsubscribe-from-marketing-emails': { action: 'unsubscribe-from-marketing-emails' },
'POST /api/v1/customers/get-stripe-checkout-session-url': { action: 'customers/get-stripe-checkout-session-url' },
'POST /api/v1/admin/get-llm-generated-sql': { action: 'admin/get-llm-generated-sql' },
'POST /api/v1/query-generator/get-llm-generated-sql': { action: 'query-generator/get-llm-generated-sql' },
};
3 changes: 2 additions & 1 deletion website/views/layouts/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
<hr>
<a purpose="mobile-dropdown-toggle" class="d-flex align-items-center mr-4 collapsed" data-toggle="collapse" data-target="#mobileNavbarToggleAdmin">Admin</a>
<div id="mobileNavbarToggleAdmin" purpose="mobile-dropdown" class="collapse" data-parent="#mobileDropdowns">
<a purpose="mobile-dropdown-link" href="/query-generator">Generate queries</a>
<a purpose="mobile-dropdown-link" href="/admin/generate-license">License generator</a>
<a purpose="mobile-dropdown-link" href="/admin/email-preview">HTML Email preview tool</a>
</div>
Expand Down Expand Up @@ -289,7 +290,7 @@
<span>Admin pages</span>
</div>
<div class="d-flex flex-row align-self-end justify-content-between">
<a purpose="admin-link" style="text-decoration: none; line-height: 23px;" href="/admin/query-generator">Generate queries</a>
<a purpose="admin-link" style="text-decoration: none; line-height: 23px;" href="/query-generator">Generate queries</a>
<a purpose="admin-link" style="text-decoration: none; line-height: 23px;" href="/admin/generate-license">License generator</a>
<a purpose="admin-link" style="text-decoration: none; line-height: 23px;" href="/admin/email-preview">HTML Email preview tool</a>
</div>
Expand Down
Loading