Añade el plugin Redmine Git Server 0.4

This commit is contained in:
Manuel Cillero 2021-05-14 16:45:54 +02:00
parent 525527a55b
commit 4b46a7472e
30 changed files with 485 additions and 0 deletions

View file

@ -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

View file

@ -0,0 +1,5 @@
Deface::Override.new virtual_path: 'repositories/show',
name: 'insert_clone_button',
insert_bottom: 'div.contextual',
partial: 'repositories/clone_button'

View file

@ -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'] %>
<h4><%= l(:clone_with_protocol, protocol: protocol.upcase) %></h4>
<%= render 'clone_form' %>
<% end %>
<% end %>
<% end %>

View file

@ -0,0 +1,28 @@
<% user = User.current %>
<% write_access = user.allowed_to?(:commit_access, @project) %>
<% read_access = user.allowed_to?(:view_changesets, @project) %>
<%= content_tag :div, class: 'clone-form' do %>
<% protocol = Setting['protocol'] %>
<p>
<%= l(:use_git_with_this_web_url) %>
<% if write_access %>
<%= l(:git_read_write_access) %>
<% else %>
<%= l(:git_read_only_access) %>
<% end %>
</p>
<%= 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 %>
<div class="flash notice"><%= l(:url_copied) %></div>
<% end %>

View file

@ -0,0 +1,10 @@
<% user = User.current %>
<% write_access = user.allowed_to?(:commit_access, @project) %>
<% read_access = user.allowed_to?(:view_changesets, @project) %>
<div class="flash warning">
<%= l(:empty_repository) %>
</div>
<div class="empty-clone-form">
<%= render 'clone_form' %>
</div>