summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-04-20 10:56:41 +0200
committerJarka Kadlecova <jarka@gitlab.com>2017-04-26 12:51:06 +0200
commit87327c5845a7feec92e546dc0da42282ac27de40 (patch)
tree87134624b3911bf49b2799fecd89f4a4334dc0c9 /app/controllers
parenta9da37434af6d44c5f851affd4bd69b370760e8e (diff)
downloadgitlab-ce-87327c5845a7feec92e546dc0da42282ac27de40.tar.gz
Support preview_markdown action for personal_snippets
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/concerns/markdown_preview.rb19
-rw-r--r--app/controllers/projects/wikis_controller.rb21
-rw-r--r--app/controllers/projects_controller.rb19
-rw-r--r--app/controllers/snippets_controller.rb5
4 files changed, 36 insertions, 28 deletions
diff --git a/app/controllers/concerns/markdown_preview.rb b/app/controllers/concerns/markdown_preview.rb
new file mode 100644
index 00000000000..40eff267348
--- /dev/null
+++ b/app/controllers/concerns/markdown_preview.rb
@@ -0,0 +1,19 @@
+module MarkdownPreview
+ private
+
+ def render_markdown_preview(text, markdown_context = {})
+ render json: {
+ body: view_context.markdown(text, markdown_context),
+ references: {
+ users: preview_referenced_users(text)
+ }
+ }
+ end
+
+ def preview_referenced_users(text)
+ extractor = Gitlab::ReferenceExtractor.new(@project, current_user)
+ extractor.analyze(text, author: current_user)
+
+ extractor.users.map(&:username)
+ end
+end
diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb
index c5e24b9e365..96125684da0 100644
--- a/app/controllers/projects/wikis_controller.rb
+++ b/app/controllers/projects/wikis_controller.rb
@@ -1,4 +1,6 @@
class Projects::WikisController < Projects::ApplicationController
+ include MarkdownPreview
+
before_action :authorize_read_wiki!
before_action :authorize_create_wiki!, only: [:edit, :create, :history]
before_action :authorize_admin_wiki!, only: :destroy
@@ -91,21 +93,13 @@ class Projects::WikisController < Projects::ApplicationController
)
end
- def preview_markdown
- text = params[:text]
-
- ext = Gitlab::ReferenceExtractor.new(@project, current_user)
- ext.analyze(text, author: current_user)
-
- render json: {
- body: view_context.markdown(text, pipeline: :wiki, project_wiki: @project_wiki, page_slug: params[:id]),
- references: {
- users: ext.users.map(&:username)
- }
- }
+ def git_access
end
- def git_access
+ def preview_markdown
+ context = { pipeline: :wiki, project_wiki: @project_wiki, page_slug: params[:id] }
+
+ render_markdown_preview(params[:text], context)
end
private
@@ -115,7 +109,6 @@ class Projects::WikisController < Projects::ApplicationController
# Call #wiki to make sure the Wiki Repo is initialized
@project_wiki.wiki
-
@sidebar_wiki_entries = WikiPage.group_by_directory(@project_wiki.pages.first(15))
rescue ProjectWiki::CouldNotCreateWikiError
flash[:notice] = "Could not create Wiki Repository at this time. Please try again later."
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 6807c37f972..9f6ee4826e6 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -1,6 +1,7 @@
class ProjectsController < Projects::ApplicationController
include IssuableCollections
include ExtractsPath
+ include MarkdownPreview
before_action :authenticate_user!, except: [:index, :show, :activity, :refs]
before_action :project, except: [:index, :new, :create]
@@ -216,20 +217,6 @@ class ProjectsController < Projects::ApplicationController
}
end
- def preview_markdown
- text = params[:text]
-
- ext = Gitlab::ReferenceExtractor.new(@project, current_user)
- ext.analyze(text, author: current_user)
-
- render json: {
- body: view_context.markdown(text),
- references: {
- users: ext.users.map(&:username)
- }
- }
- end
-
def refs
branches = BranchesFinder.new(@repository, params).execute.map(&:name)
@@ -252,6 +239,10 @@ class ProjectsController < Projects::ApplicationController
render json: options.to_json
end
+ def preview_markdown
+ render_markdown_preview(params[:text])
+ end
+
private
# Render project landing depending of which features are available
diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb
index f3fd3da8b20..056910fad67 100644
--- a/app/controllers/snippets_controller.rb
+++ b/app/controllers/snippets_controller.rb
@@ -2,6 +2,7 @@ class SnippetsController < ApplicationController
include ToggleAwardEmoji
include SpammableActions
include SnippetsActions
+ include MarkdownPreview
before_action :snippet, only: [:show, :edit, :destroy, :update, :raw, :download]
@@ -77,6 +78,10 @@ class SnippetsController < ApplicationController
)
end
+ def preview_markdown
+ render_markdown_preview(params[:text], skip_project_check: true)
+ end
+
protected
def snippet