BigW Consortium Gitlab

Commit 1eabd9df by Marin Jankovski

Merge branch 'master' into relative_links_in_documentation

parents 3682a082 358426d6
......@@ -12,6 +12,7 @@ v 6.2.0
- Update logic for validates_merge_request for tree of MR (Andrew Kumanyaev)
- Rake tasks for web hooks management (Jonhnny Weslley)
- Extended User API to expose admin and can_create_group for user creation/updating (Boyan Tabakov)
- API: Remove group
v 6.1.0
- Project specific IDs for issues, mr, milestones
......
......@@ -65,11 +65,6 @@
.tree_author {
padding-right: 8px;
img.avatar {
margin-top: 0;
width: 16px;
}
}
.tree_commit {
......
......@@ -14,7 +14,7 @@ class Projects::MilestonesController < Projects::ApplicationController
@milestones = case params[:f]
when 'all'; @project.milestones.order("state, due_date DESC")
when 'closed'; @project.milestones.closed.order("due_date DESC")
else @project.milestones.active.order("due_date DESC")
else @project.milestones.active.order("due_date ASC")
end
@milestones = @milestones.includes(:project)
......
......@@ -222,7 +222,11 @@ class MergeRequest < ActiveRecord::Base
def mr_and_commit_notes
commit_ids = commits.map(&:id)
Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND commit_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids)
project.notes.where(
"(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND commit_id IN (:commit_ids))",
mr_id: id,
commit_ids: commit_ids
)
end
# Returns the raw diff for this merge request
......
......@@ -53,6 +53,7 @@ class Project < ActiveRecord::Base
has_many :services, dependent: :destroy
has_many :events, dependent: :destroy
has_many :merge_requests, dependent: :destroy, foreign_key: "target_project_id"
has_many :fork_merge_requests,dependent: :destroy, foreign_key: "source_project_id", class_name: MergeRequest
has_many :issues, dependent: :destroy, order: "state DESC, created_at DESC"
has_many :milestones, dependent: :destroy
has_many :notes, dependent: :destroy
......@@ -312,8 +313,11 @@ class Project < ActiveRecord::Base
branch_name = ref.gsub("refs/heads/", "")
c_ids = self.repository.commits_between(oldrev, newrev).map(&:id)
# Update code for merge requests
# Update code for merge requests into project between project branches
mrs = self.merge_requests.opened.by_branch(branch_name).all
# Update code for merge requests between project and project fork
mrs += self.fork_merge_requests.opened.by_branch(branch_name).all
mrs.each { |merge_request| merge_request.reload_code; merge_request.mark_as_unchecked }
# Close merge requests
......
......@@ -36,7 +36,8 @@ class SystemHooksService
when User
data.merge!({
name: model.name,
email: model.email
email: model.email,
user_id: model.id
})
when UsersProject
data.merge!({
......
......@@ -52,7 +52,8 @@
"created_at": "2012-07-21T07:44:07Z",
"email": "js@gitlabhq.com",
"event_name": "user_create",
"name": "John Smith"
"name": "John Smith",
"user_id": 41
}
6. User removed:
......@@ -60,7 +61,8 @@
"created_at": "2012-07-21T07:44:07Z",
"email": "js@gitlabhq.com",
"event_name": "user_destroy",
"name": "John Smith"
"name": "John Smith",
"user_id": 41
}
eos
......
.alert.alert-info
%span
Post-receive hooks for binding events.
%br
Read more about system hooks
%strong #{link_to "here", help_system_hooks_path, class: "vlink"}
%h3.page-title
System Hooks
%p.light
#{link_to "System hooks ", help_system_hooks_path, class: "vlink"} can be
used for binding events when GitLab creates a User or Project.
%hr
= form_for @hook, as: :hook, url: admin_hooks_path, html: { class: 'form-inline' } do |f|
-if @hook.errors.any?
......
%span.tree_author= commit_author_link(commit, avatar: true)
%span.tree_author= commit_author_link(commit, avatar: true, size: 16)
= link_to_gfm truncate(commit.title, length: 80), project_commit_path(@project, commit.id), class: "tree-commit-link"
......@@ -57,6 +57,19 @@ Parameters:
+ `project_id` (required) - The ID of a project
## Remove group
Removes group with all projects inside.
```
DELETE /groups/:id
```
Parameters:
+ `id` (required) - The ID of a user group
## Group members
......
......@@ -20,6 +20,8 @@ Parameters:
"project_id":3,
"title":"test1",
"state":"opened",
"upvotes":0,
"downvotes":0,
"author":{
"id":1,
"username": "admin",
......@@ -62,6 +64,8 @@ Parameters:
"project_id":3,
"title":"test1",
"state":"merged",
"upvotes":0,
"downvotes":0,
"author":{
"id":1,
"username": "admin",
......@@ -106,6 +110,8 @@ Parameters:
"project_id":3,
"title":"test1",
"state":"opened",
"upvotes":0,
"downvotes":0,
"author":{
"id":1,
"username": "admin",
......@@ -152,6 +158,8 @@ Parameters:
"project_id":3,
"title":"test1",
"state":"opened",
"upvotes":0,
"downvotes":0,
"author":{
"id":1,
"username": "admin",
......
......@@ -7,7 +7,7 @@ It's useful to make a backup just in case things go south:
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:create
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
```
### 1. Stop server
......@@ -95,5 +95,5 @@ Follow the [`upgrade guide from 5.0 to 5.1`](5.0-to-5.1.md), except for the data
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:restore
sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=production
```
......@@ -7,7 +7,7 @@ It's useful to make a backup just in case things go south:
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:create
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
```
### 1. Stop server
......@@ -78,5 +78,5 @@ Follow the [`upgrade guide from 5.1 to 5.2`](5.1-to-5.2.md), except for the data
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:restore
sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=production
```
......@@ -7,7 +7,7 @@ It's useful to make a backup just in case things go south:
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:create
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
```
### 1. Stop server
......@@ -86,5 +86,5 @@ Follow the [`upgrade guide from 5.2 to 5.3`](5.2-to-5.3.md), except for the data
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:restore
sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=production
```
......@@ -24,7 +24,7 @@ It's useful to make a backup just in case things go south:
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:create
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
```
### 1. Stop server
......
......@@ -16,7 +16,7 @@ It's useful to make a backup just in case things go south:
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:create
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
```
### 1. Stop server
......@@ -99,5 +99,5 @@ Follow the [`upgrade guide from 5.4 to 6.0`](5.4-to-6.0.md), except for the data
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:restore
sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=production
```
......@@ -9,7 +9,7 @@ It's useful to make a backup just in case things go south:
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:create
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
```
### 1. Stop server
......@@ -96,5 +96,5 @@ Follow the [`upgrade guide from 6.0 to 6.1`](6.0-to-6.1.md), except for the data
```bash
cd /home/git/gitlab
sudo -u git -H RAILS_ENV=production bundle exec rake gitlab:backup:restore
sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=production
```
......@@ -112,7 +112,7 @@ module API
end
class MergeRequest < Grape::Entity
expose :id, :target_branch, :source_branch, :title, :state
expose :id, :target_branch, :source_branch, :title, :state, :upvotes, :downvotes
expose :target_project_id, as: :project_id
expose :author, :assignee, using: Entities::UserBasic
end
......
......@@ -7,12 +7,14 @@ module API
helpers do
def find_group(id)
group = Group.find(id)
if current_user.admin or current_user.groups.include? group
if can?(current_user, :read_group, group)
group
else
render_api_error!("403 Forbidden - #{current_user.username} lacks sufficient access to #{group.name}", 403)
end
end
def validate_access_level?(level)
Gitlab::Access.options_with_owner.values.include? level.to_i
end
......@@ -64,6 +66,19 @@ module API
present group, with: Entities::GroupDetail
end
# Remove group
#
# Parameters:
# id (required) - The ID of a group
# Example Request:
# DELETE /groups/:id
delete ":id" do
group = find_group(params[:id])
authorize! :manage_group, group
group.destroy
end
# Transfer a project to the Group namespace
#
# Parameters:
......@@ -132,7 +147,6 @@ module API
member.destroy
end
end
end
end
end
......@@ -35,6 +35,7 @@ module API
user = key.user
return false if user.blocked?
return false if user.ldap_user? && Gitlab::LDAP::User.blocked?(user.extern_uid)
action = case git_cmd
when *DOWNLOAD_COMMANDS
......
......@@ -71,6 +71,16 @@ module Gitlab
find_by_uid(ldap_user.dn) if ldap_user
end
# Check LDAP user existance by dn. User in git over ssh check
#
# It covers 2 cases:
# * when ldap account was removed
# * when ldap account was deactivated by change of OU membership in 'dn'
def blocked?(dn)
ldap = OmniAuth::LDAP::Adaptor.new(ldap_conf)
ldap.connection.search(base: dn, size: 1).blank?
end
private
def find_by_uid(uid)
......
......@@ -151,7 +151,7 @@ stop() {
exit_if_not_running
# If the Unicorn web server is running, tell it to stop;
if [ "$web_status" = "0" ]; then
kill -QUIT "$wpid" &
kill -QUIT "$wpid"
echo "Stopping the GitLab Unicorn web server..."
stopping=true
else
......@@ -160,7 +160,7 @@ stop() {
# And do the same thing for the Sidekiq.
if [ "$sidekiq_status" = "0" ]; then
printf "Stopping Sidekiq job dispatcher."
RAILS_ENV=$RAILS_ENV bundle exec rake sidekiq:stop &
RAILS_ENV=$RAILS_ENV bundle exec rake sidekiq:stop
stopping=true
else
echo "The Sidekiq was not running, must have run out of breath."
......
......@@ -392,14 +392,20 @@ namespace :gitlab do
hook_file = "update"
gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path
gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file)
gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user
unless File.exists?(gitlab_shell_hook_file)
puts "can't check because of previous errors".magenta
return
if File.exists?(gitlab_shell_hook_file)
puts "yes".green
else
puts "no".red
puts "Could not find #{gitlab_shell_hook_file}"
try_fixing_it(
'Check the hooks_path in config/gitlab.yml',
'Check your gitlab-shell installation'
)
for_more_information(
see_installation_guide_section "GitLab Shell"
)
end
puts "yes".green
end
def check_repo_base_exists
......
......@@ -49,8 +49,8 @@ describe MergeRequest do
before do
merge_request.stub(:commits) { [merge_request.source_project.repository.commit] }
create(:note, commit_id: merge_request.commits.first.id, noteable_type: 'Commit')
create(:note, noteable: merge_request)
create(:note, commit_id: merge_request.commits.first.id, noteable_type: 'Commit', project: merge_request.project)
create(:note, noteable: merge_request, project: merge_request.project)
end
it "should include notes for commits" do
......
......@@ -106,6 +106,44 @@ describe API::API do
end
end
describe "DELETE /groups/:id" do
context "when authenticated as user" do
it "should remove group" do
delete api("/groups/#{group1.id}", user1)
response.status.should == 200
end
it "should not remove a group if not an owner" do
user3 = create(:user)
group1.add_user(user3, Gitlab::Access::MASTER)
delete api("/groups/#{group1.id}", user3)
response.status.should == 403
end
it "should not remove a non existing group" do
delete api("/groups/1328", user1)
response.status.should == 404
end
it "should not remove a group not attached to user1" do
delete api("/groups/#{group2.id}", user1)
response.status.should == 403
end
end
context "when authenticated as admin" do
it "should remove any existing group" do
delete api("/groups/#{group2.id}", admin)
response.status.should == 200
end
it "should not remove a non existing group" do
delete api("/groups/1328", admin)
response.status.should == 404
end
end
end
describe "POST /groups/:id/projects/:project_id" do
let(:project) { create(:project) }
before(:each) do
......
......@@ -5,37 +5,29 @@ describe SystemHooksService do
let (:project) { create :project }
let (:users_project) { create :users_project }
context 'it should build event data' do
it 'should build event data for user' do
SystemHooksService.build_event_data(user, :create).should include(:event_name, :name, :created_at, :email)
end
it 'should build event data for project' do
SystemHooksService.build_event_data(project, :create).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email)
end
it 'should build event data for users project' do
SystemHooksService.build_event_data(users_project, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access)
end
context 'event data' do
it { event_data(user, :create).should include(:event_name, :name, :created_at, :email, :user_id) }
it { event_data(user, :destroy).should include(:event_name, :name, :created_at, :email, :user_id) }
it { event_data(project, :create).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email) }
it { event_data(project, :destroy).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email) }
it { event_data(users_project, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access) }
it { event_data(users_project, :destroy).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access) }
end
context 'it should build event names' do
it 'should build event names for user' do
SystemHooksService.build_event_name(user, :create).should eq "user_create"
SystemHooksService.build_event_name(user, :destroy).should eq "user_destroy"
end
it 'should build event names for project' do
SystemHooksService.build_event_name(project, :create).should eq "project_create"
SystemHooksService.build_event_name(project, :destroy).should eq "project_destroy"
end
context 'event names' do
it { event_name(user, :create).should eq "user_create" }
it { event_name(user, :destroy).should eq "user_destroy" }
it { event_name(project, :create).should eq "project_create" }
it { event_name(project, :destroy).should eq "project_destroy" }
it { event_name(users_project, :create).should eq "user_add_to_team" }
it { event_name(users_project, :destroy).should eq "user_remove_from_team" }
end
it 'should build event names for users project' do
SystemHooksService.build_event_name(users_project, :create).should eq "user_add_to_team"
def event_data(*args)
SystemHooksService.build_event_data(*args)
end
SystemHooksService.build_event_name(users_project, :destroy).should eq "user_remove_from_team"
end
def event_name(*args)
SystemHooksService.build_event_name(*args)
end
end
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