From 74d401d087803efa87b724a0d245b94a33f0bea6 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 8 Feb 2012 21:51:30 +0400 Subject: [PATCH 01/11] [issue #133] Writed draft of web editing. --- app/controllers/git/blobs_controller.rb | 8 ++++ app/helpers/git_helper.rb | 8 ++++ app/models/git/repository.rb | 54 ++++++++++++++++++++++++- app/views/git/blobs/_editor.html.haml | 39 ++++++++++++++++++ app/views/git/blobs/edit.html.haml | 20 +++++++++ app/views/git/blobs/show.html.haml | 2 +- config/routes.rb | 10 ++++- 7 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 app/views/git/blobs/_editor.html.haml create mode 100644 app/views/git/blobs/edit.html.haml diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index 0bfe6b4b4..09bd74103 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -16,6 +16,14 @@ class Git::BlobsController < Git::BaseController end end + def edit + end + + def update + @git_repository.update_file(params[:path], params[:content], :message => params[:message], :actor => current_user, :ref => @treeish) + redirect_to :action => :show + end + def blame @blame = Grit::Blob.blame(@git_repository.repo, @commit.try(:id), @path) end diff --git a/app/helpers/git_helper.rb b/app/helpers/git_helper.rb index f302b5aed..fef549d7e 100644 --- a/app/helpers/git_helper.rb +++ b/app/helpers/git_helper.rb @@ -29,6 +29,14 @@ module GitHelper res.encode_to_default.html_safe end + def blob_file_path + if @commit_hash.present? + blob_commit_path(@project, @commit_hash, @path) + else + blob_path(@project, @treeish, @path) + end + end + def render_line_numbers(n) res = "" 1.upto(n) {|i| res += "#{i}\n" } diff --git a/app/models/git/repository.rb b/app/models/git/repository.rb index 4ed82b210..6b7c88661 100644 --- a/app/models/git/repository.rb +++ b/app/models/git/repository.rb @@ -2,16 +2,17 @@ class Git::Repository delegate :commits, :commit, :tree, :tags, :heads, :commit_count, :log, :branches, :to => :repo - attr_accessor :path, :name + attr_accessor :path, :name, :repo, :last_actor def initialize(path) @path = path + @update_callbacks = [] end def master commits('master', 1).first end - + def to_s name end @@ -20,6 +21,31 @@ class Git::Repository @repo ||= Grit::Repo.new(path) end + def after_update_file(&block) + @update_callbacks << block + end + + def update_file(path, data, options = {}) + ref = options[:ref].to_s || 'master' + actor = get_actor(options[:actor]) + message = options[:message] || "Updated file #{File.split(path).last}" + + # can not write to unexisted branch + return false if branches.select{|b| b.name == ref}.size != 1 + + parent = commits(ref).first + + index = repo.index + index.read_tree(parent.tree.id) + + index.add(path, data) + sha = index.commit(message, :parents => [parent], :actor => actor, :last_tree => parent.tree.id, :head => ref) + @update_callbacks.each do |cb| + cb.call(self, sha1) + end + sha + end + def self.create(path) repo = Grit::Repo.init_bare(path) repo.enable_daemon_serve @@ -38,4 +64,28 @@ class Git::Repository [commits(treeish, options[:per_page], skip), options[:page], last_page] end + # Pretty object inspection + def inspect + %Q{#} + end + + protected + + def get_actor(actor = nil) + @last_actor = case actor.class.to_s + when 'Grit::Actor' then options[:actor] + when 'Hash' then Grit::Actor.new(actor[:name], actor[:email]) + when 'String' then Grit::Actor.from_stirng(actor) + else begin + if actor.respond_to?(:name) and actor.respond_to?(:email) + Grit::Actor.new(actor.name, actor.email) + else + config = Grit::Config.new(repo) + Grit::Actor.new(config['user.name'], config['user.email']) + end + end + end + @last_actor + end + end diff --git a/app/views/git/blobs/_editor.html.haml b/app/views/git/blobs/_editor.html.haml new file mode 100644 index 000000000..7ef82f3ff --- /dev/null +++ b/app/views/git/blobs/_editor.html.haml @@ -0,0 +1,39 @@ +#gollum-editor.edit{:'data-escaped-name' => @path} + = form_tag blob_file_path, :name => 'blob-editor', :method => :put do + %fieldset#gollum-editor-fields + + = text_area_tag :content, @blob.data.encode_to_default, :id => "gollum-editor-body" + + #gollum-editor-edit-summary.singleline + = label_tag :message, t("layout.wiki.edit_commit_message"), :class => "jaws" + = text_field_tag :message, t("layout.wiki.commit_message_placeholder"), :id => "editor-commit-message-field" + + %span.jaws + %br + + = submit_tag t("layout.wiki.save_button"), :id => "gollum-editor-submit", :title => t("layout.wiki.save_changes") + = link_to t("layout.cancel"), blob_file_path, :class => 'minibutton', :id => 'gollum-editor-preview' + +:javascript + (function($) { + $.Editor = function() { + $.Editor.Placeholder.add($('#gollum-editor-edit-summary input')); + $('#gollum-editor form[name="blob-editor"]').submit(function( e ) { + e.preventDefault(); + $.Editor.Placeholder.clearAll(); + //debug('submitting'); + $(this).unbind('submit'); + $(this).submit(); + }); + }; + + $.Editor.Placeholder = $.GollumPlaceholder; + + $.Editor(); + })(jQuery); + +- content_for :javascripts do + = javascript_include_tag 'gollum/gollum.placeholder.js' + +- content_for :stylesheets do + = stylesheet_link_tag 'gollum/editor.css' diff --git a/app/views/git/blobs/edit.html.haml b/app/views/git/blobs/edit.html.haml new file mode 100644 index 000000000..0452cc04d --- /dev/null +++ b/app/views/git/blobs/edit.html.haml @@ -0,0 +1,20 @@ +.block + = render :partial => "git/shared/navigation" + + = render :partial => "git/shared/info" + +- if @commit + .block + .content + .inner + = render :partial => "git/commits/commits", :object => [@commit] + +.block + .content + .inner + %h3 #{render_path} (#{@blob.mime_type}) + + = render :partial => 'editor' + +- content_for :sidebar, render(:partial => 'git/shared/sidebar') + diff --git a/app/views/git/blobs/show.html.haml b/app/views/git/blobs/show.html.haml index 43127ac7e..95ba637a9 100644 --- a/app/views/git/blobs/show.html.haml +++ b/app/views/git/blobs/show.html.haml @@ -21,7 +21,7 @@ - if @commit_hash #{link_to "Raw", raw_commit_path(@project, @commit_hash, @path)} #{link_to "Blame", blame_commit_path(@project, @commit_hash, @path)} #{link_to "History", commits_path(@project, @treeish, @path)} - else - #{link_to "Raw", raw_path(@project, @treeish, @path)} #{link_to "Blame", blame_path(@project, @treeish, @path)} #{link_to "History", commits_path(@project, @treeish, @path)} + #{link_to(t("edit"), edit_blob_path(@project, @treeish, @path)) if choose_render_way(@blob) == :text} #{link_to "Raw", raw_path(@project, @treeish, @path)} #{link_to "Blame", blame_path(@project, @treeish, @path)} #{link_to "History", commits_path(@project, @treeish, @path)} .clear - case choose_render_way(@blob) - when :image diff --git a/config/routes.rb b/config/routes.rb index c26020d1e..18417db60 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -179,12 +179,18 @@ Rosa::Application.routes.draw do match '/projects/:project_id/git/commit/:commit_id/comments/:id(.:format)', :controller => "comments", :action => :update, :as => :project_commit_comment, :via => :put match '/projects/:project_id/git/commit/:commit_id/comments/:id(.:format)', :controller => "comments", :action => :destroy, :via => :delete match '/projects/:project_id/git/commit/:commit_id/comments(.:format)', :controller => "comments", :action => :create, :as => :project_commit_comments, :via => :post + # Commits subscribe match '/projects/:project_id/git/commit/:commit_id/subscribe', :controller => "commit_subscribes", :action => :create, :defaults => { :format => :html }, :as => :subscribe_commit, :via => :post match '/projects/:project_id/git/commit/:commit_id/unsubscribe', :controller => "commit_subscribes", :action => :destroy, :defaults => { :format => :html }, :as => :unsubscribe_commit, :via => :delete + + # Editing files + match '/projects/:project_id/git/blob/:treeish/*path/edit', :controller => "git/blobs", :action => :edit, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :edit_blob, :via => :get + match '/projects/:project_id/git/blob/:treeish/*path', :controller => "git/blobs", :action => :update, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :via => :put + # Blobs - match '/projects/:project_id/git/blob/:treeish/*path', :controller => "git/blobs", :action => :show, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :blob - match '/projects/:project_id/git/commit/blob/:commit_hash/*path', :controller => "git/blobs", :action => :show, :project_name => /[0-9a-zA-Z_.\-]*/, :as => :blob_commit + match '/projects/:project_id/git/blob/:treeish/*path', :controller => "git/blobs", :action => :show, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :blob, :via => :get + match '/projects/:project_id/git/commit/blob/:commit_hash/*path', :controller => "git/blobs", :action => :show, :project_id => /[0-9a-zA-Z_.\-]*/, :as => :blob_commit, :via => :get # Blame match '/projects/:project_id/git/blame/:treeish/*path', :controller => "git/blobs", :action => :blame, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :blame From 009b1374a2a486ccb22e13345fc4bb83ef49cee7 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 8 Feb 2012 21:52:13 +0400 Subject: [PATCH 02/11] [issue #133] Fixed commits display --- public/stylesheets/git/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/stylesheets/git/style.css b/public/stylesheets/git/style.css index a20748d90..8428c17b1 100644 --- a/public/stylesheets/git/style.css +++ b/public/stylesheets/git/style.css @@ -37,7 +37,7 @@ li.commit .message { li.commit .trees { padding-left: 5px; - width: 180px; + width: 200px; } li.commit .message a { From d44a274c77f066bd6046492381a916e437d97b36 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 9 Feb 2012 00:56:18 +0400 Subject: [PATCH 03/11] [issue #133] Fixed bug and added comments --- app/models/git/repository.rb | 38 ++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/app/models/git/repository.rb b/app/models/git/repository.rb index 6b7c88661..2dbec885a 100644 --- a/app/models/git/repository.rb +++ b/app/models/git/repository.rb @@ -21,10 +21,35 @@ class Git::Repository @repo ||= Grit::Repo.new(path) end + # Adds a callback to be fired after update file. + # + # block - A block that expects this Git::Repository instance and the created + # commit's SHA1 as the arguments. + # + # For example: + # + # after_update_file do |repo, sha| + # # callback body + # end + # + # Returns nothing. def after_update_file(&block) @update_callbacks << block end + # Writes file to repo and runs 'after_update_file' callbacks + # + # path - path to file in repository + # data - new content of file + # options - an optional Hash of options + # :ref - ref name to write this commit to + # (Default: 'master') + # :actor - author of this commit. (See Git::Repository#get_actor) + # (Default: nil) + # :message - commit message + # (Default: "Updated file ") + # + # Returns commits sha if committing was successful and false otherwise def update_file(path, data, options = {}) ref = options[:ref].to_s || 'master' actor = get_actor(options[:actor]) @@ -39,9 +64,11 @@ class Git::Repository index.read_tree(parent.tree.id) index.add(path, data) - sha = index.commit(message, :parents => [parent], :actor => actor, :last_tree => parent.tree.id, :head => ref) + sha = index.commit(message, :parents => [parent], :actor => actor, + :last_tree => parent.tree.id, :head => ref) + # call all defined callbacks @update_callbacks.each do |cb| - cb.call(self, sha1) + cb.call(self, sha) end sha end @@ -71,6 +98,13 @@ class Git::Repository protected + # Creates new Grit::Actor instance + # + # Might be: + # * A Hash containing :name and :email + # * An instance of Grit::Actor + # * A String like "John Doe + # * Any object that responds to `name` and `email` methods def get_actor(actor = nil) @last_actor = case actor.class.to_s when 'Grit::Actor' then options[:actor] From e23a02d3576454a3b53f986bd9baa08cc9739d1f Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 9 Feb 2012 04:03:40 +0400 Subject: [PATCH 04/11] [issue #133] Some fixes in Git::Repository#update_file --- app/models/git/repository.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/models/git/repository.rb b/app/models/git/repository.rb index 2dbec885a..c1d0fec4d 100644 --- a/app/models/git/repository.rb +++ b/app/models/git/repository.rb @@ -42,7 +42,7 @@ class Git::Repository # path - path to file in repository # data - new content of file # options - an optional Hash of options - # :ref - ref name to write this commit to + # :head - branch name to write this commit to # (Default: 'master') # :actor - author of this commit. (See Git::Repository#get_actor) # (Default: nil) @@ -51,21 +51,28 @@ class Git::Repository # # Returns commits sha if committing was successful and false otherwise def update_file(path, data, options = {}) - ref = options[:ref].to_s || 'master' + path.force_encoding(Encoding::ASCII_8BIT) # some magic + + head = options[:head].to_s || 'master' actor = get_actor(options[:actor]) - message = options[:message] || "Updated file #{File.split(path).last}" + filename = File.split(path).last + message = options[:message] + message = "Updated file #{filename}" if message.nil? or message.empty? # can not write to unexisted branch - return false if branches.select{|b| b.name == ref}.size != 1 + return false if branches.select{|b| b.name == head}.size != 1 - parent = commits(ref).first + parent = commits(head).first index = repo.index index.read_tree(parent.tree.id) + # can not create new file + return false if (index.current_tree / path).nil? + index.add(path, data) sha = index.commit(message, :parents => [parent], :actor => actor, - :last_tree => parent.tree.id, :head => ref) + :last_tree => parent.tree.id, :head => head) # call all defined callbacks @update_callbacks.each do |cb| cb.call(self, sha) From ffe2608c320ee13a14a0bbefc8f617264731dcb2 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 9 Feb 2012 04:26:23 +0400 Subject: [PATCH 05/11] [issue #133] Some makeup and a lot of encodings magic --- app/controllers/git/blobs_controller.rb | 15 +++++++++++++-- app/controllers/git/trees_controller.rb | 1 + app/views/git/blobs/_editor.html.haml | 2 +- app/views/git/blobs/show.html.haml | 9 +++++++-- app/views/git/repositories/show.html.haml | 7 +++++-- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index 09bd74103..24335823a 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -20,7 +20,17 @@ class Git::BlobsController < Git::BaseController end def update - @git_repository.update_file(params[:path], params[:content], :message => params[:message], :actor => current_user, :ref => @treeish) + # Here might be callbacks for notification purposes: + # @git_repository.after_update_file do |repo, sha| + # end + + res = @git_repository.update_file(params[:path], params[:content], + :message => params[:message], :actor => current_user, :head => @treeish) + if res + flash[:notice] = t("flash.blob.successfully_updated", :name => params[:path].encode_to_default) + else + flash[:notice] = t("flash.blob.updating_error", :name => params[:path].encode_to_default) + end redirect_to :action => :show end @@ -36,7 +46,8 @@ class Git::BlobsController < Git::BaseController protected def set_path_blob @path = params[:path] - @blob = @tree / @path.encode_to_default + @path.force_encoding(Encoding::ASCII_8BIT) + @blob = @tree / @path end def set_commit_hash diff --git a/app/controllers/git/trees_controller.rb b/app/controllers/git/trees_controller.rb index 081fa7e8b..94b6b91e0 100644 --- a/app/controllers/git/trees_controller.rb +++ b/app/controllers/git/trees_controller.rb @@ -3,6 +3,7 @@ class Git::TreesController < Git::BaseController def show @path = params[:path] + @path.force_encoding(Encoding::ASCII_8BIT) if @path @tree = @git_repository.tree(@treeish) diff --git a/app/views/git/blobs/_editor.html.haml b/app/views/git/blobs/_editor.html.haml index 7ef82f3ff..48649074f 100644 --- a/app/views/git/blobs/_editor.html.haml +++ b/app/views/git/blobs/_editor.html.haml @@ -1,4 +1,4 @@ -#gollum-editor.edit{:'data-escaped-name' => @path} +#gollum-editor.edit{:'data-escaped-name' => @path.encode_to_default} = form_tag blob_file_path, :name => 'blob-editor', :method => :put do %fieldset#gollum-editor-fields diff --git a/app/views/git/blobs/show.html.haml b/app/views/git/blobs/show.html.haml index 95ba637a9..20eb84603 100644 --- a/app/views/git/blobs/show.html.haml +++ b/app/views/git/blobs/show.html.haml @@ -19,9 +19,14 @@ .size #{(@blob.size / 1024.0).round(3)} Kb .buttons - if @commit_hash - #{link_to "Raw", raw_commit_path(@project, @commit_hash, @path)} #{link_to "Blame", blame_commit_path(@project, @commit_hash, @path)} #{link_to "History", commits_path(@project, @treeish, @path)} + #{link_to "Raw", raw_commit_path(@project, @commit_hash, @path)} + #{link_to "Blame", blame_commit_path(@project, @commit_hash, @path)} + #{link_to "History", commits_path(@project, @treeish, @path)} - else - #{link_to(t("edit"), edit_blob_path(@project, @treeish, @path)) if choose_render_way(@blob) == :text} #{link_to "Raw", raw_path(@project, @treeish, @path)} #{link_to "Blame", blame_path(@project, @treeish, @path)} #{link_to "History", commits_path(@project, @treeish, @path)} + #{link_to "Edit", edit_blob_path(@project, @treeish, @path)) if choose_render_way(@blob) == :text} + #{link_to "Raw", raw_path(@project, @treeish, @path)} + #{link_to "Blame", blame_path(@project, @treeish, @path)} + #{link_to "History", commits_path(@project, @treeish, @path)} .clear - case choose_render_way(@blob) - when :image diff --git a/app/views/git/repositories/show.html.haml b/app/views/git/repositories/show.html.haml index 41c205ebd..c3131ed82 100644 --- a/app/views/git/repositories/show.html.haml +++ b/app/views/git/repositories/show.html.haml @@ -36,10 +36,13 @@ - else = image_tag("git/icons/folder_16.png") %td.tree_element + - entry_path = File.join([@path.present? ? @path.encode_to_default : nil, entry.name.encode_to_default].compact) - if entry.is_a?(Grit::Blob) - = link_to entry.name.encode_to_default, blob_path(@project, @treeish, File.join([@path, entry.name.encode_to_default].compact)) + = link_to entry.name.encode_to_default, + blob_path(@project, @treeish.encode_to_default, entry_path) - else - = link_to "#{entry.name.encode_to_default}/", tree_path(@project, @treeish, File.join([@path, entry.name.encode_to_default].compact)) + = link_to "#{entry.name.encode_to_default}/", + tree_path(@project, @treeish.encode_to_default, entry_path) %td==   %td.last==   From 2160f3aa6627d793e5abc3ce112e098d653180c5 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 9 Feb 2012 04:28:39 +0400 Subject: [PATCH 06/11] [issue #133] Added translations --- config/locales/en.yml | 4 ++++ config/locales/ru.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index d864d5797..fc11a7bdd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -692,6 +692,10 @@ en: revert_success: Changes successfully reverted patch_does_not_apply: Patch does not apply + blob: + successfully_updated: File '%{name}' successfully updated + updating_error: Error updating file '%{name}' + attributes: password: Password password_confirmation: Confirmation diff --git a/config/locales/ru.yml b/config/locales/ru.yml index c165f173a..3b8345ab2 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -549,6 +549,10 @@ ru: revert_success: Изменения успешно откачены patch_does_not_apply: Не удалось откатить изменения + blob: + successfully_updated: Файл '%{name}' успешно обновлен + updating_error: Ошибка обновления файла '%{name}' + attributes: password: Пароль password_confirmation: Подтверждение From a4baf8b6702fa6cb864e47b31c71a89a30ad1346 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Thu, 9 Feb 2012 04:35:07 +0400 Subject: [PATCH 07/11] [issue #133] Editor JS moved to separate file --- app/views/git/blobs/_editor.html.haml | 21 ++++----------------- db/schema.rb | 15 +++++++-------- public/javascripts/blob.editor.js | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 public/javascripts/blob.editor.js diff --git a/app/views/git/blobs/_editor.html.haml b/app/views/git/blobs/_editor.html.haml index 48649074f..9851626e4 100644 --- a/app/views/git/blobs/_editor.html.haml +++ b/app/views/git/blobs/_editor.html.haml @@ -15,25 +15,12 @@ = link_to t("layout.cancel"), blob_file_path, :class => 'minibutton', :id => 'gollum-editor-preview' :javascript - (function($) { - $.Editor = function() { - $.Editor.Placeholder.add($('#gollum-editor-edit-summary input')); - $('#gollum-editor form[name="blob-editor"]').submit(function( e ) { - e.preventDefault(); - $.Editor.Placeholder.clearAll(); - //debug('submitting'); - $(this).unbind('submit'); - $(this).submit(); - }); - }; - - $.Editor.Placeholder = $.GollumPlaceholder; - - $.Editor(); - })(jQuery); + $(function() { + $.BlobEditor(); + }); - content_for :javascripts do - = javascript_include_tag 'gollum/gollum.placeholder.js' + = javascript_include_tag 'gollum/gollum.placeholder.js', 'blob.editor.js' - content_for :stylesheets do = stylesheet_link_tag 'gollum/editor.css' diff --git a/db/schema.rb b/db/schema.rb index ad2ca6d65..e1b5eda9a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120131124517) do +ActiveRecord::Schema.define(:version => 20120131141651) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -253,11 +253,11 @@ ActiveRecord::Schema.define(:version => 20120131124517) do t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true + t.boolean "has_wiki", :default => false t.string "srpm_file_name" t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" - t.boolean "has_wiki", :default => false end add_index "projects", ["category_id"], :name => "index_projects_on_category_id" @@ -320,19 +320,18 @@ ActiveRecord::Schema.define(:version => 20120131124517) do create_table "users", :force => true do |t| t.string "name" - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false - t.string "password_salt", :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" - t.string "remember_token" + t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" t.text "ssh_key" t.string "uname" t.string "role" - t.string "language", :default => "en" - t.integer "own_projects_count", :default => 0, :null => false + t.string "language", :default => "en" + t.integer "own_projects_count", :default => 0, :null => false end add_index "users", ["email"], :name => "index_users_on_email", :unique => true diff --git a/public/javascripts/blob.editor.js b/public/javascripts/blob.editor.js new file mode 100644 index 000000000..edcf8bf1c --- /dev/null +++ b/public/javascripts/blob.editor.js @@ -0,0 +1,14 @@ +(function($) { + $.BlobEditor = function() { + $.BlobEditor.Placeholder.add($('#gollum-editor-edit-summary input')); + $('#gollum-editor form[name="blob-editor"]').submit(function( e ) { + e.preventDefault(); + $.BlobEditor.Placeholder.clearAll(); + //debug('submitting'); + $(this).unbind('submit'); + $(this).submit(); + }); + }; + + $.BlobEditor.Placeholder = $.GollumPlaceholder; +})(jQuery); From 391716fee52ceaed6fe50a40ddce15093084817d Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 13 Feb 2012 14:43:57 +0400 Subject: [PATCH 08/11] [refs #133] Fix syntax error into blob template --- app/views/git/blobs/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/git/blobs/show.html.haml b/app/views/git/blobs/show.html.haml index 20eb84603..c94f11f38 100644 --- a/app/views/git/blobs/show.html.haml +++ b/app/views/git/blobs/show.html.haml @@ -23,7 +23,7 @@ #{link_to "Blame", blame_commit_path(@project, @commit_hash, @path)} #{link_to "History", commits_path(@project, @treeish, @path)} - else - #{link_to "Edit", edit_blob_path(@project, @treeish, @path)) if choose_render_way(@blob) == :text} + #{link_to "Edit", edit_blob_path(@project, @treeish, @path) if choose_render_way(@blob) == :text} #{link_to "Raw", raw_path(@project, @treeish, @path)} #{link_to "Blame", blame_path(@project, @treeish, @path)} #{link_to "History", commits_path(@project, @treeish, @path)} From 8c0cd29f0eec37293514e87aaf8e2ed4795b9e48 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 13 Feb 2012 19:21:00 +0400 Subject: [PATCH 09/11] [issue #133] Fixed bug with no acl on editing blobs --- app/controllers/git/blobs_controller.rb | 2 ++ app/views/git/blobs/show.html.haml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index 24335823a..fa4e75386 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -17,9 +17,11 @@ class Git::BlobsController < Git::BaseController end def edit + authorize! :write, @project end def update + authorize! :write, @project # Here might be callbacks for notification purposes: # @git_repository.after_update_file do |repo, sha| # end diff --git a/app/views/git/blobs/show.html.haml b/app/views/git/blobs/show.html.haml index c94f11f38..14f6e6164 100644 --- a/app/views/git/blobs/show.html.haml +++ b/app/views/git/blobs/show.html.haml @@ -23,7 +23,7 @@ #{link_to "Blame", blame_commit_path(@project, @commit_hash, @path)} #{link_to "History", commits_path(@project, @treeish, @path)} - else - #{link_to "Edit", edit_blob_path(@project, @treeish, @path) if choose_render_way(@blob) == :text} + #{link_to "Edit", edit_blob_path(@project, @treeish, @path) if choose_render_way(@blob) == :text and can? :write, @project} #{link_to "Raw", raw_path(@project, @treeish, @path)} #{link_to "Blame", blame_path(@project, @treeish, @path)} #{link_to "History", commits_path(@project, @treeish, @path)} From c26962c216625233cb315beeb996ea5a180758fa Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 13 Feb 2012 22:45:45 +0400 Subject: [PATCH 10/11] [issue #133] Added redirects if cannot find Blob object --- app/controllers/git/blobs_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index fa4e75386..c03a1be8f 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -5,6 +5,7 @@ class Git::BlobsController < Git::BaseController before_filter :set_commit_hash def show + redirect_to project_repo_path(@project) unless @blob.present? if params[:raw] image_url = Rails.root.to_s + "/" + @path @@ -17,10 +18,12 @@ class Git::BlobsController < Git::BaseController end def edit + redirect_to project_repo_path(@project) unless @blob.present? authorize! :write, @project end def update + redirect_to project_repo_path(@project) unless @blob.present? authorize! :write, @project # Here might be callbacks for notification purposes: # @git_repository.after_update_file do |repo, sha| @@ -41,6 +44,7 @@ class Git::BlobsController < Git::BaseController end def raw + redirect_to project_repo_path(@project) unless @blob.present? headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"] render :text => @blob.data, :content_type => @blob.mime_type end From 4dcc39975d64a3b5c55f42edf2d07b0c8b809bcc Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Mon, 13 Feb 2012 23:04:41 +0400 Subject: [PATCH 11/11] [issue #133] Fixed redirection bugs --- Gemfile.lock | 14 +++++++------- app/controllers/git/blobs_controller.rb | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1c497b240..5a673d43e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -54,14 +54,14 @@ GEM activerecord (>= 2.2.2) arel (2.0.10) bcrypt-ruby (3.0.1) - bluepill (0.0.52) + bluepill (0.0.55) activesupport (>= 3.0.0) - daemons (~> 1.1.0) + daemons (~> 1.1.4) i18n (>= 0.5.0) state_machine (~> 1.1.0) builder (2.1.2) cancan (1.6.7) - cape (1.2.0) + cape (1.4.0) capistrano (2.9.0) highline net-scp (>= 1.0.0) @@ -74,7 +74,7 @@ GEM chronic (0.6.7) cocaine (0.2.1) creole (0.4.2) - daemons (1.1.6) + daemons (1.1.8) delayed_job (2.1.4) activesupport (~> 3.0) daemons @@ -92,7 +92,7 @@ GEM factory_girl_rails (1.4.0) factory_girl (~> 2.3.0) railties (>= 3.0.0) - github-markup (0.7.0) + github-markup (0.7.1) gollum (1.3.1) albino (~> 1.3.2) github-markup (>= 0.4.0, < 1.0.0) @@ -152,7 +152,7 @@ GEM omniauth (~> 1.0) rack-openid (~> 1.3.1) orm_adapter (0.0.6) - paperclip (2.5.2) + paperclip (2.6.0) activerecord (>= 2.3.0) activesupport (>= 2.3.2) cocaine (>= 0.0.2) @@ -179,7 +179,7 @@ GEM rails-xmlrpc (0.3.6) rails3-generators (0.17.4) railties (>= 3.0.0) - rails3-jquery-autocomplete (1.0.5) + rails3-jquery-autocomplete (1.0.6) rails (~> 3.0) railties (3.0.11) actionpack (= 3.0.11) diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index c03a1be8f..0b93db28f 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -5,7 +5,7 @@ class Git::BlobsController < Git::BaseController before_filter :set_commit_hash def show - redirect_to project_repo_path(@project) unless @blob.present? + redirect_to project_repo_path(@project) and return unless @blob.present? if params[:raw] image_url = Rails.root.to_s + "/" + @path @@ -18,12 +18,12 @@ class Git::BlobsController < Git::BaseController end def edit - redirect_to project_repo_path(@project) unless @blob.present? + redirect_to project_repo_path(@project) and return unless @blob.present? authorize! :write, @project end def update - redirect_to project_repo_path(@project) unless @blob.present? + redirect_to project_repo_path(@project) and return unless @blob.present? authorize! :write, @project # Here might be callbacks for notification purposes: # @git_repository.after_update_file do |repo, sha| @@ -44,7 +44,7 @@ class Git::BlobsController < Git::BaseController end def raw - redirect_to project_repo_path(@project) unless @blob.present? + redirect_to project_repo_path(@project) and return unless @blob.present? headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"] render :text => @blob.data, :content_type => @blob.mime_type end