aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsobiemir <sobiemir@aculo.pl>2019-01-07 00:11:09 +0100
committersobiemir <sobiemir@aculo.pl>2019-01-07 00:11:09 +0100
commit4f813309958b0411bc3ff16c2d8dde80f1be8f18 (patch)
tree72c03cfbb2df060393f8d7bff2c5779ea16fa37d
parentdd0ceb1246b71afa50c91f7b585d7daf2ecae6d3 (diff)
downloadredmine-revision-redirect-4f813309958b0411bc3ff16c2d8dde80f1be8f18.tar.gz
redmine-revision-redirect-4f813309958b0411bc3ff16c2d8dde80f1be8f18.zip
Create and update records
-rw-r--r--app/controllers/RevisionRedirectsController.rb55
-rw-r--r--app/controllers/revision_redirects_controller.rb62
-rw-r--r--app/views/projects/settings/_repositories.html.erb2
-rw-r--r--app/views/revision_redirects/edit.html.erb35
-rw-r--r--config/locales/en.yml6
-rw-r--r--db/migrate/001_create_revision_redirects.rb1
-rw-r--r--init.rb11
-rw-r--r--lib/revision_repositories_patch.rb19
-rw-r--r--test/test_helper.rb2
9 files changed, 118 insertions, 75 deletions
diff --git a/app/controllers/RevisionRedirectsController.rb b/app/controllers/RevisionRedirectsController.rb
deleted file mode 100644
index 8f89fda..0000000
--- a/app/controllers/RevisionRedirectsController.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-class RevisionRedirectsController < ApplicationController
- before_action :find_repository_details, :only => [:edit, :update]
-
- def edit
- end
-
- def update
- end
-
- def find_repository_details
- @repository = Repository.find(params[:id])
- @redirect = RevisionRedirect.where(repository_id: params[:id]).first
-
- if not @redirect then
- @redirect = RevisionRedirect.new({
- revision_redirect: false,
- diff_redirect: false,
- repository_redirect: false,
- commiter_email: false,
- repository_id: params[:id],
- revision_link: "",
- diff_link: "",
- repository_link: ""
- })
- end
-
- @project = @repository.project
- rescue ActiveRecord::RecordNotFound
- render_404
- end
-
- # def update
- # project = Project.find(params[:id])
- # if params[:repository_id].present?
- # repository = project.repositories.find_by_identifier_param(params[:repository_id])
- # else
- # repository = project.repository
- # end
- # (render_404; return false) unless repository
- # path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s
- # rev = params[:rev].blank? ? repository.default_branch : params[:rev].to_s.strip
- # rev_to = params[:rev_to]
-
- # unless rev.to_s.match(REV_PARAM_RE) && rev_to.to_s.match(REV_PARAM_RE)
- # if repository.branches.blank?
- # raise InvalidRevisionParam
- # end
- # end
- # rescue ActiveRecord::RecordNotFound
- # render_404
- # rescue InvalidRevisionParam
- # show_error_not_found
- # end
-
-end
diff --git a/app/controllers/revision_redirects_controller.rb b/app/controllers/revision_redirects_controller.rb
new file mode 100644
index 0000000..796647a
--- /dev/null
+++ b/app/controllers/revision_redirects_controller.rb
@@ -0,0 +1,62 @@
+class RevisionRedirectsController < ApplicationController
+ before_action :authorize
+ before_action :find_repository_details, :only => [:edit, :update]
+
+ def edit
+ end
+
+ def update
+ if @redirect.new_record? then
+ @redirect = RevisionRedirect.new(update_params)
+ @redirect.repository_id = params[:id]
+
+ # try to save new object to database
+ if @redirect.save
+ redirect_to settings_project_path(@project, :tab => 'repositories')
+ else
+ render :action => 'edit'
+ end
+ else
+ # if it's not a new record, just update data
+ if @redirect.update(update_params) then
+ redirect_to settings_project_path(@project, :tab => 'repositories')
+ else
+ render :action => 'edit'
+ end
+ end
+ end
+
+ private
+
+ def find_repository_details
+ @repository = Repository.find(params[:id])
+ @redirect = RevisionRedirect.where(repository_id: params[:id]).first
+ @project = @repository.project
+
+ # if redirect cannot be found, create new with default values
+ if not @redirect then
+ @redirect = RevisionRedirect.new({
+ revision_redirect: false,
+ diff_redirect: false,
+ repository_redirect: false,
+ repository_id: params[:id],
+ revision_link: "https://git.example.com/#{@project.identifier}/commit/?id=\%REV\%",
+ diff_link: "https://git.example.com/#{@project.identifier}/diff/?id=\%DIFF\%",
+ repository_link: "https://git.example.com/#{@project.identifier}"
+ })
+ end
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
+ def update_params
+ params.require(:redirect).permit(
+ :revision_redirect,
+ :diff_redirect,
+ :repository_redirect,
+ :revision_link,
+ :diff_link,
+ :repository_link
+ )
+ end
+end
diff --git a/app/views/projects/settings/_repositories.html.erb b/app/views/projects/settings/_repositories.html.erb
index 60b59b7..1fe194b 100644
--- a/app/views/projects/settings/_repositories.html.erb
+++ b/app/views/projects/settings/_repositories.html.erb
@@ -30,7 +30,7 @@
:class => 'icon icon-user') %>
<%= link_to(l(:button_edit), edit_repository_path(repository),
:class => 'icon icon-edit') %>
- <%= link_to(l(:rrr_button_redirect), edit_revision_redirect_path(repository),
+ <%= link_to('Redirects', edit_revision_redirect_path(repository),
:class => 'icon icon-shared') %>
<%= delete_link repository_path(repository) %>
<% end %>
diff --git a/app/views/revision_redirects/edit.html.erb b/app/views/revision_redirects/edit.html.erb
index f50ce08..03ae466 100644
--- a/app/views/revision_redirects/edit.html.erb
+++ b/app/views/revision_redirects/edit.html.erb
@@ -1,13 +1,36 @@
-<h2><%= l(:rrr_label_redirect) %></h2>
+<h2>Repository redirects</h2>
<%= labelled_form_for :redirect, @redirect, :url => revision_redirect_path(@repository), :html => {:method => :put, :id => 'revision-redirect-form'} do |f| %>
- <%= error_messages_for 'redirect' %>
-
<div class="box tabular">
- <p><%= f.check_box :revision_redirect, :label => :rrr_field_revision_redirect %></p>
- <p><%= f.check_box :diff_redirect, :label => :rrr_field_diff_redirect %></p>
- <p><%= f.check_box :repository_redirect, :label => :rrr_field_repository_redirect %></p>
+ <p>
+ <%= f.check_box :revision_redirect, :label => 'Revision redirect' %>
+ </p>
+ <p>
+ <%= f.text_field :revision_link, :label => 'Revision link', :size => 60 %>
+ <em class="info">
+ You can use <code>%REV%</code> and <code>%ID%</code> in your link.<br />
+ <code>%REV%</code> is current revision requested to get in diffstat.<br />
+ <code>%ID%</code> is project identifier given when project was creating.
+ </em>
+ </p>
+ <p>
+ <%= f.check_box :diff_redirect, :label => 'Diffstat redirect' %>
+ </p>
+ <p>
+ <%= f.text_field :diff_link, :label => 'Diffstat link', :size => 60 %>
+ <em class="info">
+ You can use <code>%DIFF%</code> and <code>%ID%</code> in your link.<br />
+ <code>%DIFF%</code> is current revision requested to get in diffstat.<br />
+ <code>%ID%</code> is project identifier given when project was creating.
+ </em>
+ </p>
+ <p>
+ <%= f.check_box :repository_redirect, :label => 'Repository redirect' %>
+ </p>
+ <p>
+ <%= f.text_field :repository_link, :label => 'Repository link', :size => 60 %>
+ </p>
</div>
<p>
diff --git a/config/locales/en.yml b/config/locales/en.yml
deleted file mode 100644
index bdf8c14..0000000
--- a/config/locales/en.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-en:
- rrr_button_redirect: "Redirects"
- rrr_label_redirect: "Repository redirects"
- rrr_field_revision_redirect: "Revision redirect"
- rrr_field_diff_redirect: "Diff redirect"
- rrr_field_repository_redirect: "Repository redirect"
diff --git a/db/migrate/001_create_revision_redirects.rb b/db/migrate/001_create_revision_redirects.rb
index b2135a2..3fb5c71 100644
--- a/db/migrate/001_create_revision_redirects.rb
+++ b/db/migrate/001_create_revision_redirects.rb
@@ -8,7 +8,6 @@ class CreateRevisionRedirects < ActiveRecord::Migration[5.2]
t.string :diff_link
t.string :repository_link
t.integer :repository_id
- t.boolean :commiter_email
end
add_index :revision_redirects, :repository_id
end
diff --git a/init.rb b/init.rb
index c196b75..4a25550 100644
--- a/init.rb
+++ b/init.rb
@@ -1,9 +1,12 @@
Redmine::Plugin.register :redmine_revision_redirect do
name 'Redmine Revision Redirect plugin'
author 'sobiemir'
- description 'This plugin redirects all revisions to external service
-with git repository.'
+ description 'This plugin redirects all revisions to external service with git repository.'
version '0.0.1'
- #url 'http://example.com/path/to/plugin'
- #author_url 'http://example.com/about'
+ url 'https://git.aculo.pl/redmine-revision-redirect'
+ author_url 'https://aculo.pl'
+end
+
+Rails.configuration.to_prepare do
+ RepositoriesController.send(:include, RevisionRepositoriesPatch)
end
diff --git a/lib/revision_repositories_patch.rb b/lib/revision_repositories_patch.rb
new file mode 100644
index 0000000..7b0ee85
--- /dev/null
+++ b/lib/revision_repositories_patch.rb
@@ -0,0 +1,19 @@
+require_dependency 'repositories_controller'
+
+module RevisionRepositoriesPatch
+ def self.included(base)
+ base.send(:include, InstanceMethods)
+
+ base.class_eval do
+ unloadable
+ before_action :destroy_revision_redirects, :only => [:destroy]
+ end
+ end
+end
+
+module InstanceMethods
+ def destroy_revision_redirects
+ redirect = RevisionRedirect.where(repository_id: params[:id]).first
+ redirect.destroy if request.delete?
+ end
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
deleted file mode 100644
index 54685d3..0000000
--- a/test/test_helper.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-# Load the Redmine helper
-require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')