Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pubsweet
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Tremblay McLellan
pubsweet
Commits
6fde33a5
Commit
6fde33a5
authored
6 years ago
by
Jure
Browse files
Options
Downloads
Patches
Plain Diff
feat(server): expand access to custom models in authsome
parent
26c7b27b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/server/src/helpers/authsome.js
+22
-21
22 additions, 21 deletions
packages/server/src/helpers/authsome.js
packages/server/src/models/index.js
+16
-0
16 additions, 0 deletions
packages/server/src/models/index.js
with
38 additions
and
21 deletions
packages/server/src/helpers/authsome.js
+
22
−
21
View file @
6fde33a5
...
...
@@ -5,26 +5,27 @@ const mode = require(config.get('authsome.mode'))
const
models
=
require
(
'
../models
'
)
const
authsome
=
new
Authsome
(
{
...
config
.
authsome
,
mode
},
{
// restrict methods passed to mode since these have to be shimmed on client
// any changes here should be reflected in the `withAuthsome` component of `pubsweet-client`
models
:
{
Collection
:
{
find
:
id
=>
models
.
Collection
.
find
(
id
),
},
Fragment
:
{
find
:
id
=>
models
.
Fragment
.
find
(
id
),
},
User
:
{
find
:
id
=>
models
.
User
.
find
(
id
),
},
Team
:
{
find
:
id
=>
models
.
Team
.
find
(
id
),
},
},
},
)
// be lenient with custom/extended data models based on BaseModel
// and allow them through to authsome in their entirety. If you use this
// you are responsible for providing a similar interface in the client
// as well - if you want your authsome modes to be usable on both platforms.
const
context
=
{
models
:
Object
.
assign
({},
models
)
}
// more restrictive with core models, restrict methods passed to mode since
// these have to be shimmed in the client (withAuthsome, AuthorizeWithGraphQL)
context
.
models
.
Collection
=
{
find
:
models
.
Collection
.
find
.
bind
(
models
.
Collection
),
}
context
.
models
.
Fragment
=
{
find
:
models
.
Fragment
.
find
.
bind
(
models
.
Fragment
),
}
context
.
models
.
User
=
{
find
:
models
.
User
.
find
.
bind
(
models
.
User
),
}
context
.
models
.
Team
=
{
find
:
models
.
Team
.
find
.
bind
(
models
.
Team
),
}
const
authsome
=
new
Authsome
({
...
config
.
authsome
,
mode
},
context
)
module
.
exports
=
authsome
This diff is collapsed.
Click to expand it.
packages/server/src/models/index.js
+
16
−
0
View file @
6fde33a5
const
config
=
require
(
'
config
'
)
// core models
const
models
=
{
Collection
:
'
./Collection
'
,
Fragment
:
'
./Fragment
'
,
...
...
@@ -8,3 +11,16 @@ const models = {
Object
.
keys
(
models
).
forEach
((
key
,
_
)
=>
{
module
.
exports
[
key
]
=
require
(
models
[
key
])
})
const
requireRelative
=
m
=>
require
(
require
.
resolve
(
m
,
{
paths
:
[
process
.
cwd
()]
}))
// custom data models
if
(
config
.
has
(
'
pubsweet.components
'
))
{
config
.
get
(
'
pubsweet.components
'
).
forEach
(
componentName
=>
{
const
component
=
requireRelative
(
componentName
)
if
(
component
.
modelName
)
{
module
.
exports
[
component
.
modelName
]
=
component
.
model
}
})
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment