Commit 7ab808a5 authored by jplang's avatar jplang
Browse files

Resourcified repositories for CRUD operations to prepare for multiple SCM per project (#779).

git-svn-id: https://svn.redmine.org/redmine/trunk@8648 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 139f4e65
......@@ -176,7 +176,6 @@ class ProjectsController < ApplicationController
@issue_category ||= IssueCategory.new
@member ||= @project.members.new
@trackers = Tracker.all
@repository ||= @project.repository
@wiki ||= @project.wiki
end
......
......@@ -24,44 +24,45 @@ class InvalidRevisionParam < Exception; end
class RepositoriesController < ApplicationController
menu_item :repository
menu_item :settings, :only => :edit
menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers]
default_search_scope :changesets
before_filter :find_repository, :except => :edit
before_filter :find_project, :only => :edit
before_filter :find_project_by_project_id, :only => [:new, :create]
before_filter :check_repository_uniqueness, :only => [:new, :create]
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
before_filter :find_project_repository, :except => [:new, :create, :edit, :update, :destroy, :committers]
before_filter :authorize
accept_rss_auth :revisions
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
def edit
@repository = @project.repository
if !@repository && !params[:repository_scm].blank?
@repository = Repository.factory(params[:repository_scm])
@repository.project = @project if @repository
end
if request.post? && @repository
p1 = params[:repository]
p = {}
p_extra = {}
p1.each do |k, v|
if k =~ /^extra_/
p_extra[k] = v
else
p[k] = v
end
end
@repository.attributes = p
@repository.merge_extra_info(p_extra)
@repository.save
def new
scm = params[:repository_scm] || Redmine::Scm::Base.all.first
@repository = Repository.factory(scm)
@repository.project = @project
render :layout => !request.xhr?
end
def create
@repository = Repository.factory(params[:repository_scm], params[:repository])
@repository.project = @project
if request.post? && @repository.save
redirect_to settings_project_path(@project, :tab => 'repositories')
else
render :action => 'new'
end
render(:update) do |page|
page.replace_html "tab-content-repository",
:partial => 'projects/settings/repository'
if @repository && !@project.repository
@project.reload # needed to reload association
page.replace_html "main-menu", render_main_menu(@project)
end
end
def edit
end
def update
@repository.attributes = params[:repository]
@repository.project = @project
if request.put? && @repository.save
redirect_to settings_project_path(@project, :tab => 'repositories')
else
render :action => 'edit'
end
end
......@@ -76,16 +77,13 @@ class RepositoriesController < ApplicationController
# Build a hash with repository usernames as keys and corresponding user ids as values
@repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'committers', :id => @project
redirect_to settings_project_path(@project, :tab => 'repositories')
end
end
def destroy
@repository.destroy
redirect_to :controller => 'projects',
:action => 'settings',
:id => @project,
:tab => 'repository'
@repository.destroy if request.delete?
redirect_to settings_project_path(@project, :tab => 'repositories')
end
def show
......@@ -250,9 +248,23 @@ class RepositoriesController < ApplicationController
private
def find_repository
@repository = Repository.find(params[:id])
@project = @repository.project
rescue ActiveRecord::RecordNotFound
render_404
end
# TODO: remove it when multiple SCM support is added
def check_repository_uniqueness
if @project.repository
redirect_to settings_project_path(@project, :tab => 'repositories')
end
end
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
def find_repository
def find_project_repository
@project = Project.find(params[:id])
@repository = @project.repository
(render_404; return false) unless @repository
......
......@@ -30,7 +30,7 @@ module ProjectsHelper
{:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
{:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
{:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
{:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
{:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository},
{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
{:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
]
......
......@@ -139,13 +139,10 @@ module RepositoriesHelper
options_for_select(scm_options, repository.class.name.demodulize),
:disabled => (repository && !repository.new_record?),
:onchange => remote_function(
:url => {
:controller => 'repositories',
:action => 'edit',
:id => @project
},
:method => :get,
:with => "Form.serialize(this.form)")
:url => new_project_repository_path(@project),
:method => :get,
:update => 'content',
:with => "Form.serialize(this.form)")
)
end
......
......@@ -48,6 +48,26 @@ class Repository < ActiveRecord::Base
super(attr_name, *args)
end
alias :attributes_without_extra_info= :attributes=
def attributes=(new_attributes, guard_protected_attributes = true)
return if new_attributes.nil?
attributes = new_attributes.dup
attributes.stringify_keys!
p = {}
p_extra = {}
attributes.each do |k, v|
if k =~ /^extra_/
p_extra[k] = v
else
p[k] = v
end
end
send :attributes_without_extra_info=, p, guard_protected_attributes
merge_extra_info(p_extra)
end
# Removes leading and trailing whitespace
def url=(arg)
write_attribute(:url, arg ? arg.to_s.strip : nil)
......
<% if @project.repository %>
<table class="list">
<thead>
<tr>
<th><%= l(:label_scm) %></th>
<th><%= l(:label_repository) %></th>
<th></th>
</tr>
</thead>
<tbody>
<% repository = @project.repository %>
<tr class="<%= cycle 'odd', 'even' %>">
<td><%=h repository.scm_name %></td>
<td><%=h repository.url %></td>
<td class="buttons">
<% if User.current.allowed_to?(:manage_repository, @project) %>
<%= link_to(l(:label_user_plural), committers_repository_path(repository),
:class => 'icon icon-user') %>
<%= link_to(l(:button_edit), edit_repository_path(repository),
:class => 'icon icon-edit') %>
<%= link_to(l(:button_delete), repository_path(repository),
:confirm => l(:text_are_you_sure),
:method => :delete,
:class => 'icon icon-del') %>
<% end %>
</td>
</tr>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
<% if @project.repository.nil? && User.current.allowed_to?(:manage_repository, @project) %>
<p><%= link_to l(:label_repository_new), new_project_repository_path(@project), :class => 'icon icon-add' %></p>
<% end %>
<%= error_messages_for 'repository' %>
<div class="box tabular">
<p>
<%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(@repository) %>
<% if @repository && ! @repository.class.scm_available %>
<br />
<em><%= content_tag 'span', l(:text_scm_command_not_available), :class => 'error' %></em>
<% end %>
</p>
<% button_disabled = true %>
<% if @repository %>
<% button_disabled = ! @repository.class.scm_available %>
<%= repository_field_tags(f, @repository)%>
<% end %>
</div>
<p>
<%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save), :disabled => button_disabled) %>
<%= link_to l(:button_cancel), settings_project_path(@project, :tab => 'repositories') %>
</p>
\ No newline at end of file
<h2><%= l(:label_repository) %></h2>
<% labelled_form_for :repository, @repository, :url => repository_path(@path), :html => {:method => :put} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>
\ No newline at end of file
<h2><%= l(:label_repository_new) %></h2>
<% labelled_form_for :repository, @repository, :url => project_repositories_path(@project) do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>
......@@ -1011,3 +1011,4 @@ ar:
zero: 0 قضية
one: 1 قضية
other: "%{count} قضايا"
label_repository_new: New repository
......@@ -1009,3 +1009,4 @@ bg:
description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати
description_date_from: Въведете начална дата
description_date_to: Въведете крайна дата
label_repository_new: New repository
......@@ -1025,3 +1025,4 @@ bs:
zero: 0 aktivnost
one: 1 aktivnost
other: "%{count} aktivnosti"
label_repository_new: New repository
......@@ -1013,3 +1013,4 @@ ca:
zero: 0 assumpte
one: 1 assumpte
other: "%{count} assumptes"
label_repository_new: New repository
......@@ -1014,3 +1014,4 @@ cs:
zero: 0 Úkol
one: 1 Úkol
other: "%{count} Úkoly"
label_repository_new: New repository
......@@ -1028,3 +1028,4 @@ da:
zero: 0 sag
one: 1 sag
other: "%{count} sager"
label_repository_new: New repository
......@@ -1031,3 +1031,4 @@ de:
zero: 0 ticket
one: 1 ticket
other: "%{count} tickets"
label_repository_new: New repository
......@@ -1011,3 +1011,4 @@ el:
zero: 0 Θέμα
one: 1 Θέμα
other: "%{count} Θέματα"
label_repository_new: New repository
......@@ -1013,3 +1013,4 @@ en-GB:
zero: 0 issue
one: 1 issue
other: "%{count} issues"
label_repository_new: New repository
......@@ -650,6 +650,7 @@ en:
label_not_contains: doesn't contain
label_day_plural: days
label_repository: Repository
label_repository_new: New repository
label_repository_plural: Repositories
label_browse: Browse
label_modification: "%{count} change"
......
......@@ -1048,3 +1048,4 @@ es:
zero: 0 petición
one: 1 petición
other: "%{count} peticiones"
label_repository_new: New repository
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment