Skip to content
Browse files

Added read-only option to disable all editing options including: Dele…

…te, Edit, Rename, and Create.
  • Loading branch information...
1 parent 9f1bbd0 commit e4fa25da38a91c3198f53f6ee321eec9bd70fe31 @GRMrGecko committed Feb 20, 2013
View
3 bin/gollum
@@ -84,6 +84,9 @@ opts = OptionParser.new do |opts|
opts.on("--collapse-tree", "Collapse file view tree. By default, expanded tree is shown.") do
wiki_options[:collapse_tree] = true
end
+ opts.on("--read-only", "Disables ability to edit wiki in web client.") do
+ wiki_options[:read_only] = true
+ end
opts.on("--h1-title", "Sets page title to value of first h1") do
wiki_options[:h1_title] = true
end
View
34 lib/gollum/frontend/app.rb
@@ -120,11 +120,12 @@ def wiki_new
end
get '/edit/*' do
- wikip = wiki_page(params[:splat].first)
- @name = wikip.name
- @path = wikip.path
+ wikip = wiki_page(params[:splat].first)
+ wiki = wikip.wiki
+ halt 404 if wiki.read_only
+ @name = wikip.name
+ @path = wikip.path
- wiki = wikip.wiki
if page = wikip.page
if wiki.live_preview && page.format.to_s.include?('markdown') && supported_useragent?(request.user_agent)
live_preview_url = '/livepreview/index.html?page=' + encodeURIComponent(@name)
@@ -148,6 +149,7 @@ def wiki_new
wikip = wiki_page(params[:splat].first)
halt 500 if wikip.nil?
wiki = wikip.wiki
+ halt 404 if wiki.read_only
page = wiki.paged(wikip.name, wikip.path, exact = true)
rename = params[:rename]
halt 500 if page.nil?
@@ -181,9 +183,10 @@ def wiki_new
end
post '/edit/*' do
+ wiki = wiki_new
+ halt 404 if wiki.read_only
path = '/' + clean_url(sanitize_empty_params(params[:path])).to_s
page_name = CGI.unescape(params[:page])
- wiki = wiki_new
page = wiki.paged(page_name, path, exact = true)
return if page.nil?
committer = Gollum::Committer.new(wiki, commit_message)
@@ -200,8 +203,9 @@ def wiki_new
get '/delete/*' do
wikip = wiki_page(params[:splat].first)
- name = wikip.name
wiki = wikip.wiki
+ halt 404 if wiki.read_only
+ name = wikip.name
page = wikip.page
wiki.delete_page(page, { :message => "Destroyed #{name} (#{page.format})" })
@@ -210,6 +214,8 @@ def wiki_new
get '/create/*' do
wikip = wiki_page(params[:splat].first.gsub('+', '-'))
+ wiki = wikip.wiki
+ halt 404 if wiki.read_only
@name = wikip.name.to_url
@path = wikip.path
@@ -231,10 +237,11 @@ def wiki_new
end
post '/create' do
+ wiki = wiki_new
+ halt 404 if wiki.read_only
name = params[:page].to_url
path = sanitize_empty_params(params[:path]) || ''
format = params[:format].intern
- wiki = wiki_new
begin
wiki.write_page(name, format, params[:content], commit_message, path)
@@ -249,9 +256,10 @@ def wiki_new
post '/revert/:page/*' do
wikip = wiki_page(params[:page])
+ wiki = wikip.wiki
+ halt 404 if wiki.read_only
@path = wikip.path
@name = wikip.name
- wiki = wikip.wiki
@page = wiki.paged(@name,@path)
shas = params[:splat].first.split("/")
sha1 = shas.shift
@@ -271,6 +279,7 @@ def wiki_new
post '/preview' do
wiki = wiki_new
+ halt 404 if wiki.read_only
@name = params[:page] || "Preview"
@page = wiki.preview_page(@name, params[:content], params[:format])
@content = @page.formatted_data
@@ -282,9 +291,12 @@ def wiki_new
end
get '/history/*' do
- @page = wiki_page(params[:splat].first).page
+ wikip = wiki_page(params[:splat].first)
+ wiki = wikip.wiki
+ @page = wikip.page
@page_num = [params[:page].to_i, 1].max
@versions = @page.versions :page => @page_num
+ @not_read_only = !wiki.read_only
mustache :history
end
@@ -318,6 +330,7 @@ def wiki_new
@page = wikip.page
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
@diff = diffs.first
+ @not_read_only = !wiki.read_only
mustache :compare
end
@@ -358,6 +371,7 @@ def wiki_new
@results = wiki.pages
@results += wiki.files if settings.wiki_options[:show_all]
@ref = wiki.ref
+ @not_read_only = !wiki.read_only
mustache :pages
end
@@ -391,6 +405,7 @@ def show_page_or_file(fullpath)
@content = page.formatted_data
# Extensions and layout data
+ @not_read_only = !wiki.read_only
@editable = true
@toc_content = wiki.universal_toc ? @page.toc_data : nil
@mathjax = wiki.mathjax
@@ -402,6 +417,7 @@ def show_page_or_file(fullpath)
content_type file.mime_type
file.raw_data
else
+ halt 404 if wiki.read_only
page_path = [path, name].compact.join('/')
redirect to("/create/#{clean_url(encodeURIComponent(page_path))}")
end
View
2 lib/gollum/frontend/templates/compare.mustache
@@ -8,8 +8,10 @@
</li>
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
class="action-view-page">View Page</a></li>
+ {{#not_read_only}}
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
class="action-edit-page">Edit Page</a></li>
+ {{/not_read_only}}
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
class="action-page-history">Page History</a></li>
</ul>
View
2 lib/gollum/frontend/templates/history.mustache
@@ -7,8 +7,10 @@
</li>
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
class="action-view-page">View Page</a></li>
+ {{#not_read_only}}
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
class="action-edit-page">Edit Page</a></li>
+ {{/not_read_only}}
</ul>
</div>
<div id="wiki-history">
View
4 lib/gollum/frontend/templates/page.mustache
@@ -18,6 +18,7 @@ Mousetrap.bind(['e'], function( e ) {
class="action-all-pages">All</a></li>
<li class="minibutton"><a href="{{base_url}}/fileview"
class="action-all-pages">Files</a></li>
+ {{#not_read_only}}
<li class="minibutton" class="jaws">
<a href="#" id="minibutton-new-page">New</a></li>
{{#editable}}
@@ -26,6 +27,7 @@ Mousetrap.bind(['e'], function( e ) {
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
class="action-edit-page">Edit</a></li>
{{/editable}}
+ {{/not_read_only}}
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
class="action-page-history">History</a></li>
</ul>
@@ -68,9 +70,11 @@ Mousetrap.bind(['e'], function( e ) {
</div>
<div id="footer">
<p id="last-edit">Last edited by <b>{{author}}</b>, {{date}}</p>
+ {{#not_read_only}}
<p>
<a id="delete-link" href="{{base_url}}/{{escaped_url_path}}" data-confirm="Are you sure you want to delete this page?"><span>Delete this Page</span></a>
</p>
+ {{/not_read_only}}
</div>
</div>
View
2 lib/gollum/frontend/templates/pages.mustache
@@ -7,9 +7,11 @@
</li>
<li class="minibutton"><a href="{{base_url}}/"
class="action-edit-page">Home</a></li>
+ {{#not_read_only}}
<li class="minibutton" class="jaws">
<a href="#" id="minibutton-new-page">New</a>
</li>
+ {{/not_read_only}}
</ul>
</div>
<div id="pages">
View
5 lib/gollum/wiki.rb
@@ -174,6 +174,7 @@ def history_sanitization
# :show_all - Show all files in file view, not just valid pages.
# Default: false
# :collapse_tree - Start with collapsed file view. Default: false
+ # :read_only - Disables ability to edit wiki in web client.
# :css - Include the custom.css file from the repo.
# :h1_title - Concatenate all h1's on a page to form the
# page title.
@@ -215,6 +216,7 @@ def initialize(path, options = {})
@mathjax = options.fetch :mathjax, false
@show_all = options.fetch :show_all, false
@collapse_tree = options.fetch :collapse_tree, false
+ @read_only = options.fetch :read_only, false
@css = options.fetch :css, false
@h1_title = options.fetch :h1_title, false
@index_page = options.fetch :index_page, 'Home'
@@ -700,6 +702,9 @@ def history_sanitizer
# Start with collapsed file view. Default: false
attr_reader :collapse_tree
+ # Enables read-only mode.
+ attr_reader :read_only
+
# Normalize the data.
#
# data - The String data to be normalized.

0 comments on commit e4fa25d

Please sign in to comment.
Something went wrong with that request. Please try again.