summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHannes Rosenögger <123haynes@gmail.com>2015-01-08 18:15:50 +0100
committerHannes Rosenögger <123haynes@gmail.com>2015-03-12 19:13:51 +0100
commit7ff9c8229d8df09be5927086222aad0cd5d71477 (patch)
treefb6657b673feb7fb48ecf142cea8c8728fb36e10 /app
parentd66148ef393f1748c669c934eec4e928d92ef36a (diff)
downloadgitlab-ce-7ff9c8229d8df09be5927086222aad0cd5d71477.tar.gz
Add a service to support external wikis
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/services_controller.rb2
-rw-r--r--app/helpers/external_wiki_helper.rb11
-rw-r--r--app/models/project.rb1
-rw-r--r--app/models/project_services/external_wiki_service.rb48
-rw-r--r--app/views/layouts/nav/_project.html.haml2
5 files changed, 62 insertions, 2 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb
index 570447c746c..9a484c109ba 100644
--- a/app/controllers/projects/services_controller.rb
+++ b/app/controllers/projects/services_controller.rb
@@ -53,7 +53,7 @@ class Projects::ServicesController < Projects::ApplicationController
:description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
:colorize_messages, :channels,
:push_events, :issues_events, :merge_requests_events, :tag_push_events,
- :note_events, :send_from_committer_email, :disable_diffs
+ :note_events, :send_from_committer_email, :disable_diffs, :external_wiki_url
)
end
end
diff --git a/app/helpers/external_wiki_helper.rb b/app/helpers/external_wiki_helper.rb
new file mode 100644
index 00000000000..838b85afdfe
--- /dev/null
+++ b/app/helpers/external_wiki_helper.rb
@@ -0,0 +1,11 @@
+module ExternalWikiHelper
+ def get_project_wiki_path(project)
+ external_wiki_service = project.services.
+ select { |service| service.to_param == 'external_wiki' }.first
+ if external_wiki_service.present? && external_wiki_service.active?
+ external_wiki_service.properties['external_wiki_url']
+ else
+ namespace_project_wiki_path(project.namespace, project, :home)
+ end
+ end
+end
diff --git a/app/models/project.rb b/app/models/project.rb
index c45338bf4eb..5fbda1ae86c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -93,6 +93,7 @@ class Project < ActiveRecord::Base
has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
has_one :forked_from_project, through: :forked_project_link
+ has_one :external_wiki_service, dependent: :destroy
# Merge Requests for target project should be removed with it
has_many :merge_requests, dependent: :destroy, foreign_key: 'target_project_id'
# Merge requests from source project should be kept when source project was removed
diff --git a/app/models/project_services/external_wiki_service.rb b/app/models/project_services/external_wiki_service.rb
new file mode 100644
index 00000000000..e521186798c
--- /dev/null
+++ b/app/models/project_services/external_wiki_service.rb
@@ -0,0 +1,48 @@
+# == Schema Information
+#
+# Table name: services
+#
+# id :integer not null, primary key
+# type :string(255)
+# title :string(255)
+# project_id :integer not null
+# created_at :datetime
+# updated_at :datetime
+# active :boolean default(FALSE), not null
+# properties :text
+#
+
+class ExternalWikiService < Service
+ include HTTParty
+
+ prop_accessor :external_wiki_url
+ validates :external_wiki_url,
+ presence: true,
+ format: { with: URI::regexp },
+ if: :activated?
+
+ def title
+ 'External Wiki'
+ end
+
+ def description
+ 'Replaces the link to the internal wiki with a link to an external wiki.'
+ end
+
+ def to_param
+ 'external_wiki'
+ end
+
+ def fields
+ [
+ { type: 'text', name: 'external_wiki_url', placeholder: 'The URL of the external Wiki' },
+ ]
+ end
+
+ def execute(_data)
+ @response = HTTParty.get(properties['external_wiki_url'], verify: true) rescue nil
+ if @response !=200
+ nil
+ end
+ end
+end
diff --git a/app/views/layouts/nav/_project.html.haml b/app/views/layouts/nav/_project.html.haml
index d340ab1796a..91cae2b572c 100644
--- a/app/views/layouts/nav/_project.html.haml
+++ b/app/views/layouts/nav/_project.html.haml
@@ -75,7 +75,7 @@
- if project_nav_tab? :wiki
= nav_link(controller: :wikis) do
- = link_to namespace_project_wiki_path(@project.namespace, @project, :home), title: 'Wiki', class: 'shortcuts-wiki' do
+ = link_to get_project_wiki_path(@project), title: 'Wiki', class: 'shortcuts-wiki' do
%i.fa.fa-book
%span
Wiki