Skip to content

Commit

Permalink
Merge pull request #4 from fabrix-app/v1.1
Browse files Browse the repository at this point in the history
[chore] extendable models
  • Loading branch information
scott-wyatt authored Aug 3, 2018
2 parents b419632 + bb7b0f1 commit 38b90d6
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 76 deletions.
2 changes: 1 addition & 1 deletion lib/api/models/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Event extends Model {
}
}

static schema (app, Sequelize?) {
static schema (app, Sequelize?): {[key: string]: any} {
return {
// The Target Model or object
object: {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/models/Permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { FabrixModel as Model } from '@fabrix/fabrix/dist/common'
import { SequelizeResolver } from '@fabrix/spool-sequelize'

export class Permission extends Model {
static config(app, Sequelize) {
static config(app, Sequelize): {[key: string]: any} {
return {
options: {
underscored: true
}
}
}

static schema(app, Sequelize) {
static schema(app, Sequelize): {[key: string]: any} {
return {
action: {
type: Sequelize.STRING,
Expand Down
4 changes: 2 additions & 2 deletions lib/api/models/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FabrixModel as Model } from '@fabrix/fabrix/dist/common'
import { SequelizeResolver } from '@fabrix/spool-sequelize'

export class Resource extends Model {
public static config(app, Sequelize) {
public static config(app, Sequelize): {[key: string]: any} {
return {
// More information about supported models options here : http://docs.sequelizejs.com/en/latest/docs/models-definition/#configuration
options: {
Expand All @@ -11,7 +11,7 @@ export class Resource extends Model {
}
}

public static schema(app, Sequelize) {
public static schema(app, Sequelize): {[key: string]: any} {
return {
type: {
type: Sequelize.ENUM,
Expand Down
4 changes: 2 additions & 2 deletions lib/api/models/Role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { FabrixModel as Model } from '@fabrix/fabrix/dist/common'
import { SequelizeResolver } from '@fabrix/spool-sequelize'

export class Role extends Model {
static config(app, Sequelize) {
static config(app, Sequelize): {[key: string]: any} {
return {
options: {
underscored: true
}
}
}

static schema(app, Sequelize) {
static schema(app, Sequelize): {[key: string]: any} {
return {
name: {
type: Sequelize.STRING,
Expand Down
7 changes: 4 additions & 3 deletions lib/api/models/User.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { FabrixApp } from '@fabrix/fabrix'
import {
User as PassportUser,
UserResolver as PassportUserResolver
} from '@fabrix/spool-passport/dist/api/models/User'
import { merge, defaultsDeep } from 'lodash'
import { queryDefaults } from '../utils'

import { Utils } from '@fabrix/spool-sequelize'

export class UserResolver extends PassportUserResolver {
findByIdDefault(criteria, options: {[key: string]: any} = {}) {
options = merge(options, queryDefaults.User.default(this.app))
Expand All @@ -20,8 +21,8 @@ export class UserResolver extends PassportUserResolver {

export class User extends PassportUser {

static config(app, Sequelize) {
return defaultsDeep({}, PassportUser.config(app, Sequelize), {
static config(app, Sequelize): {[key: string]: any} {
return Utils.mergeConfig(PassportUser.config(app, Sequelize), {
options: {
underscored: true,
hooks: {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/models/UserItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { SequelizeResolver } from '@fabrix/spool-sequelize'
*/
export class UserItem extends Model {

static config (app, Sequelize) {
static config (app, Sequelize): {[key: string]: any} {
return {
options: {
underscored: true
}
}
}

static schema (app, Sequelize) {
static schema (app, Sequelize): {[key: string]: any} {
return {
// Record ID
id: {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/models/UserRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { SequelizeResolver } from '@fabrix/spool-sequelize'
*/
export class UserRole extends Model {

static config (app, Sequelize) {
static config (app, Sequelize): {[key: string]: any} {
return {
options: {
underscored: true
}
}
}

static schema (app, Sequelize) {
static schema (app, Sequelize): {[key: string]: any} {
return {
id: {
type: Sequelize.INTEGER,
Expand Down
4 changes: 2 additions & 2 deletions lib/api/models/UserUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class UserUploadResolver extends SequelizeResolver {
*/
export class UserUpload extends Model {

static config (app, Sequelize) {
static config (app, Sequelize): {[key: string]: any} {
return {
// migrate: 'drop', // override default models configurations if needed
// store: 'uploads',
Expand All @@ -46,7 +46,7 @@ export class UserUpload extends Model {
}
}

static schema (app, Sequelize) {
static schema (app, Sequelize): {[key: string]: any} {
return {
// Upload ID
upload_id: {
Expand Down
68 changes: 17 additions & 51 deletions package-lock.json

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

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-permissions",
"version": "1.1.3",
"version": "1.1.4",
"description": "Spool: Permissions (ACL) for Fabrix using Spool-Passport",
"homepage": "https://fabrix.app",
"author": {
Expand Down Expand Up @@ -40,7 +40,7 @@
"test"
],
"dependencies": {
"papaparse": "^4.3.6",
"papaparse": "^4.6.0",
"joi": "^13.4.0",
"multer": "^1.2.1",
"shortid": "^2.2.12"
Expand All @@ -49,11 +49,11 @@
"@fabrix/fabrix": "^1.1.3",
"@fabrix/lint": "^1.0.0-alpha.3",
"@fabrix/spool-email": "^1.1.0",
"@fabrix/spool-express": "^1.1.4",
"@fabrix/spool-express": "^1.1.5",
"@fabrix/spool-i18n": "^1.1.0",
"@fabrix/spool-passport": "^1.1.5",
"@fabrix/spool-passport": "^1.1.6",
"@fabrix/spool-router": "^1.1.3",
"@fabrix/spool-sequelize": "^1.1.4",
"@fabrix/spool-sequelize": "^1.1.8",
"@fabrix/spool-tapestries": "^1.1.3",
"@types/lodash": "^4.14.109",
"@types/node": "~10.3.4",
Expand All @@ -74,12 +74,12 @@
},
"peerDependencies": {
"@fabrix/fabrix": "^1.1.3",
"@fabrix/spool-express": "^1.1.4",
"@fabrix/spool-express": "^1.1.5",
"@fabrix/spool-router": "^1.1.3",
"@fabrix/spool-i18n": "^1.1.0",
"@fabrix/spool-sequelize": "^1.1.4",
"@fabrix/spool-sequelize": "^1.1.8",
"@fabrix/spool-email": "^1.1.0",
"@fabrix/spool-passport": "^1.1.5"
"@fabrix/spool-passport": "^1.1.6"
},
"engines": {
"node": ">= 7.6.0"
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ const App = {
}
}
},
'/success/all/permissions': {
'GET': 'TestController.success',
config: {
app: {
permissions: {
resource_name: 'successAllRoute',
roles: ['admin', 'registered', 'public']
}
}
}
},
'/failure/public/permissions': {
'GET': 'TestController.failure',
config: {
Expand Down
10 changes: 9 additions & 1 deletion test/integration/policies/CheckPermissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('CheckPermissions', () => {
.set('Accept', 'application/json') //set header for this test
.expect(200)
.end((err, res) => {
assert.equal(res.body.length, 44)
assert.equal(res.body.length, 47)
done(err)
})
})
Expand All @@ -107,6 +107,14 @@ describe('CheckPermissions', () => {
})
})

it('should allow to access Route with granted permissions for non logged users', done => {
request.get('/api/success/all/permissions')
.expect(200)
.end((err, res) => {
done(err)
})
})

it('should not allow to access Route with no permissions for non logged users', done => {
request.get('/api/failure/public/permissions')
.set('Accept', 'application/json') //set header for this test
Expand Down

0 comments on commit 38b90d6

Please sign in to comment.