Commit 31b1ffd5 authored by Douwe Maan's avatar Douwe Maan

Allow mirror user to be set.

parent 6d928726
......@@ -102,6 +102,8 @@ class Dispatcher
new Activities()
when 'projects:group_links:index'
new GroupsSelect()
when 'projects:mirrors:show', 'projects:mirrors:update'
new UsersSelect()
when 'admin:emails:show'
new AdminEmailSelect()
......
......@@ -8,6 +8,7 @@ class @UsersSelect
@projectId = $(select).data('project-id')
@groupId = $(select).data('group-id')
@showCurrentUser = $(select).data('current-user')
@pushCodeToProtectedBranches = $(select).data('push-code-to-protected-branches')
showNullUser = $(select).data('null-user')
showAnyUser = $(select).data('any-user')
showEmailUser = $(select).data('email-user')
......@@ -112,6 +113,7 @@ class @UsersSelect
group_id: @groupId
skip_ldap: @skipLdap
current_user: @showCurrentUser
push_code_to_protected_branches: @pushCodeToProtectedBranches
dataType: "json"
).done (users) ->
callback(users)
......
......@@ -34,7 +34,11 @@ class AutocompleteController < ApplicationController
@users = @users.search(params[:search]) if params[:search].present?
@users = @users.active
@users = @users.reorder(:name)
@users = @users.page(params[:page]).per(PER_PAGE)
if params[:push_code_to_protected_branches] && project
@users = @users.to_a.select { |user| user.can?(:push_code_to_protected_branches, project) }.take(PER_PAGE)
else
@users = @users.page(params[:page]).per(PER_PAGE)
end
unless params[:search].present?
# Include current user if available to filter by "Me"
......
......@@ -48,6 +48,6 @@ class Projects::ImportsController < Projects::ApplicationController
end
def import_params
params.require(:project).permit(:import_url, :mirror)
params.require(:project).permit(:import_url, :mirror, :mirror_user_id)
end
end
......@@ -16,8 +16,10 @@ class Projects::MirrorsController < Projects::ApplicationController
@project.update_mirror
flash[:notice] = "Mirroring settings were successfully updated. The project is being updated."
else
elsif @project.mirror_changed?
flash[:notice] = "Mirroring was successfully disabled."
else
flash[:notice] = "Mirroring settings were successfully updated."
end
redirect_to namespace_project_mirror_path(@project.namespace, @project)
......@@ -31,11 +33,11 @@ class Projects::MirrorsController < Projects::ApplicationController
flash[:notice] = "The repository is being updated..."
redirect_back_or_default(default: namespace_project_path(@project.namespace, @project))
end
end
private
def mirror_params
params.require(:project).permit(:mirror, :import_url)
params.require(:project).permit(:mirror, :import_url, :mirror_user_id)
end
end
......@@ -237,6 +237,7 @@ class ProjectsController < ApplicationController
:merge_requests_rebase_enabled,
:merge_requests_template,
:mirror,
:mirror_user_id,
:reset_approvals_on_push
)
end
......
......@@ -13,6 +13,7 @@ module SelectsHelper
first_user = opts[:first_user] && current_user ? current_user.username : false
current_user = opts[:current_user] || false
project = opts[:project] || @project
push_code_to_protected_branches = opts[:push_code_to_protected_branches]
html = {
class: css_class,
......@@ -21,7 +22,8 @@ module SelectsHelper
'data-any-user' => any_user,
'data-email-user' => email_user,
'data-first-user' => first_user,
'data-current-user' => current_user
'data-current-user' => current_user,
'data-push-code-to-protected-branches' => push_code_to_protected_branches
}
unless opts[:scope] == :all
......
......@@ -76,6 +76,8 @@ class Project < ActiveRecord::Base
has_one :git_hook, dependent: :destroy
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event', foreign_key: 'project_id'
belongs_to :mirror_user, foreign_key: 'mirror_user_id', class_name: 'User'
# Project services
has_many :services
has_one :gitlab_ci_service, dependent: :destroy
......@@ -162,6 +164,7 @@ class Project < ActiveRecord::Base
format: { with: /\A#{URI.regexp(%w(ssh git http https))}\z/, message: 'should be a valid url' },
if: :external_import?
validates :import_url, presence: true, if: :mirror?
validates :mirror_user, presence: true, if: :mirror?
validates :star_count, numericality: { greater_than_or_equal_to: 0 }
validate :check_limit, on: :create
validate :avatar_type,
......
......@@ -55,5 +55,16 @@
%li
The update action will time out after 10 minutes. For big repositories, use a clone/push combination.
.form-group
= f.label :mirror_user_id, class: 'control-label' do
Mirror user
.col-sm-10
= users_select_tag("project[mirror_user_id]", class: 'input-large', selected: @project.mirror_user_id || current_user.id,
first_user: true, current_user: true, push_code_to_protected_branches: true)
.help-block
This user will be the author of all events in the activity feed that are the result of an update,
like new branches being created or new commits being pushed to existing branches.
They need to have at least master access to this project.
.form-actions
= f.submit "Save Changes", class: "btn btn-create"
......@@ -24,3 +24,5 @@
Mirror repository
.help-block
Automatically update this project's branches and tags from the upstream repository every hour.
= f.hidden_field :mirror_user_id, value: current_user.id
......@@ -8,8 +8,7 @@ class RepositoryUpdateMirrorWorker
def perform(project_id)
@project = Project.find(project_id)
# TODO: Use actual user
@current_user = User.last
@current_user = @project.mirror_user || @project.creator
result = Projects::UpdateMirrorService.new(@project, @current_user).execute
if result[:status] == :error
......
......@@ -3,5 +3,6 @@ class AddMirrorToProject < ActiveRecord::Migration
add_column :projects, :mirror, :boolean, default: false, null: false
add_column :projects, :mirror_last_update_at, :datetime
add_column :projects, :mirror_last_successful_update_at, :datetime
add_column :projects, :mirror_user_id, :integer
end
end
......@@ -48,9 +48,9 @@ ActiveRecord::Schema.define(version: 20151114113410) do
t.boolean "twitter_sharing_enabled", default: true
t.text "help_text"
t.text "restricted_visibility_levels"
t.boolean "version_check_enabled", default: true
t.integer "max_attachment_size", default: 10, null: false
t.integer "default_project_visibility"
t.boolean "version_check_enabled", default: true
t.integer "default_snippet_visibility"
t.text "restricted_signup_domains"
t.boolean "user_oauth_applications", default: true
......@@ -725,10 +725,11 @@ ActiveRecord::Schema.define(version: 20151114113410) do
t.boolean "reset_approvals_on_push", default: true
t.boolean "merge_requests_ff_only_enabled", default: false
t.text "issues_template"
t.text "import_error"
t.boolean "mirror", default: false, null: false
t.datetime "mirror_last_update_at"
t.datetime "mirror_last_successful_update_at"
t.text "import_error"
t.integer "mirror_user_id"
end
add_index "projects", ["created_at", "id"], name: "index_projects_on_created_at_and_id", using: :btree
......
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