mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-29 12:01:32 +02:00
remove scripts that are no longer used
GitOrigin-RevId: 3f6c69d856bb16e56759b7947b099293163c4615
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
const { db } = require('../app/src/infrastructure/mongojs')
|
||||
const async = require('async')
|
||||
const minimist = require('minimist')
|
||||
const UserMapper = require('../modules/overleaf-integration/app/src/OverleafUsers/UserMapper')
|
||||
|
||||
const argv = minimist(process.argv.slice(2))
|
||||
const commit = argv.commit !== undefined
|
||||
|
||||
if (!commit) {
|
||||
console.log('Doing dry run without --commit')
|
||||
}
|
||||
|
||||
db.userstubs.aggregate(
|
||||
[
|
||||
{
|
||||
$lookup: {
|
||||
localField: 'overleaf.id',
|
||||
from: 'users',
|
||||
foreignField: 'overleaf.id',
|
||||
as: 'users'
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
email: 1,
|
||||
overleaf: 1,
|
||||
_id: 1,
|
||||
'users.email': 1,
|
||||
'users.emails': 1,
|
||||
'users.overleaf': 1,
|
||||
'users._id': 1
|
||||
}
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
users: { $exists: 1 },
|
||||
'overleaf.id': { $exists: 1 }
|
||||
}
|
||||
}
|
||||
],
|
||||
(err, stubs) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
console.log('Found ' + stubs.length + ' dangling stubs')
|
||||
async.mapLimit(
|
||||
stubs,
|
||||
Number(argv.limit || '10'),
|
||||
(stub, callback) => {
|
||||
if (commit) {
|
||||
if (stub.users.length === 0) {
|
||||
console.log('Deleting stub without users:', stub._id)
|
||||
return db.userstubs.remove({ _id: stub._id }, callback)
|
||||
}
|
||||
if (stub.users.length > 1) {
|
||||
console.log('Found stub with multiple users:', stub)
|
||||
return callback()
|
||||
}
|
||||
console.log(
|
||||
'Processing stub',
|
||||
stub._id,
|
||||
'for user',
|
||||
stub.users[0]._id
|
||||
)
|
||||
UserMapper._updateUserStubReferences(
|
||||
stub.overleaf,
|
||||
stub._id,
|
||||
stub.users[0]._id,
|
||||
callback
|
||||
)
|
||||
} else {
|
||||
if (stub.users.length === 0) {
|
||||
console.log('Would delete stub without users:', stub._id)
|
||||
return callback()
|
||||
}
|
||||
if (stub.users.length > 1) {
|
||||
console.log('Found stub with multiple users:', stub)
|
||||
return callback()
|
||||
}
|
||||
console.log(
|
||||
'Would call UserMapper._updateUserStubReferences with:',
|
||||
stub.overleaf,
|
||||
stub._id,
|
||||
stub.users[0]._id
|
||||
)
|
||||
callback()
|
||||
}
|
||||
},
|
||||
err => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
console.log('All done')
|
||||
process.exit(0)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
2
services/web/scripts/import-oauth/.gitignore
vendored
2
services/web/scripts/import-oauth/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
node_modules
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
/* eslint-disable max-len */
|
||||
/**
|
||||
* run with: node import_oauth_access_grants /path/oauth_access_grants.csv
|
||||
*
|
||||
* where csv is generated from v1 with sql statement like:
|
||||
*
|
||||
* \copy ( SELECT oag.token, oag.scopes, oag.redirect_uri, resource_owner_id AS user_id, oa.uid AS client_id, oag.created_at + oag.expires_in * interval '1 second' AS expires_at FROM oauth_access_grants oag JOIN oauth_applications oa ON oag.application_id = oa.id WHERE oa.id = 1 AND oag.revoked_at IS NULL AND oag.created_at + oag.expires_in * interval '1 second' > NOW() ) to 'oauth_access_grants.csv' WITH CSV HEADER;
|
||||
*
|
||||
* this query exports the most non-expired oauth authorization codes for collabractec (1)
|
||||
*
|
||||
/* eslint-enable */
|
||||
|
||||
'use strict'
|
||||
|
||||
const OauthApplication = require('../../app/src/models/OauthApplication')
|
||||
.OauthApplication
|
||||
const OauthAuthorizationCode = require('../../app/src/models/OauthAuthorizationCode')
|
||||
.OauthAuthorizationCode
|
||||
const User = require('../../app/src/models/User').User
|
||||
const async = require('async')
|
||||
const csvParser = require('csv-parser')
|
||||
const fs = require('fs')
|
||||
const minimist = require('minimist')
|
||||
|
||||
const argv = minimist(process.argv.slice(2))
|
||||
|
||||
let lineNum = 0
|
||||
const records = []
|
||||
|
||||
fs.createReadStream(argv._[0])
|
||||
.pipe(csvParser())
|
||||
.on('data', data => {
|
||||
data.lineNum = ++lineNum
|
||||
records.push(data)
|
||||
})
|
||||
.on('end', () => {
|
||||
async.mapSeries(records, loadRecord, function(err) {
|
||||
if (err) console.error(err)
|
||||
process.exit()
|
||||
})
|
||||
})
|
||||
|
||||
function loadRecord(record, cb) {
|
||||
getOauthApplication(record.client_id, function(err, oauthApplication) {
|
||||
if (err) return cb(err)
|
||||
User.findOne(
|
||||
{ 'overleaf.id': parseInt(record.user_id) },
|
||||
{ _id: 1 },
|
||||
function(err, user) {
|
||||
if (err) return cb(err)
|
||||
if (!user) {
|
||||
console.log(
|
||||
record.lineNum +
|
||||
': User not found for ' +
|
||||
record.user_id +
|
||||
' - skipping'
|
||||
)
|
||||
return cb()
|
||||
}
|
||||
const newRecord = {
|
||||
authorizationCode: record.token,
|
||||
expiresAt: record.expires_at,
|
||||
oauthApplication_id: oauthApplication._id,
|
||||
redirectUri: record.redirect_uri,
|
||||
scope: record.scopes,
|
||||
user_id: user._id
|
||||
}
|
||||
console.log(
|
||||
record.lineNum +
|
||||
'Creating OauthAuthorizationCode for User ' +
|
||||
user._id
|
||||
)
|
||||
OauthAuthorizationCode.update(
|
||||
newRecord,
|
||||
newRecord,
|
||||
{ upsert: true },
|
||||
cb
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const oauthApplications = {}
|
||||
|
||||
function getOauthApplication(clientId, cb) {
|
||||
if (oauthApplications[clientId]) return cb(null, oauthApplications[clientId])
|
||||
OauthApplication.findOne({ id: clientId }, { _id: 1 }, function(
|
||||
err,
|
||||
oauthApplication
|
||||
) {
|
||||
if (err) return cb(err)
|
||||
if (!oauthApplication) return cb(new Error('oauthApplication not found'))
|
||||
oauthApplications[clientId] = oauthApplication
|
||||
cb(null, oauthApplication)
|
||||
})
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/* eslint-disable max-len */
|
||||
/**
|
||||
* run with: node import_oauth_access_tokens /path/import_oauth_access_tokens.csv
|
||||
*
|
||||
* where csv is generated from v1 with sql statement like:
|
||||
*
|
||||
* \copy ( SELECT oat.token, oat.refresh_token, oat.scopes, oat.resource_owner_id AS user_id, u.email, u.confirmed_at, oa.uid AS client_id, oat.created_at + oat.expires_in * interval '1 second' AS expires_at FROM oauth_access_tokens oat LEFT JOIN oauth_access_tokens oat2 ON oat2.previous_refresh_token = oat.refresh_token JOIN oauth_applications oa ON oat.application_id = oa.id JOIN users u ON u.id = oat.resource_owner_id WHERE (oat2.id IS NULL OR oat2.created_at > NOW() - interval '24 hour') AND oat.revoked_at IS NULL AND (oat.application_id = 1 OR (oat.application_id = 2 AND oat.created_at + oat.expires_in * interval '1 second' > NOW())) ) to 'oauth_access_tokens.csv' WITH CSV HEADER;
|
||||
*
|
||||
* this query exports the most recent collabractec (1) and gitbridge (2) tokens for
|
||||
* each user. expired tokens are exported for collabratec but not for gitbridge.
|
||||
*
|
||||
* tokens that have been refreshed are not exported if it has been over 24 hours
|
||||
* since the new token was issued.
|
||||
*/
|
||||
/* eslint-enable */
|
||||
|
||||
'use strict'
|
||||
|
||||
const OauthApplication = require('../../app/src/models/OauthApplication')
|
||||
.OauthApplication
|
||||
const OauthAccessToken = require('../../app/src/models/OauthAccessToken')
|
||||
.OauthAccessToken
|
||||
const User = require('../../app/src/models/User').User
|
||||
const UserMapper = require('../../modules/overleaf-integration/app/src/OverleafUsers/UserMapper')
|
||||
const async = require('async')
|
||||
const csvParser = require('csv-parser')
|
||||
const fs = require('fs')
|
||||
const minimist = require('minimist')
|
||||
|
||||
const argv = minimist(process.argv.slice(2))
|
||||
|
||||
let lineNum = 0
|
||||
const records = []
|
||||
|
||||
fs.createReadStream(argv._[0])
|
||||
.pipe(csvParser())
|
||||
.on('data', data => {
|
||||
data.lineNum = ++lineNum
|
||||
records.push(data)
|
||||
})
|
||||
.on('end', () => {
|
||||
async.mapSeries(records, loadRecord, function(err) {
|
||||
if (err) console.error(err)
|
||||
process.exit()
|
||||
})
|
||||
})
|
||||
|
||||
function loadRecord(record, cb) {
|
||||
getOauthApplication(record.client_id, function(err, oauthApplication) {
|
||||
if (err) return cb(err)
|
||||
const overleafId = parseInt(record.user_id)
|
||||
User.findOne({ 'overleaf.id': overleafId }, { _id: 1 }, function(
|
||||
err,
|
||||
user
|
||||
) {
|
||||
if (err) return cb(err)
|
||||
if (user) {
|
||||
console.log(
|
||||
record.lineNum + ': Creating OauthAccessToken for User ' + user._id
|
||||
)
|
||||
createOauthAccessToken(user._id, oauthApplication._id, record, cb)
|
||||
} else {
|
||||
// create user stub
|
||||
const olUser = {
|
||||
confirmed_at: record.confirmed_at,
|
||||
email: record.email,
|
||||
id: overleafId
|
||||
}
|
||||
console.log(record.lineNum + ': User not found for ' + record.user_id)
|
||||
return UserMapper.getSlIdFromOlUser(olUser, function(err, userStubId) {
|
||||
if (err) return cb(err)
|
||||
console.log(
|
||||
record.lineNum +
|
||||
': Creating OauthAccessToken for UserStub ' +
|
||||
userStubId
|
||||
)
|
||||
createOauthAccessToken(userStubId, oauthApplication._id, record, cb)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function createOauthAccessToken(userId, oauthApplicationId, record, cb) {
|
||||
const newRecord = {
|
||||
accessToken: record.token,
|
||||
accessTokenExpiresAt: record.expires_at,
|
||||
oauthApplication_id: oauthApplicationId,
|
||||
refreshToken: record.refresh_token,
|
||||
scope: record.scopes,
|
||||
user_id: userId
|
||||
}
|
||||
OauthAccessToken.update(newRecord, newRecord, { upsert: true }, cb)
|
||||
}
|
||||
|
||||
const oauthApplications = {}
|
||||
|
||||
function getOauthApplication(clientId, cb) {
|
||||
if (oauthApplications[clientId]) return cb(null, oauthApplications[clientId])
|
||||
OauthApplication.findOne({ id: clientId }, { _id: 1 }, function(
|
||||
err,
|
||||
oauthApplication
|
||||
) {
|
||||
if (err) return cb(err)
|
||||
if (!oauthApplication) return cb(new Error('oauthApplication not found'))
|
||||
oauthApplications[clientId] = oauthApplication
|
||||
cb(null, oauthApplication)
|
||||
})
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/* eslint-disable max-len */
|
||||
/**
|
||||
* run with: node import_oauth_applications /path/oauth_applications.csv
|
||||
*
|
||||
* where csv is generated from v1 with sql statement like:
|
||||
*
|
||||
* \copy (SELECT * FROM oauth_applications) to 'oauth_applications.csv' WITH CSV HEADER;
|
||||
*/
|
||||
/* eslint-enable */
|
||||
|
||||
'use strict'
|
||||
|
||||
const OauthApplication = require('../../app/src/models/OauthApplication')
|
||||
.OauthApplication
|
||||
const async = require('async')
|
||||
const csvParser = require('csv-parser')
|
||||
const fs = require('fs')
|
||||
const minimist = require('minimist')
|
||||
|
||||
const argv = minimist(process.argv.slice(2))
|
||||
|
||||
const records = []
|
||||
|
||||
fs.createReadStream(argv._[0])
|
||||
.pipe(csvParser())
|
||||
.on('data', data => records.push(data))
|
||||
.on('end', () => {
|
||||
async.mapSeries(records, loadRecord, function(err) {
|
||||
if (err) console.error(err)
|
||||
process.exit()
|
||||
})
|
||||
})
|
||||
|
||||
function loadRecord(record, cb) {
|
||||
const newRecord = {
|
||||
clientSecret: record.secret,
|
||||
id: record.uid,
|
||||
// doorkeeper does not define grant types so add all supported
|
||||
grants: ['authorization_code', 'refresh_token', 'password'],
|
||||
name: record.name,
|
||||
// redirect uris are stored new-line separated
|
||||
redirectUris: record.redirect_uri.split(/\r?\n/),
|
||||
// scopes are stored space separated
|
||||
scopes: record.scopes.split(/\s+/)
|
||||
}
|
||||
console.log('Creating OauthApplication ' + newRecord.name)
|
||||
OauthApplication.update(newRecord, newRecord, { upsert: true }, cb)
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/* eslint-disable max-len */
|
||||
/**
|
||||
* run with: node import_user_collabratec_ids /path/user_collabratec_ids.csv
|
||||
*
|
||||
* where csv is generated from v1 with sql statement like:
|
||||
*
|
||||
* \copy ( SELECT ut.user_id, u.email, u.confirmed_at, ut.team_user_id AS collabratec_id FROM user_teams ut JOIN teams t ON ut.team_id = t.id JOIN users u ON ut.user_id = u.id WHERE t.name = 'IEEECollabratec' AND ut.removed_at IS NULL AND ut.team_user_id IS NOT NULL ) to 'user_collabratec_ids.csv' WITH CSV HEADER;
|
||||
*/
|
||||
/* eslint-enable */
|
||||
|
||||
'use strict'
|
||||
|
||||
const UserMapper = require('../../modules/overleaf-integration/app/src/OverleafUsers/UserMapper')
|
||||
const User = require('../../app/src/models/User').User
|
||||
const UserStub = require('../../app/src/models/UserStub').UserStub
|
||||
const async = require('async')
|
||||
const csvParser = require('csv-parser')
|
||||
const fs = require('fs')
|
||||
const minimist = require('minimist')
|
||||
|
||||
const argv = minimist(process.argv.slice(2))
|
||||
|
||||
let lineNum = 0
|
||||
const records = []
|
||||
|
||||
fs.createReadStream(argv._[0])
|
||||
.pipe(csvParser())
|
||||
.on('data', data => {
|
||||
data.lineNum = ++lineNum
|
||||
records.push(data)
|
||||
})
|
||||
.on('end', () => {
|
||||
async.mapSeries(records, loadRecord, function(err) {
|
||||
if (err) console.error(err)
|
||||
process.exit()
|
||||
})
|
||||
})
|
||||
|
||||
function loadRecord(record, cb) {
|
||||
const overleafId = parseInt(record.user_id)
|
||||
User.findOne(
|
||||
{ 'overleaf.id': overleafId },
|
||||
{ _id: 1, thirdPartyIdentifiers: 1 },
|
||||
function(err, user) {
|
||||
if (err) return cb(err)
|
||||
const query = {
|
||||
'thirdPartyIdentifiers.providerId': {
|
||||
$ne: 'collabratec'
|
||||
}
|
||||
}
|
||||
const update = {
|
||||
$push: {
|
||||
thirdPartyIdentifiers: {
|
||||
externalUserId: record.collabratec_id,
|
||||
externalData: {},
|
||||
providerId: 'collabratec'
|
||||
}
|
||||
}
|
||||
}
|
||||
if (user) {
|
||||
console.log(record.lineNum + ': setting TPI for User ' + user._id)
|
||||
query._id = user._id
|
||||
User.update(query, update, cb)
|
||||
} else {
|
||||
// create user stub
|
||||
const olUser = {
|
||||
confirmed_at: record.confirmed_at,
|
||||
email: record.email,
|
||||
id: overleafId
|
||||
}
|
||||
console.log(record.lineNum + ': User not found for ' + record.user_id)
|
||||
return UserMapper.getSlIdFromOlUser(olUser, function(err, userStubId) {
|
||||
if (err) return cb(err)
|
||||
console.log(
|
||||
record.lineNum + ': setting TPI for UserStub ' + userStubId
|
||||
)
|
||||
query._id = userStubId
|
||||
UserStub.update(query, update, cb)
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"csv-parser": "^2.2.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user