diff --git a/.gitignore b/.gitignore index d22760e778069498ed0e86a4bccbcb06f870a28a..b636554543ae576eabdf673dcdb5f49e9da5c628 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +vendor/bundle .bundle .rbx/ db/*.sqlite3 diff --git a/.rvmrc.example b/.rvmrc.example new file mode 100644 index 0000000000000000000000000000000000000000..15ef749243f8696e186f6c4dc109a7c5da1dc9c4 --- /dev/null +++ b/.rvmrc.example @@ -0,0 +1 @@ +rvm 1.9.3@gitlabhq diff --git a/Gemfile b/Gemfile index 8e569c5b2e525b07ba78e552352717004371a76a..2d6f1946526e2031df6f183cb11353096324604c 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,8 @@ gem "rails", "3.2.8" gem "sqlite3" gem "mysql2" +gem 'devise_cas_authenticatable' + # Auth gem "devise", "~> 2.1.0" gem 'omniauth' diff --git a/Gemfile.lock b/Gemfile.lock index 3d27d3fbe816fcf5af41114e741d6f9ddb5c7068..3ad06fecce35f41a92a1d1c91668b41064925f6b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -141,6 +141,9 @@ GEM orm_adapter (~> 0.1) railties (~> 3.1) warden (~> 1.2.1) + devise_cas_authenticatable (1.1.2) + devise (>= 1.0.6) + rubycas-client (>= 2.2.1) diff-lcs (1.1.3) draper (0.17.0) actionpack (~> 3.2) @@ -331,6 +334,8 @@ GEM activesupport (>= 3.0) railties (>= 3.0) rspec (~> 2.10.0) + rubycas-client (2.3.9) + activesupport rubyntlm (0.1.1) rubypython (0.6.2) blankslate (>= 2.1.2.3) @@ -422,7 +427,7 @@ DEPENDENCIES colored database_cleaner devise (~> 2.1.0) - draper + drapper email_spec factory_girl_rails ffaker diff --git a/app/models/user.rb b/app/models/user.rb index 47876722755db329f48081131796be9324d2fdb0..22d26a68f456a04406f9fe2d47af1925292543fa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,12 +2,11 @@ class User < ActiveRecord::Base include Account - devise :database_authenticatable, :token_authenticatable, :lockable, - :recoverable, :rememberable, :trackable, :validatable, :omniauthable + devise :cas_authenticatable, :trackable attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :projects_limit, :skype, :linkedin, :twitter, :dark_scheme, - :theme_id, :force_random_password, :extern_uid, :provider + :theme_id, :force_random_password, :username attr_accessor :force_random_password @@ -56,7 +55,6 @@ class User < ActiveRecord::Base validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider} - before_save :ensure_authentication_token alias_attribute :private_token, :authentication_token scope :not_in_project, lambda { |project| where("id not in (:ids)", ids: project.users.map(&:id) ) } @@ -64,7 +62,7 @@ class User < ActiveRecord::Base scope :blocked, where(blocked: true) scope :active, where(blocked: false) - before_validation :generate_password, on: :create + before_validation :generate_password, :on => :create def generate_password if self.force_random_password @@ -72,6 +70,10 @@ class User < ActiveRecord::Base end end + def generate_email + self.email = "#{self.username}@locaweb.com.br" + end + def self.filter filter_name case filter_name when "admins"; self.admins diff --git a/config/gitlab.nginx b/config/gitlab.nginx new file mode 100644 index 0000000000000000000000000000000000000000..0b313b7c4c64efea95465e581ccfb9e5cf4a4635 --- /dev/null +++ b/config/gitlab.nginx @@ -0,0 +1,45 @@ +upstream gitlab { + server unix:/var/www/gitlabhq/tmp/sockets/gitlab.socket; +} + +server { + listen 80; + listen [::]:80; + listen 443 default ssl; + + # change the server_name to your host + server_name gitlab.local.host; + + root /var/www/gitlabhq/public; + ssl on; + #ssl_certificate /path/to/my/cert; + #ssl_certificate_key /path/to/my/key; + + + # individual nginx logs for this gitlab vhost + access_log /var/log/nginx/gitlab_access.log; + error_log /var/log/nginx/gitlab_error.log; + + if ($ssl_protocol = "") { + rewrite ^ https://$server_name$request_uri? permanent; + } + + location / { + # serve static files from defined root folder;. + # @gitlab is a named location for the upstream fallback, see below + try_files $uri $uri/index.html $uri.html @gitlab; + } + + # if a file, which is not found in the root folder is requested, + # then the proxy pass the request to the upsteam (gitlab unicorn) + location @gitlab { + proxy_redirect off; + # you need to change this to "https", if you set "ssl" directive to "on" + proxy_set_header X-FORWARDED_PROTO https; + proxy_set_header Host gitlab.local.host:80; + proxy_set_header X-Real-IP $remote_addr; + + proxy_pass http://gitlab; + } + +} diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 8f3cef5a2ac769578a219ad580dd04ee461aab37..4bd13dfd42b339837dcb6466ddccc0cf028f2260 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,6 +1,7 @@ # Use this hook to configure devise mailer, warden hooks and so forth. The first # four configuration values can also be set straight in your models. Devise.setup do |config| + config.cas_base_url = "https://sso.sysint.locaweb.com.br/cas-web" # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class with default "from" parameter. diff --git a/config/unicorn.rb.orig b/config/unicorn.rb similarity index 100% rename from config/unicorn.rb.orig rename to config/unicorn.rb diff --git a/db/migrate/20120728014121_add_cas_authenticatable.rb b/db/migrate/20120728014121_add_cas_authenticatable.rb new file mode 100644 index 0000000000000000000000000000000000000000..f2e8436fc8d3a9b9b884a44a0c20b607802e9919 --- /dev/null +++ b/db/migrate/20120728014121_add_cas_authenticatable.rb @@ -0,0 +1,11 @@ +class AddCasAuthenticatable < ActiveRecord::Migration + def up + add_column :users, :username, :string + add_index :users, :username, :unique => true + end + + def down + remove_column :users, :username + remove_index :users, :username, :unique => true + end +end diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000000000000000000000000000000000000..4b194110c00edf1c50360ec0baf2de89381c6482 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,6 @@ +gitlabhq (0.0.1-1) unstable; urgency=low + + * Initial release, first version of changelog, not really a real changelog + yet. + + -- Rodrigo Sampaio Vaz Wed, 11 Jul 2012 01:36:16 -0300 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000000000000000000000000000000000000..a3f8415175d81b3892ff69c08219bc792da86318 --- /dev/null +++ b/debian/control @@ -0,0 +1,16 @@ +Source: gitlabhq +Section: ruby +Priority: extra +Maintainer: Rodrigo Sampaio Vaz +Build-Depends: debhelper, libicu-dev, ruby1.9.1-dev, libmysqlclient-dev, libsqlite3-dev +Standards-Version: 3.8.4 +Homepage: http://gitlabhq.com +#Vcs-Git: git://git.debian.org/collab-maint/gitlabhq.git +#Vcs-Browser: http://git.debian.org/?p=collab-maint/gitlabhq.git;a=summary + +Package: gitlabhq +Architecture: any +Depends: libmysqlclient16, libsqlite3-0, ruby1.9.1, gitolite, nginx | apache-mpm-worker, redis-server +Recommends: libbundler-ruby +Description: Self Hosted Git Management + Fast, secure and stable solution based on Ruby on Rails & Gitolite. Distributed under the MIT License. diff --git a/debian/init.d b/debian/init.d new file mode 100644 index 0000000000000000000000000000000000000000..27a086e65f3b32e99dca53495fc714ae78770aee --- /dev/null +++ b/debian/init.d @@ -0,0 +1,57 @@ +#! /bin/bash +### BEGIN INIT INFO +# Provides: gitlab +# Required-Start: $local_fs $remote_fs $network $syslog redis-server +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: GitLab git repository management +# Description: GitLab git repository management +### END INIT INFO + +DAEMON_OPTS="-c /var/www/gitlabhq/config/unicorn.rb -E production -D" +NAME=unicorn +DESC="Gitlab service" +PID=/var/www/gitlabhq/tmp/pids/unicorn.pid +RESQUE_PID=/var/www/gitlabhq/tmp/pids/resque_worker.pid + +case "$1" in + start) + CD_TO_APP_DIR="cd /var/www/gitlabhq" + START_DAEMON_PROCESS="bundle exec unicorn_rails $DAEMON_OPTS" + START_RESQUE_PROCESS="./resque.sh" + + echo -n "Starting $DESC: " + if [ `whoami` = root ]; then + su - gitlab -c "sh -l -c \"$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS\"" + else + $CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS + fi + echo "$NAME." + ;; + stop) + echo -n "Stopping $DESC: " + kill -QUIT `cat $PID` + kill -QUIT `cat $RESQUE_PID` + echo "$NAME." + ;; + restart) + echo -n "Restarting $DESC: " + kill -USR2 `cat $PID` + kill -USR2 `cat $RESQUE_PID` + echo "$NAME." + ;; + reload) + echo -n "Reloading $DESC configuration: " + kill -HUP `cat $PID` + kill -HUP `cat $RESQUE_PID` + echo "$NAME." + ;; + *) + echo "Usage: $NAME {start|stop|restart|reload}" >&2 + exit 1 + ;; +esac + +exit 0 + diff --git a/debian/postinst b/debian/postinst new file mode 100644 index 0000000000000000000000000000000000000000..9adb0201ee2fa0f8a4edb3e0bcce784bb1d0b4f6 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,67 @@ +#!/bin/sh +# postinst script for gitlabhq +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + + makedir /tmp/gitlab root:root 700 + + chgrp git /tmp/gitlab 2>/dev/null || + addgroup --system git + chown git /tmp/gitlab 2>/dev/null || + adduser \ + --system \ + --home /home/git \ + --shell /bin/sh \ + --gecos 'git version control' \ + --ingroup git \ + --disabled-password git + + + chown gitlab /tmp/gitlab 2>/dev/null || + adduser --disabled-login --gecos 'gitlab system' --ingroup git gitlab + + su - gitlab -c "ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa" + + cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub + chmod 777 /home/git/gitlab.pub + + sed -i 's/0077/0007/g' /etc/gitolite/example.gitolite.rc + su - git -c 'sh -c "gl-setup /home/git/gitlab.pub"' + + chmod -R g+rwX /home/git/repositories/ + chown -R git:git /home/git/repositories/ + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000000000000000000000000000000000000..caa49e9496b1210880cc7d16d41293e50480d520 --- /dev/null +++ b/debian/rules @@ -0,0 +1,28 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +export DH_VERBOSE=1 + +inst_dir=debian/tmp/var/www/gitlabhq + +%: + dh $@ + +override_dh_prep: + bundle install --without=test:development --deployment + +override_dh_install: + mkdir -p $(inst_dir) + mkdir -p debian/tmp/etc/nginx/sites-available + cp -r `ls | grep -v git | grep -v debian` .bundle $(inst_dir)/ + cp config/gitlab.nginx debian/tmp/etc/nginx/sites-available/gitlab + dh_install + +override_dh_shlibdeps: + echo "Ignored, moving on"