@galadrim/galadmin 0.1.206 → 0.1.208

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -339,6 +339,7 @@ export type AuthRole = {
339
339
  usernameField: string;
340
340
  passwordField: string;
341
341
  idField: string;
342
+ filters?: string;
342
343
  };
343
344
  export type Config = {
344
345
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galadrim/galadmin",
3
- "version": "0.1.206",
3
+ "version": "0.1.208",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/src/api.ts CHANGED
@@ -212,7 +212,7 @@ export default (db, config, user) => {
212
212
  customQuery: view.customQuery,
213
213
  join: view.join,
214
214
  selectExpression: view.selectExpression,
215
- orderBy: req.body.orderBy || (view.subviews && req.body.subviewIndex !== undefined ? view.subviews[req.body.subviewIndex]?.orderBy : null) || view.orderBy,
215
+ orderBy: [req.body.orderBy || (view.subviews && req.body.subviewIndex !== undefined ? view.subviews[req.body.subviewIndex]?.orderBy : null) || view.orderBy, view.primaryId].filter(x => x).join(", "),
216
216
  isDesc: req.body.isDesc === null ? view.isDesc : req.body.isDesc,
217
217
  primaryId: view.primaryId,
218
218
  query: req.body.query,
package/src/index.ts CHANGED
@@ -84,7 +84,8 @@ export default (config: Config): any => {
84
84
  res.send({ success: true })
85
85
  } else if (config.authRoles) {
86
86
  for (const authRole of config.authRoles) {
87
- const { rows } = await db.query("SELECT * FROM ?? WHERE ?? = ?", [authRole.table, authRole.usernameField, req.body.username]);
87
+ const filters = authRole.filters ? `AND ${authRole.filters}` : ""
88
+ const { rows } = await db.query(`SELECT * FROM ?? WHERE ?? = ? ${filters}`, [authRole.table, authRole.usernameField, req.body.username]);
88
89
  let user;
89
90
  for (const row of rows) {
90
91
  if (await passwordMatch(req.body.password, row[authRole.passwordField])) {
@@ -183,7 +183,7 @@ export type CustomAction = {
183
183
  successMessage?: string;
184
184
  isBulkAction?: boolean;
185
185
  /**
186
- * A callback that will be called after the action finishes successfully
186
+ * A callback that will be called after the action finishes successfully
187
187
  * If set, the default success action will be ignored
188
188
  * @param record The record the action was called on
189
189
  * @param response The response from the action
@@ -406,6 +406,7 @@ export type AuthRole = {
406
406
  usernameField: string;
407
407
  passwordField: string;
408
408
  idField: string;
409
+ filters?: string;
409
410
  };
410
411
 
411
412
  export type Config = {