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

Auth module #1019

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cecf400
Remove sliver as a dependency
3ach Mar 15, 2019
0add640
Add virtual users
3ach Mar 15, 2019
226d4e9
Add new share link backend
3ach Mar 15, 2019
643a8a4
Create alias
3ach Apr 16, 2019
a1fd859
Initial pass at auth
3ach Sep 16, 2019
9072bd4
Add privilege management
3ach Oct 4, 2019
f6b0bb6
Copy ownedBy into auth table
3ach Oct 4, 2019
a75cc62
Update privileges to include sharing
3ach Oct 6, 2019
302ff06
Deal with spoofing
3ach Oct 6, 2019
7ee2d6e
Shorten buttons
3ach Oct 10, 2019
70b4827
Fix setup flow
3ach Oct 11, 2019
6336d60
Fix return link on manage sharing page
3ach Oct 15, 2019
e63a93d
Fix back button on share link page
3ach Oct 15, 2019
7a8f89e
Fix alias on spoofed instances
3ach Oct 15, 2019
e578d58
Show shared on Shared with Me
3ach Nov 3, 2019
37b8055
Fix sharing page
3ach Nov 16, 2019
5fdfff8
Show privilege for share links
3ach Nov 21, 2019
5b670eb
UpdateShare
3ach Jan 30, 2020
52a3579
Allow editing share privileges
3ach Feb 3, 2020
ed0ae06
Show non-collection shared
3ach Feb 3, 2020
f01b95b
Allow edit of shared parts
3ach Feb 3, 2020
e547e39
Fix start issue
3ach Feb 3, 2020
f5fe7ac
Startup bugs
3ach Feb 3, 2020
27b9443
Fix app.js
3ach Feb 25, 2020
10e1ce0
Change addowner to sharing tests
3ach Feb 25, 2020
ff18abc
Fix API tokens and logout
3ach Feb 25, 2020
6216f9d
Fix metadata check
3ach Feb 28, 2020
31ae25d
Fix tests
3ach Feb 28, 2020
2a62795
Don't die on request abort
3ach Feb 28, 2020
6254b7c
Fix shared with me
3ach May 11, 2020
f936a8c
Fix viewing share link privileges
3ach May 11, 2020
54e5383
Fix infinite redirect
3ach May 11, 2020
382239f
Update tests
3ach May 11, 2020
13c5e15
Remove merge artifact
3ach May 12, 2020
476cb53
Public editing
3ach May 12, 2020
25eca6b
Make public access
3ach May 13, 2020
8a980f1
Update tests
3ach May 13, 2020
2a91547
Fix make public
3ach May 16, 2020
30c045d
Fix migration with spoofing
3ach May 26, 2020
bf0afc9
Fix messaging
3ach May 26, 2020
811156a
Allow sharing of public items
3ach May 26, 2020
009cb71
Add SQL useful for debugging
3ach May 29, 2020
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
24 changes: 24 additions & 0 deletions browser/synbiohub.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,3 +735,27 @@ $('form[action="/setup"] select[name="authProvider"]').change(function () {
parentEl.find('div[class^="auth-"]').hide();
parentEl.find('div.auth-' + providerName).show();
})

$(document).on('click', '.copyShare', function() {
let $row = $(this).closest('tr');
let shareLink = $row.find('#link').first().text();

let textArea = document.createElement("textarea");
textArea.value = shareLink;
document.body.appendChild(textArea);

textArea.select()
textArea.setSelectionRange(0, 9999999); // for mobile?
document.execCommand('copy');

textArea.remove();
})

$(document).on('change', 'select#privilege', function() {
let name = $(this).attr('name').substring(6);
let value = $(this).val();
let updatePath = location.pathname.split('/').slice(0, -1).join('/') + '/updateShare'

$.post(updatePath, { authId: name, newPrivilege: value })
})

51 changes: 0 additions & 51 deletions lib/actions/addOwnedBy.js

This file was deleted.

44 changes: 23 additions & 21 deletions lib/actions/makePublic.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
const {
getCollectionMetaData
} = require('../query/collection')

var pug = require('pug')

const pug = require('pug')
const {
fetchSBOLObjectRecursive
} = require('../fetch/fetch-sbol-object-recursive')

const serializeSBOL = require('../serializeSBOL')

var config = require('../config')

var loadTemplate = require('../loadTemplate')

var extend = require('xtend')

var getUrisFromReq = require('../getUrisFromReq')

var sparql = require('../sparql/sparql')

const config = require('../config')
const loadTemplate = require('../loadTemplate')
const extend = require('xtend')
const getUrisFromReq = require('../getUrisFromReq')
const sparql = require('../sparql/sparql')
const tmp = require('tmp-promise')

var fs = require('mz/fs')

const fs = require('mz/fs')
const prepareSubmission = require('../prepare-submission')
const access = require('../auth/access')
const db = require('../db')
const generateGraph = require('../generateGraph')

module.exports = function (req, res) {
req.setTimeout(0) // no timeout
Expand Down Expand Up @@ -74,7 +66,7 @@ module.exports = function (req, res) {
var citations = []
var collectionUri

const { graphUri, uri } = getUrisFromReq(req, res)
const { graphUri, baseUri, uri } = getUrisFromReq(req, res)

if (req.method === 'POST') {
overwriteMerge = req.body.tabState === 'new' ? '0' : '2'
Expand Down Expand Up @@ -146,7 +138,7 @@ module.exports = function (req, res) {
console.log('check if exists:' + uri)

return getCollectionMetaData(collectionUri, null /* public store */).then((result) => {
if (!result) {
if (!result || !result.displayId) {
/* not found */
console.log('not found')
if (overwriteMerge === '0') {
Expand Down Expand Up @@ -233,6 +225,9 @@ module.exports = function (req, res) {
})
}).then((result) => {
const { success, errorLog, resultFilename } = result
let publicPrefix = config.get('databasePrefix') + 'public/' + collectionId
let privatePrefix = baseUri
access.makePublic(privatePrefix, publicPrefix, uri)

if (!success) {
if (!req.accepts('text/html')) {
Expand All @@ -251,7 +246,14 @@ module.exports = function (req, res) {

console.log('upload')

return sparql.uploadFile(null, resultFilename, 'application/rdf+xml').then(function removeSubmission (next) {
return sparql.uploadFile(null, resultFilename, 'application/rdf+xml').then(async function removeSubmission (next) {
let user = await db.model.User.findOne({ where: { graphUri: graphUri } })
let rootCollectionIdentity = config.get('databasePrefix') + `public/${collectionId}/${collectionId}_collection/${version}`

let graph = { }
graph[rootCollectionIdentity] = generateGraph(rootCollectionIdentity, { graphUri: null }) // second param should be a user, but no user owns public graph
access.grant(user, graph, 3, 'owner from make public')

if (req.params.version !== 'current') {
console.log('remove')

Expand Down
51 changes: 0 additions & 51 deletions lib/actions/removeOwnedBy.js

This file was deleted.

26 changes: 26 additions & 0 deletions lib/actions/removeShare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const db = require('../db')

module.exports = async function (req, res) {
let toRemove = [ req.params.id ]

while (toRemove.length > 0) {
let id = toRemove.shift()
let children = await db.model.Auth.findAll({
where: {
rootAuth: id
}
})

children.forEach(child => {
toRemove.push(child.id)
})

db.model.Auth.destroy({
where: {
id: id
}
})
}

res.redirect(req.header('Referer'))
}
10 changes: 10 additions & 0 deletions lib/actions/removeShareLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const alias = require('../auth/alias')
const virtualUser = require('../auth/virtualUser')

module.exports = async function (req, res) {
let tag = req.params.tag
let user = await alias.remove(tag)
virtualUser.remove(user)

res.redirect(req.header('Referer')) // go back
}
2 changes: 1 addition & 1 deletion lib/actions/resetPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function (req, res) {
return
}

req.session.user = user.id
req.session.users = [user.id]
req.user = user

var locals = {
Expand Down
2 changes: 2 additions & 0 deletions lib/actions/setNewPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = async function (req, res) {
user.password = User.hashPassword(req.body.password1)

await user.save()
req.session.users = [user.id]
req.user = user

req.session.user = user.id
if (!req.accepts('text/html')) {
Expand Down
15 changes: 15 additions & 0 deletions lib/actions/updateShare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const privileges = require('../auth/privileges')
const access = require('../auth/access')

module.exports = function updateShare (req, res) {
if (!privileges.canShare(req.privilege)) {
res.sendStatus(403).end()
return
}

let authId = req.body.authId
let desiredPrivilege = req.body.newPrivilege

access.updatePrivilege(authId, desiredPrivilege)
res.sendStatus(200).end()
}
6 changes: 4 additions & 2 deletions lib/apiTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ function deleteToken (token) {
function getUserFromToken (token) {
const uid = tokens[token]

if (uid === undefined) { return null }
if (uid === undefined) {
return Promise.reject(new Error('No user'))
}

return db.model.User.findById(uid)
return db.model.User.findById(uid, { include: [db.model.UserExternalProfile] })
}

function getUserIdFromToken (token) {
Expand Down
Loading