diff --git a/plugins/redmine_base_deface/LICENSE b/plugins/redmine_base_deface/LICENSE new file mode 100644 index 0000000..5010104 --- /dev/null +++ b/plugins/redmine_base_deface/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Jean-Baptiste Barth + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/plugins/redmine_base_deface/PluginGemfile b/plugins/redmine_base_deface/PluginGemfile new file mode 100644 index 0000000..811428d --- /dev/null +++ b/plugins/redmine_base_deface/PluginGemfile @@ -0,0 +1 @@ +gem 'deface', '1.5.3' diff --git a/plugins/redmine_base_deface/README.md b/plugins/redmine_base_deface/README.md new file mode 100644 index 0000000..cea4bcd --- /dev/null +++ b/plugins/redmine_base_deface/README.md @@ -0,0 +1,36 @@ +Redmine base_deface plugin +====================== + +Integrate with the deface gem to manage view modifications in plugins + +Installation +------------ + +This plugin is compatible with Redmine 2.1.0+. + +Please apply general instructions for plugins [here](http://www.redmine.org/wiki/redmine/Plugins). + +First download the source or clone the plugin and put it in the "plugins/" directory of your redmine instance. Note that this is crucial that the directory is named redmine_base_deface ! + +Then execute from redmine root directory: + + $ bundle install + $ rake redmine:plugins + +And finally restart your Redmine instance. + + +Contributing +------------ + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request + + +License +------- + +This project is released under the MIT license, see LICENSE file. diff --git a/plugins/redmine_base_deface/app/overrides/README.txt b/plugins/redmine_base_deface/app/overrides/README.txt new file mode 100644 index 0000000..f1ea528 --- /dev/null +++ b/plugins/redmine_base_deface/app/overrides/README.txt @@ -0,0 +1 @@ +This directory is only here to ensure the plugin works through unit tests. It is automatically added to Rails.application.paths["app/overrides"] diff --git a/plugins/redmine_base_deface/init.rb b/plugins/redmine_base_deface/init.rb new file mode 100644 index 0000000..018d869 --- /dev/null +++ b/plugins/redmine_base_deface/init.rb @@ -0,0 +1,20 @@ +Redmine::Plugin.register :redmine_base_deface do + name 'Redmine Base Deface plugin' + author 'Jean-Baptiste BARTH' + description 'This is a plugin for Redmine' + version '1.5.3' + url 'https://github.com/jbbarth/redmine_base_deface' + author_url 'jeanbaptiste.barth@gmail.com' + #doesn't work since redmine evaluates dependencies as it loads, and loads in lexical order + #TODO: see if it works in Redmine 2.6.x or 3.x when they're released + # requires_redmine_plugin :redmine_base_rspec, :version_or_higher => '0.0.3' if Rails.env.test? +end + +# Little hack for deface in redmine: +# - redmine plugins are not railties nor engines, so deface overrides are not detected automatically +# - deface doesn't support direct loading anymore ; it unloads everything at boot so that reload in dev works +# - hack consists in adding "app/overrides" path of all plugins in Redmine's main #paths +Rails.application.paths["app/overrides"] ||= [] +Dir.glob("#{Rails.root}/plugins/*/app/overrides").each do |dir| + Rails.application.paths["app/overrides"] << dir unless Rails.application.paths["app/overrides"].include?(dir) +end diff --git a/plugins/redmine_base_deface/spec/models/deface_paths_spec.rb b/plugins/redmine_base_deface/spec/models/deface_paths_spec.rb new file mode 100644 index 0000000..00b62a2 --- /dev/null +++ b/plugins/redmine_base_deface/spec/models/deface_paths_spec.rb @@ -0,0 +1,10 @@ +require "spec_helper" + +describe "DefacePaths" do + it "should app overrides paths" do + overrides_paths = Rails.application.paths["app/overrides"] + this_plugin_paths = Rails.root.join("plugins/redmine_base_deface/app/overrides") + assert overrides_paths.include?(this_plugin_paths.to_s), + "The init.rb of this very plugin should add every plugins' app/overrides to rails paths for app/overrides" + end +end diff --git a/plugins/redmine_git_server/Gemfile b/plugins/redmine_git_server/Gemfile new file mode 100644 index 0000000..ae94895 --- /dev/null +++ b/plugins/redmine_git_server/Gemfile @@ -0,0 +1 @@ +gem 'grack', '0.1.1' diff --git a/plugins/redmine_git_server/LICENSE b/plugins/redmine_git_server/LICENSE new file mode 100644 index 0000000..48a575d --- /dev/null +++ b/plugins/redmine_git_server/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Romain Lalaut + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/plugins/redmine_git_server/README.md b/plugins/redmine_git_server/README.md new file mode 100644 index 0000000..1422d28 --- /dev/null +++ b/plugins/redmine_git_server/README.md @@ -0,0 +1,52 @@ +Redmine plugin - Git Server +============ + +This Redmine plugin lets your users pull and push to/from your git repositories hosted on Redmine with HTTP - without any complex setup. + +Under the hood, it relies on [Grack](https://github.com/grackorg/grack), a Ruby/Rack Git Smart HTTP Server Handler. + + +Screenshot +------------ + + + + +Installation +------------ + +This plugin is tested with Redmine 4.1+ (but it could be compatible with other versions). + +Please apply general instructions for plugins [here](http://www.redmine.org/wiki/redmine/Plugins). + +Note that this plugin depends on this other plugin: +* **redmine_base_deface** [here](https://github.com/jbbarth/redmine_base_deface) + +First download the source or clone the plugin and put it in the "plugins/" directory of your redmine instance. Note that this is crucial that the directory is named 'redmine_git_server'! + +Then execute: + + $ bundle install + $ rake redmine:plugins + +And finally restart your Redmine instance. + + +Permissions +----------- + +* *Git Server > Enable git server* : allows a user to enable/disable the project module "Git Server" +* *(Redmine built-in) Repository > View changesets* : allows a user to fetch changesets (pull) from a repository +* *(Redmine built-in) Repository > Commit access* : allows a user to push to a repository + + +Alternatives +------------ + +* [redmine_git_hosting](http://redmine-git-hosting.io/) - based on Gitolite, this plugin offer a **lot** more features but it is also more complex to setup. + + +Knowns issues +------------- + +Puma 3.7 which is currently bundled with Redmine has an issue with chunked uploads. You can upgrade to Puma 4.3 or configure git locally to avoid chunked uploads (eg. `git config --global http.postBuffer 524288000`) diff --git a/plugins/redmine_git_server/app/controllers/git_server_controller.rb b/plugins/redmine_git_server/app/controllers/git_server_controller.rb new file mode 100644 index 0000000..d8c9b53 --- /dev/null +++ b/plugins/redmine_git_server/app/controllers/git_server_controller.rb @@ -0,0 +1,50 @@ +class GitServerController < ApplicationController + + skip_before_action :verify_authenticity_token + skip_before_action :check_if_login_required + + before_action do + begin + authenticate_or_request_with_http_basic do |username, password| + @user = User.try_to_login(username, password, false) + if @user.nil? or @user.new_record? or !@user.active? + logger.info "(Git Server) Authentication failed from #{request.remote_ip} at #{Time.now.utc}" + false + else + logger.info "(Git Server) Successful authentication for '#{@user.login}' from #{request.remote_ip} at #{Time.now.utc}" + true + end + end + next false unless @user + project = Project.find(params[:id]) + unless project.module_enabled?("git_server") + logger.warn "(Git Server) project '#{project.identifier}' doesn't have the git_server module enabled" + render_404 + next false + end + repository = project.repositories.find_by_identifier_param(params[:repository_id]) + unless repository + render_404 + next false + end + @grack_app = RedmineGitServer::GrackApp.new \ + request: request, + repository_path: repository.url, + allow_push: @user.allowed_to?(:commit_access, project), + allow_pull: @user.allowed_to?(:view_changesets, project) + rescue ActiveRecord::RecordNotFound + render_404 + end + end + + Grack::App::ROUTES.collect{|o| o[2] }.uniq.each do |action| + define_method action do + path = request.params["path"] + params = action == :info_refs ? [] : [path] + rack_response = @grack_app.send(action, *params) + self.response = ActionDispatch::Response.new(*rack_response) + response.sending! + end + end + +end diff --git a/plugins/redmine_git_server/app/overrides/repositories/show.rb b/plugins/redmine_git_server/app/overrides/repositories/show.rb new file mode 100644 index 0000000..9a7744d --- /dev/null +++ b/plugins/redmine_git_server/app/overrides/repositories/show.rb @@ -0,0 +1,5 @@ +Deface::Override.new virtual_path: 'repositories/show', + name: 'insert_clone_button', + insert_bottom: 'div.contextual', + partial: 'repositories/clone_button' + diff --git a/plugins/redmine_git_server/app/views/repositories/_clone_button.html.erb b/plugins/redmine_git_server/app/views/repositories/_clone_button.html.erb new file mode 100644 index 0000000..d65cdf9 --- /dev/null +++ b/plugins/redmine_git_server/app/views/repositories/_clone_button.html.erb @@ -0,0 +1,14 @@ +<% user = User.current %> +<% write_access = user.allowed_to?(:commit_access, @project) %> +<% read_access = user.allowed_to?(:view_changesets, @project) %> +<% if @project.module_enabled?("git_server") and read_access %> + | + <%= content_tag :div, class: 'drdn clone-wrapper' do %> + <%= button_tag l(:clone), type: 'button', class: 'drdn-trigger clone-button' %> + <%= content_tag :div, class: 'drdn-content clone-dropdown' do %> + <% protocol = Setting['protocol'] %> +
+ <%= l(:use_git_with_this_web_url) %> + <% if write_access %> + <%= l(:git_read_write_access) %> + <% else %> + <%= l(:git_read_only_access) %> + <% end %> +
+ <%= content_tag :code, class: 'clone-input-group' do %> + <% url = url_for( + controller: 'repositories', + action: 'show', + id: @project.identifier, + repository_id: @repository.identifier, + user: User.current.login, + password: '', + only_path: false, + protocol: protocol).sub(':@', '@') %> + <%= text_field_tag 'url', url, readonly: true %> + <%= button_tag image_tag('../plugin_assets/redmine_git_server/images/copy-to-clipboard.png') %> + <% end %> +