From 4ee008d0e71608f48b210b57067e9b156dc36a05 Mon Sep 17 00:00:00 2001
From: GitLab <gitlab@localhost>
Date: Fri, 16 Aug 2013 19:15:47 +0200
Subject: [PATCH 01/14] Add generated password and password expiry to user
 creation call

---
 lib/api/users.rb | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/lib/api/users.rb b/lib/api/users.rb
index 84256b51124..9d96b01a99a 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -31,8 +31,9 @@ module API
       #
       # Parameters:
       #   email (required)                  - Email
-      #   password (required)               - Password
-      #   name                              - Name
+      #   password (semi-required)          - Password
+      #   name (required)                   - Name
+      #   username (required)               - username
       #   skype                             - Skype ID
       #   linkedin                          - Linkedin
       #   twitter                           - Twitter account
@@ -40,13 +41,42 @@ module API
       #   extern_uid                        - External authentication provider UID
       #   provider                          - External provider
       #   bio                               - Bio
+      #   password_expired                  - password is set expired
+      #   force_random_password             - generate random password for user
       # Example Request:
       #   POST /users
       post do
         authenticated_as_admin!
-        required_attributes! [:email, :password, :name, :username]
+        required_attributes! [:email, :name, :username]
+
+        attrs = attributes_for_keys [:email, :name, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio]
+
+        #parse password strategy params
+        if params[:expired_password].present?
+          expired = params[:expired_password].to_i > 0
+        else
+          expired = false
+        end
+        if params[:force_random_password].present?
+          force_random = params[:force_random_password].to_i > 0
+        else
+          force_random = false
+        end
+
+        #check params set properly
+        if !(force_random ^ params[:password].present?)
+          render_api_error!('400 Either password or force_random must be set',400)
+        end
+
+        if expired
+          attrs[:password_expires_at] = Time.now
+        end
+        if force_random
+          attrs[:force_random_password] = true
+        else
+          attrs[:password] = params[:password]
+        end
 
-        attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio]
         user = User.new attrs, as: :admin
         if user.save
           present user, with: Entities::User
-- 
GitLab


From a1d7353e18ce03772ae57f78d27a3ea7bc01860e Mon Sep 17 00:00:00 2001
From: GitLab <gitlab@localhost>
Date: Sat, 17 Aug 2013 19:52:19 +0200
Subject: [PATCH 02/14] Completed proper temp password api option

---
 lib/api/users.rb | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/lib/api/users.rb b/lib/api/users.rb
index 9d96b01a99a..1b563250a09 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -41,7 +41,7 @@ module API
       #   extern_uid                        - External authentication provider UID
       #   provider                          - External provider
       #   bio                               - Bio
-      #   password_expired                  - password is set expired
+      #   expired_password                  - password is set expired
       #   force_random_password             - generate random password for user
       # Example Request:
       #   POST /users
@@ -52,25 +52,16 @@ module API
         attrs = attributes_for_keys [:email, :name, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio]
 
         #parse password strategy params
-        if params[:expired_password].present?
-          expired = params[:expired_password].to_i > 0
-        else
-          expired = false
-        end
-        if params[:force_random_password].present?
-          force_random = params[:force_random_password].to_i > 0
-        else
-          force_random = false
-        end
+        expired = params[:expired_password] && (params[:expired_password].to_i > 0)
+        force_random =  params[:force_random_password] && (params[:force_random_password].to_i > 0)
 
         #check params set properly
         if !(force_random ^ params[:password].present?)
           render_api_error!('400 Either password or force_random must be set',400)
         end
 
-        if expired
-          attrs[:password_expires_at] = Time.now
-        end
+        attrs[:password_expires_at] = Time.now if expired
+
         if force_random
           attrs[:force_random_password] = true
         else
@@ -78,6 +69,8 @@ module API
         end
 
         user = User.new attrs, as: :admin
+        user.created_by_id = current_user.id if expired # this is necessary to make the new user notification work correctly.
+
         if user.save
           present user, with: Entities::User
         else
-- 
GitLab


From a4e4424633a53b409dedf4fedf188bb430334578 Mon Sep 17 00:00:00 2001
From: Lukas Erlacher <l.erlacher@gmail.com>
Date: Mon, 16 Sep 2013 17:38:14 +0200
Subject: [PATCH 03/14] Test for force_random_password

Added a test for the new features introduced to the user api in ba10a34
---
 spec/requests/api/users_spec.rb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index e42c0567ef6..7ca31f6ebcd 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -75,11 +75,16 @@ describe API::API do
       response.status.should == 400
     end
 
-    it "should return 400 error if password not given" do
+    it "should return 400 error if password or force_random_password not given" do
       post api("/users", admin), { email: 'test@example.com' }
       response.status.should == 400
     end
 
+    it "should return 400 error if both password and force_random_password are set" do
+      post api("/users", admin), { password: 'password', force_random_password: '1' }
+      response.status.should == 400
+    end
+
     it "should return 400 error if email not given" do
       post api("/users", admin), { password: 'pass1234' }
       response.status.should == 400
-- 
GitLab


From 28cce431606e7b95ff6d46e2cb0ac0a181c01f92 Mon Sep 17 00:00:00 2001
From: Lukas Erlacher <l.erlacher@gmail.com>
Date: Mon, 16 Sep 2013 17:59:13 +0200
Subject: [PATCH 04/14] Correct error message param reference

Parameter reference in error string was typo'd.
---
 lib/api/users.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/api/users.rb b/lib/api/users.rb
index 1b563250a09..eb9f5ccb63e 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -57,7 +57,7 @@ module API
 
         #check params set properly
         if !(force_random ^ params[:password].present?)
-          render_api_error!('400 Either password or force_random must be set',400)
+          render_api_error!('400 Either password or force_random_password must be set',400)
         end
 
         attrs[:password_expires_at] = Time.now if expired
-- 
GitLab


From 24622941faf627484a8d1f3be62e267cd7687797 Mon Sep 17 00:00:00 2001
From: Lukas Erlacher <l.erlacher@gmail.com>
Date: Mon, 16 Sep 2013 18:42:31 +0200
Subject: [PATCH 05/14] Correct parameters for /user api call tests

Several tests for the /user api call were succeeding for the wrong reason.
The tests were all missing required parameters, so the api would return
an error because of that and not because of the specific condition
intended to be tested.

Also fixed a small typo.
---
 spec/requests/api/users_spec.rb | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 7ca31f6ebcd..88c872c743b 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -71,26 +71,26 @@ describe API::API do
     end
 
     it "should not create user with invalid email" do
-      post api("/users", admin), { email: "invalid email", password: 'password' }
+      post api("/users", admin), { email: "invalid email", password: 'password', name: "T. User", username: "testuser" }
       response.status.should == 400
     end
 
     it "should return 400 error if password or force_random_password not given" do
-      post api("/users", admin), { email: 'test@example.com' }
+      post api("/users", admin), { email: 'test@example.com', name: "T. User", username: "testuser" }
       response.status.should == 400
     end
 
     it "should return 400 error if both password and force_random_password are set" do
-      post api("/users", admin), { password: 'password', force_random_password: '1' }
+      post api("/users", admin), { password: 'password', force_random_password: '1', email: 'test@example.com', name: "T. User", username: "testuser"   }
       response.status.should == 400
     end
 
     it "should return 400 error if email not given" do
-      post api("/users", admin), { password: 'pass1234' }
+      post api("/users", admin), { password: 'pass1234', name: "T. User", username: "testuser"  }
       response.status.should == 400
     end
 
-    it "shouldn't available for non admin users" do
+    it "shouldn't be available for non admin users" do
       post api("/users", user), attributes_for(:user)
       response.status.should == 403
     end
-- 
GitLab


From c8fe55ed54056a9ff4ffff7b8996f468c9110f47 Mon Sep 17 00:00:00 2001
From: Lukas Erlacher <l.erlacher@gmail.com>
Date: Mon, 16 Sep 2013 21:11:53 +0200
Subject: [PATCH 06/14] Changed /users POST call parameter comments

replaced "semi-required" description for password field to proper
description.
---
 lib/api/users.rb | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/api/users.rb b/lib/api/users.rb
index eb9f5ccb63e..5ce3daf2378 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -30,19 +30,19 @@ module API
       # Create user. Available only for admin
       #
       # Parameters:
-      #   email (required)                  - Email
-      #   password (semi-required)          - Password
-      #   name (required)                   - Name
-      #   username (required)               - username
-      #   skype                             - Skype ID
-      #   linkedin                          - Linkedin
-      #   twitter                           - Twitter account
-      #   projects_limit                    - Number of projects user can create
-      #   extern_uid                        - External authentication provider UID
-      #   provider                          - External provider
-      #   bio                               - Bio
-      #   expired_password                  - password is set expired
-      #   force_random_password             - generate random password for user
+      #   email (required)                                          - Email
+      #   password (required unless force_random_password is set)   - Password
+      #   name (required)                                           - Name
+      #   username (required)                                       - username
+      #   skype                                                     - Skype ID
+      #   linkedin                                                  - Linkedin
+      #   twitter                                                   - Twitter account
+      #   projects_limit                                            - Number of projects user can create
+      #   extern_uid                                                - External authentication provider UID
+      #   provider                                                  - External provider
+      #   bio                                                       - Bio
+      #   expired_password                                          - password is set expired
+      #   force_random_password (required unless password is set)   - generate random password for user
       # Example Request:
       #   POST /users
       post do
-- 
GitLab


From 0e83ffec04028d1210c6494378d3927e5b97fa8b Mon Sep 17 00:00:00 2001
From: Lukas Erlacher <l.erlacher@gmail.com>
Date: Mon, 16 Sep 2013 21:15:27 +0200
Subject: [PATCH 07/14] Marked true/false parameters

---
 lib/api/users.rb | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/api/users.rb b/lib/api/users.rb
index 5ce3daf2378..fb372d5e18e 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -30,19 +30,19 @@ module API
       # Create user. Available only for admin
       #
       # Parameters:
-      #   email (required)                                          - Email
-      #   password (required unless force_random_password is set)   - Password
-      #   name (required)                                           - Name
-      #   username (required)                                       - username
-      #   skype                                                     - Skype ID
-      #   linkedin                                                  - Linkedin
-      #   twitter                                                   - Twitter account
-      #   projects_limit                                            - Number of projects user can create
-      #   extern_uid                                                - External authentication provider UID
-      #   provider                                                  - External provider
-      #   bio                                                       - Bio
-      #   expired_password                                          - password is set expired
-      #   force_random_password (required unless password is set)   - generate random password for user
+      #   email (required)                                                    - Email
+      #   password (required unless force_random_password is set)             - Password
+      #   name (required)                                                     - Name
+      #   username (required)                                                 - username
+      #   skype                                                               - Skype ID
+      #   linkedin                                                            - Linkedin
+      #   twitter                                                             - Twitter account
+      #   projects_limit                                                      - Number of projects user can create
+      #   extern_uid                                                          - External authentication provider UID
+      #   provider                                                            - External provider
+      #   bio                                                                 - Bio
+      #   expired_password (true/false)                                       - password is set expired
+      #   force_random_password (true/false; required unless password is set) - generate random password for user
       # Example Request:
       #   POST /users
       post do
-- 
GitLab


From d8012e525f1a8654e7a000bfc8c061178fb9991f Mon Sep 17 00:00:00 2001
From: "J. Random Hacker (duk3luk3)" <hacker@greyhat.raptorswithhats.com>
Date: Sun, 22 Sep 2013 20:01:12 +0200
Subject: [PATCH 08/14] Code formatting

Removed parentheses in if-statements
---
 lib/api/users.rb | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/lib/api/users.rb b/lib/api/users.rb
index fb372d5e18e..e5b6ac18d46 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -55,19 +55,15 @@ module API
         expired = params[:expired_password] && (params[:expired_password].to_i > 0)
         force_random =  params[:force_random_password] && (params[:force_random_password].to_i > 0)
 
-        #check params set properly
-        if !(force_random ^ params[:password].present?)
+        if params[:password] && !force_random
+          attrs[:password] = params[:password]
+        elsif force_random && !params[:password]
+          attrs[:force_random_password] = true
+        else
           render_api_error!('400 Either password or force_random_password must be set',400)
-        end
 
         attrs[:password_expires_at] = Time.now if expired
 
-        if force_random
-          attrs[:force_random_password] = true
-        else
-          attrs[:password] = params[:password]
-        end
-
         user = User.new attrs, as: :admin
         user.created_by_id = current_user.id if expired # this is necessary to make the new user notification work correctly.
 
-- 
GitLab


From 4965970ef3af6bd56450f134ae06008d91662d9a Mon Sep 17 00:00:00 2001
From: "J. Random Hacker (duk3luk3)" <hacker@greyhat.raptorswithhats.com>
Date: Sun, 22 Sep 2013 20:07:20 +0200
Subject: [PATCH 09/14] Documentation for /users POST api

Added documentation for the extended api.
---
 doc/api/users.md | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/doc/api/users.md b/doc/api/users.md
index 49afbab8c6a..b9651c19b97 100644
--- a/doc/api/users.md
+++ b/doc/api/users.md
@@ -87,17 +87,19 @@ POST /users
 
 Parameters:
 
-+ `email` (required)          - Email
-+ `password` (required)       - Password
-+ `username` (required)       - Username
-+ `name` (required)           - Name
-+ `skype` (optional)          - Skype ID
-+ `linkedin` (optional)       - Linkedin
-+ `twitter` (optional)        - Twitter account
-+ `projects_limit` (optional) - Number of projects user can create
-+ `extern_uid` (optional)     - External UID
-+ `provider` (optional)       - External provider name
-+ `bio` (optional)            - User's bio
++ `email` (required)                                                    - Email
++ `password` (required unless force_random_password is set)             - Password
++ `username` (required)                                                 - Username
++ `name` (required)                                                     - Name
++ `skype` (optional)                                                    - Skype ID
++ `linkedin` (optional)                                                 - Linkedin
++ `twitter` (optional)                                                  - Twitter account
++ `projects_limit` (optional)                                           - Number of projects user can create
++ `extern_uid` (optional)                                               - External UID
++ `provider` (optional)                                                 - External provider name
++ `bio` (optional)                                                      - User's bio
++ `expired_password` (true/false)                                       - Password is set expired
++ `force_random_password` (true/false; required unless password is set) - generate random password for user
 
 
 ## User modification
-- 
GitLab


From 650db83680f83ca5f6719ca0b02abc0feb525746 Mon Sep 17 00:00:00 2001
From: Kevin Krauss <earlkrauss@gmail.com>
Date: Tue, 1 Oct 2013 11:51:43 -0700
Subject: [PATCH 10/14] Update gitlab

---
 lib/support/nginx/gitlab | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/support/nginx/gitlab b/lib/support/nginx/gitlab
index 3e929c52990..54bf6fb9059 100644
--- a/lib/support/nginx/gitlab
+++ b/lib/support/nginx/gitlab
@@ -1,6 +1,6 @@
 # GITLAB
 # Maintainer: @randx
-# App Version: 5.0
+# App Version: 6.1
 
 upstream gitlab {
   server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
-- 
GitLab


From 976185db97d767db2dc88a1a39d1bc53606af311 Mon Sep 17 00:00:00 2001
From: Jacob Vosmaer <contact@jacobvosmaer.nl>
Date: Wed, 9 Oct 2013 15:44:25 +0200
Subject: [PATCH 11/14] Always shut down sidekiq before starting

---
 lib/tasks/sidekiq.rake | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake
index d0e9dfe46a1..e71cf0380ed 100644
--- a/lib/tasks/sidekiq.rake
+++ b/lib/tasks/sidekiq.rake
@@ -5,7 +5,15 @@ namespace :sidekiq do
   end
 
   desc "GITLAB | Start sidekiq"
-  task :start do
+  task :start => :restart
+
+  desc 'GitLab | Restart sidekiq'
+  task :restart do
+    if File.exist?(pidfile)
+      puts 'Shutting down existing sidekiq process.'
+      Rake::Task['sidekiq:stop'].invoke
+      puts 'Starting new sidekiq process.'
+    end
     system "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &"
   end
 
-- 
GitLab


From a02a4dfa3793dad1a3ac5ede2c606824dbd58dee Mon Sep 17 00:00:00 2001
From: Jacob Vosmaer <contact@jacobvosmaer.nl>
Date: Wed, 9 Oct 2013 15:46:00 +0200
Subject: [PATCH 12/14] Remove duplicate log path generation

---
 lib/tasks/sidekiq.rake | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake
index e71cf0380ed..46caffd0754 100644
--- a/lib/tasks/sidekiq.rake
+++ b/lib/tasks/sidekiq.rake
@@ -14,15 +14,19 @@ namespace :sidekiq do
       Rake::Task['sidekiq:stop'].invoke
       puts 'Starting new sidekiq process.'
     end
-    system "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &"
+    system "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{log_file} 2>&1 &"
   end
 
   desc "GITLAB | Start sidekiq with launchd on Mac OS X"
   task :launchd do
-    system "bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1"
+    system "bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{log_file} 2>&1"
   end
 
   def pidfile
     Rails.root.join("tmp", "pids", "sidekiq.pid")
   end
+
+  def log_file
+    Rails.root.join("log", "sidekiq.log")
+  end
 end
-- 
GitLab


From 70563a780f6db9a13b380ab6aed79915fe9d3f56 Mon Sep 17 00:00:00 2001
From: Jacob Vosmaer <contact@jacobvosmaer.nl>
Date: Wed, 9 Oct 2013 15:48:28 +0200
Subject: [PATCH 13/14] Use built-in sidekiq deamonization

---
 lib/tasks/sidekiq.rake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake
index 46caffd0754..ba79b6e035d 100644
--- a/lib/tasks/sidekiq.rake
+++ b/lib/tasks/sidekiq.rake
@@ -14,7 +14,7 @@ namespace :sidekiq do
       Rake::Task['sidekiq:stop'].invoke
       puts 'Starting new sidekiq process.'
     end
-    system "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{log_file} 2>&1 &"
+    system "bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} -d -L #{log_file} >> #{log_file} 2>&1"
   end
 
   desc "GITLAB | Start sidekiq with launchd on Mac OS X"
-- 
GitLab


From 22fc1fe4a69552f6f40659db7791dd517061f862 Mon Sep 17 00:00:00 2001
From: Lukas Erlacher <erlacher@in.tum.de>
Date: Wed, 23 Oct 2013 17:03:56 +0200
Subject: [PATCH 14/14] Syntax Error fixed

---
 lib/api/users.rb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/api/users.rb b/lib/api/users.rb
index e5b6ac18d46..69b850f8ae4 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -61,6 +61,7 @@ module API
           attrs[:force_random_password] = true
         else
           render_api_error!('400 Either password or force_random_password must be set',400)
+	end
 
         attrs[:password_expires_at] = Time.now if expired
 
-- 
GitLab