diff options
31 files changed, 64 insertions, 21 deletions
@@ -128,6 +128,7 @@ Environment variables (will overwrite other server configs) | HMD_TWITTER_CONSUMERSECRET | no example | Twitter API consumer secret | | HMD_GITHUB_CLIENTID | no example | GitHub API client id | | HMD_GITHUB_CLIENTSECRET | no example | GitHub API client secret | +| HMD_GITLAB_SCOPE | `read_user` or `api` | GitLab API requested scope (default is `api`) (gitlab snippet import/export need `api` scope) | | HMD_GITLAB_BASEURL | no example | GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional) | | HMD_GITLAB_CLIENTID | no example | GitLab API client id | | HMD_GITLAB_CLIENTSECRET | no example | GitLab API client secret | @@ -335,8 +335,10 @@ if (config.github) { successReturnToOrRedirect: config.serverurl + '/', failureRedirect: config.serverurl + '/' })) - // github callback actions - app.get('/auth/github/callback/:noteId/:action', response.githubActions) + if (!config.gitlab.scope || config.gitlab.scope === 'api') { + // gitlab callback actions + app.get('/auth/gitlab/callback/:noteId/:action', response.gitlabActions) + } } // gitlab auth if (config.gitlab) { @@ -89,6 +89,10 @@ "description": "GitLab API client secret", "required": false }, + "HMD_GITLAB_SCOPE": { + "description": "GitLab API client scope (optional)", + "required": false + }, "HMD_DROPBOX_CLIENTID": { "description": "Dropbox API client id", "required": false diff --git a/config.json.example b/config.json.example index 9ee00c09..87c04ed0 100644 --- a/config.json.example +++ b/config.json.example @@ -36,7 +36,8 @@ "gitlab": { "baseURL": "change this", "clientID": "change this", - "clientSecret": "change this" + "clientSecret": "change this", + "scope": "use 'read_user' scope for auth user only or remove this property if you need gitlab snippet import/export support (will result to be default scope 'api')" }, "dropbox": { "clientID": "change this", diff --git a/lib/auth.js b/lib/auth.js index ef1d6464..3e129b95 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -1,3 +1,4 @@ +'use strict' // auth // external modules var passport = require('passport') @@ -90,6 +91,7 @@ function registerAuthMethod () { baseURL: config.gitlab.baseURL, clientID: config.gitlab.clientID, clientSecret: config.gitlab.clientSecret, + scope: config.gitlab.scope, callbackURL: config.serverurl + '/auth/gitlab/callback' }, callback)) } diff --git a/lib/config.js b/lib/config.js index af4c22cd..674dd113 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,3 +1,4 @@ +'use strict' // external modules var fs = require('fs') var path = require('path') @@ -101,8 +102,9 @@ var github = ((process.env.HMD_GITHUB_CLIENTID && process.env.HMD_GITHUB_CLIENTS var gitlab = ((process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSECRET) || (fs.existsSync('/run/secrets/gitlab_clientID') && fs.existsSync('/run/secrets/gitlab_clientSecret'))) ? { baseURL: process.env.HMD_GITLAB_BASEURL, clientID: handleDockerSecret('gitlab_clientID') || process.env.HMD_GITLAB_CLIENTID, - clientSecret: handleDockerSecret('gitlab_clientSecret') || process.env.HMD_GITLAB_CLIENTSECRET -} : config.gitlab || false + clientSecret: handleDockerSecret('gitlab_clientSecret') || process.env.HMD_GITLAB_CLIENTSECRET, + scope: process.env.HMD_GITLAB_SCOPE +} : (config.gitlab && config.gitlab.clientID && config.gitlab.clientSecret && config.gitlab) || false var dropbox = ((process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) || (fs.existsSync('/run/secrets/dropbox_clientID') && fs.existsSync('/run/secrets/dropbox_clientSecret'))) ? { clientID: handleDockerSecret('dropbox_clientID') || process.env.HMD_DROPBOX_CLIENTID, clientSecret: handleDockerSecret('dropbox_clientSecret') || process.env.HMD_DROPBOX_CLIENTSECRET diff --git a/lib/history.js b/lib/history.js index 69337dc5..ffed3b96 100644 --- a/lib/history.js +++ b/lib/history.js @@ -1,3 +1,4 @@ +'use strict' // history // external modules diff --git a/lib/letter-avatars.js b/lib/letter-avatars.js index 92bd36ee..7ba336b6 100644 --- a/lib/letter-avatars.js +++ b/lib/letter-avatars.js @@ -1,3 +1,4 @@ +'use strict' // external modules var randomcolor = require('randomcolor') diff --git a/lib/logger.js b/lib/logger.js index 23e302da..2111d69a 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -1,3 +1,4 @@ +'use strict' var winston = require('winston') winston.emitErrs = true diff --git a/lib/migrations/20160515114000-user-add-tokens.js b/lib/migrations/20160515114000-user-add-tokens.js index 20c0e03c..4f051887 100644 --- a/lib/migrations/20160515114000-user-add-tokens.js +++ b/lib/migrations/20160515114000-user-add-tokens.js @@ -1,3 +1,4 @@ +'use strict' module.exports = { up: function (queryInterface, Sequelize) { queryInterface.addColumn('Users', 'accessToken', Sequelize.STRING) diff --git a/lib/migrations/20160607060246-support-revision.js b/lib/migrations/20160607060246-support-revision.js index 618bb4d7..114aec2e 100644 --- a/lib/migrations/20160607060246-support-revision.js +++ b/lib/migrations/20160607060246-support-revision.js @@ -1,3 +1,4 @@ +'use strict' module.exports = { up: function (queryInterface, Sequelize) { queryInterface.addColumn('Notes', 'savedAt', Sequelize.DATE) diff --git a/lib/migrations/20160703062241-support-authorship.js b/lib/migrations/20160703062241-support-authorship.js index 98381d4e..a1d695e5 100644 --- a/lib/migrations/20160703062241-support-authorship.js +++ b/lib/migrations/20160703062241-support-authorship.js @@ -1,3 +1,4 @@ +'use strict' module.exports = { up: function (queryInterface, Sequelize) { queryInterface.addColumn('Notes', 'authorship', Sequelize.TEXT) diff --git a/lib/migrations/20161009040430-support-delete-note.js b/lib/migrations/20161009040430-support-delete-note.js index 984920b8..6e6fa20e 100644 --- a/lib/migrations/20161009040430-support-delete-note.js +++ b/lib/migrations/20161009040430-support-delete-note.js @@ -1,3 +1,4 @@ +'use strict' module.exports = { up: function (queryInterface, Sequelize) { queryInterface.addColumn('Notes', 'deletedAt', Sequelize.DATE) diff --git a/lib/migrations/20161201050312-support-email-signin.js b/lib/migrations/20161201050312-support-email-signin.js index a97d3be5..1f3abb1e 100644 --- a/lib/migrations/20161201050312-support-email-signin.js +++ b/lib/migrations/20161201050312-support-email-signin.js @@ -1,3 +1,4 @@ +'use strict' module.exports = { up: function (queryInterface, Sequelize) { queryInterface.addColumn('Users', 'email', Sequelize.TEXT) diff --git a/lib/models/author.js b/lib/models/author.js index 5e39c347..8b4f74e5 100644 --- a/lib/models/author.js +++ b/lib/models/author.js @@ -1,3 +1,4 @@ +'use strict' // external modules var Sequelize = require('sequelize') diff --git a/lib/models/index.js b/lib/models/index.js index 96babc2a..a378ee67 100644 --- a/lib/models/index.js +++ b/lib/models/index.js @@ -1,3 +1,4 @@ +'use strict' // external modules var fs = require('fs') var path = require('path') diff --git a/lib/models/note.js b/lib/models/note.js index bef9ee21..f7c25bde 100644 --- a/lib/models/note.js +++ b/lib/models/note.js @@ -1,3 +1,4 @@ +'use strict' // external modules var fs = require('fs') var path = require('path') @@ -153,7 +154,7 @@ module.exports = function (sequelize, DataTypes) { authorship = Note.updateAuthorshipByOperation(operations[i], null, authorship) } note.update({ - authorship: JSON.stringify(authorship) + authorship: authorship }).then(function (note) { return callback(null, note.id) }).catch(function (err) { diff --git a/lib/models/revision.js b/lib/models/revision.js index d8dab30a..581e7ea5 100644 --- a/lib/models/revision.js +++ b/lib/models/revision.js @@ -1,3 +1,4 @@ +'use strict' // external modules var Sequelize = require('sequelize') var async = require('async') diff --git a/lib/models/temp.js b/lib/models/temp.js index e770bb3a..2ad23fb5 100644 --- a/lib/models/temp.js +++ b/lib/models/temp.js @@ -1,3 +1,4 @@ +'use strict' // external modules var shortId = require('shortid') diff --git a/lib/models/user.js b/lib/models/user.js index f7e533b7..042b0d2f 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -1,3 +1,4 @@ +'use strict' // external modules var md5 = require('blueimp-md5') var Sequelize = require('sequelize') diff --git a/lib/realtime.js b/lib/realtime.js index cff795c7..618fdad0 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -1,3 +1,4 @@ +'use strict' // realtime // external modules var cookie = require('cookie') diff --git a/lib/response.js b/lib/response.js index 31fa18b2..13a94bbf 100755 --- a/lib/response.js +++ b/lib/response.js @@ -1,3 +1,4 @@ +'use strict' // response // external modules var fs = require('fs') diff --git a/lib/workers/dmpWorker.js b/lib/workers/dmpWorker.js index 6a1da981..b0ed0f43 100644 --- a/lib/workers/dmpWorker.js +++ b/lib/workers/dmpWorker.js @@ -1,3 +1,4 @@ +'use strict' // external modules var DiffMatchPatch = require('diff-match-patch') var dmp = new DiffMatchPatch() diff --git a/package.json b/package.json index d1b4c032..cb65eac0 100644 --- a/package.json +++ b/package.json @@ -54,8 +54,7 @@ "js-yaml": "^3.7.0", "jsdom-nogyp": "^0.8.3", "keymaster": "^1.6.2", - "list.js": "^1.3.0", - "list.pagination.js": "^0.1.1", + "list.js": "^1.5.0", "lodash": "^4.17.4", "lz-string": "1.4.4", "markdown-it": "^8.2.2", diff --git a/public/js/cover.js b/public/js/cover.js index a45a1c13..c9c2b6cb 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -54,11 +54,9 @@ const options = { '</a>' + '</li>', page: 18, - plugins: [ - window.ListPagination({ - outerWindow: 1 - }) - ] + pagination: [{ + outerWindow: 1 + }] } const historyList = new List('history', options) diff --git a/public/js/extra.js b/public/js/extra.js index 844d52c6..9dd78535 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -551,6 +551,19 @@ export function postProcess (code) { } window.postProcess = postProcess +var domevents = Object.getOwnPropertyNames(document).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(Object.getPrototypeOf(document)))).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(window))).filter(function (i) { + return !i.indexOf('on') && (document[i] === null || typeof document[i] === 'function') +}).filter(function (elem, pos, self) { + return self.indexOf(elem) === pos +}) + +export function removeDOMEvents (view) { + for (var i = 0, l = domevents.length; i < l; i++) { + view.find('[' + domevents[i] + ']').removeAttr(domevents[i]) + } +} +window.removeDOMEvents = removeDOMEvents + function generateCleanHTML (view) { const src = view.clone() const eles = src.find('*') @@ -568,7 +581,7 @@ function generateCleanHTML (view) { let name = $(value).attr('alt') name = name.substr(1) name = name.slice(0, name.length - 1) - $(value).attr('src', `https://www.tortue.me/emoji/${name}.png`) + $(value).attr('src', `https://cdnjs.cloudflare.com/ajax/libs/emojify.js/1.1.0/images/basic/${name}.png`) }) // replace video to iframe src.find('div[data-videoid]').each((key, value) => { diff --git a/public/js/index.js b/public/js/index.js index 53dd647c..e5142f29 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -42,6 +42,7 @@ import { deduplicatedHeaderId, exportToHTML, exportToRawHTML, + removeDOMEvents, finishView, generateToc, isValidURL, @@ -2859,6 +2860,7 @@ function updateViewInner () { if (result && lastResult && result.length !== lastResult.length) { updateDataAttrs(result, ui.area.markdown.children().toArray()) } lastResult = $(result).clone() } + removeDOMEvents(ui.area.markdown) finishView(ui.area.markdown) autoLinkify(ui.area.markdown) deduplicatedHeaderId(ui.area.markdown) diff --git a/public/js/pretty.js b/public/js/pretty.js index 718941a8..ff6f9dfd 100644 --- a/public/js/pretty.js +++ b/public/js/pretty.js @@ -10,6 +10,7 @@ require('highlight.js/styles/github-gist.css') import { autoLinkify, deduplicatedHeaderId, + removeDOMEvents, finishView, generateToc, md, @@ -57,6 +58,7 @@ if (md.meta.type && md.meta.type === 'slide') { } $(document.body).show() +removeDOMEvents(markdown) finishView(markdown) autoLinkify(markdown) deduplicatedHeaderId(markdown) diff --git a/public/js/slide.js b/public/js/slide.js index e743bb55..8d4b7153 100644 --- a/public/js/slide.js +++ b/public/js/slide.js @@ -4,7 +4,7 @@ require('../css/extra.css') require('../css/site.css') -import { md, updateLastChange, finishView } from './extra' +import { md, updateLastChange, removeDOMEvents, finishView } from './extra' const body = $('.slides').text() @@ -109,6 +109,7 @@ function renderSlide (event) { if (window.location.search.match(/print-pdf/gi)) { const slides = $('.slides') let title = document.title + removeDOMEvents(slides) finishView(slides) document.title = title Reveal.layout() @@ -116,6 +117,7 @@ function renderSlide (event) { const markdown = $(event.currentSlide) if (!markdown.attr('data-rendered')) { let title = document.title + removeDOMEvents(markdown) finishView(markdown) markdown.attr('data-rendered', 'true') document.title = title diff --git a/public/views/hackmd/header.ejs b/public/views/hackmd/header.ejs index bb4e3174..24282b07 100644 --- a/public/views/hackmd/header.ejs +++ b/public/views/hackmd/header.ejs @@ -42,7 +42,7 @@ <li role="presentation"><a role="menuitem" class="ui-save-gist" tabindex="-1" href="#" target="_blank"><i class="fa fa-github fa-fw"></i> Gist</a> </li> <% } %> - <% if(typeof gitlab !== 'undefined' && gitlab) { %> + <% if(typeof gitlab !== 'undefined' && gitlab && (!gitlab.scope || gitlab.scope === 'api')) { %> <li role="presentation"><a role="menuitem" class="ui-save-snippet" href="#"><i class="fa fa-gitlab fa-fw"></i> Snippet</a> </li> <% } %> @@ -54,7 +54,7 @@ </li> <li role="presentation"><a role="menuitem" class="ui-import-gist" href="#" data-toggle="modal" data-target="#gistImportModal"><i class="fa fa-github fa-fw"></i> Gist</a> </li> - <% if(typeof gitlab !== 'undefined' && gitlab) { %> + <% if(typeof gitlab !== 'undefined' && gitlab && (!gitlab.scope || gitlab.scope === 'api')) { %> <li role="presentation"><a role="menuitem" class="ui-import-snippet" href="#"><i class="fa fa-gitlab fa-fw"></i> Snippet</a> </li> <% } %> @@ -139,7 +139,7 @@ <li role="presentation"><a role="menuitem" class="ui-save-gist" tabindex="-1" href="#" target="_blank"><i class="fa fa-github fa-fw"></i> Gist</a> </li> <% } %> - <% if(typeof gitlab !== 'undefined' && gitlab) { %> + <% if(typeof gitlab !== 'undefined' && gitlab && (!gitlab.scope || gitlab.scope === 'api')) { %> <li role="presentation"><a role="menuitem" class="ui-save-snippet" href="#"><i class="fa fa-gitlab fa-fw"></i> Snippet</a> </li> <% } %> @@ -151,7 +151,7 @@ </li> <li role="presentation"><a role="menuitem" class="ui-import-gist" href="#" data-toggle="modal" data-target="#gistImportModal"><i class="fa fa-github fa-fw"></i> Gist</a> </li> - <% if(typeof gitlab !== 'undefined' && gitlab) { %> + <% if(typeof gitlab !== 'undefined' && gitlab && (!gitlab.scope || gitlab.scope === 'api')) { %> <li role="presentation"><a role="menuitem" class="ui-import-snippet" href="#"><i class="fa fa-gitlab fa-fw"></i> Snippet</a> </li> <% } %> diff --git a/webpackBaseConfig.js b/webpackBaseConfig.js index 9ab4c06a..f37eae59 100644 --- a/webpackBaseConfig.js +++ b/webpackBaseConfig.js @@ -182,7 +182,6 @@ module.exports = { 'cover-pack': [ 'babel-polyfill', 'bootstrap-validator', - 'script!listPagnation', 'expose?select2!select2', 'expose?moment!moment', 'script!js-url', @@ -365,7 +364,6 @@ module.exports = { codemirrorSpellChecker: path.join(__dirname, 'public/vendor/codemirror-spell-checker/spell-checker.min.js'), codemirrorInlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/codemirror.inline-attachment.js'), ot: path.join(__dirname, 'public/vendor/ot/ot.min.js'), - listPagnation: path.join(__dirname, 'node_modules/list.pagination.js/dist/list.pagination.min.js'), mermaid: path.join(__dirname, 'node_modules/mermaid/dist/mermaid.min.js'), handlebars: path.join(__dirname, 'node_modules/handlebars/dist/handlebars.min.js'), 'jquery-ui-resizable': path.join(__dirname, 'public/vendor/jquery-ui/jquery-ui.min.js'), |