Commit be942d74 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #2051 from gitlabhq/namespaces

User/Group namespaces for projects
parents 5f7dc99a 1d7fdf45
......@@ -139,7 +139,7 @@ group :development, :test do
gem 'rb-inotify', require: linux_only('rb-inotify')
# PhantomJS driver for Capybara
gem 'poltergeist'
gem 'poltergeist', git: 'https://github.com/jonleighton/poltergeist.git', ref: '5c2e092001074a8cf09f332d3714e9ba150bc8ca'
end
group :test do
......
......@@ -59,6 +59,18 @@ GIT
specs:
yaml_db (0.2.2)
GIT
remote: https://github.com/jonleighton/poltergeist.git
revision: 5c2e092001074a8cf09f332d3714e9ba150bc8ca
ref: 5c2e092001074a8cf09f332d3714e9ba150bc8ca
specs:
poltergeist (1.0.2)
capybara (~> 1.1)
childprocess (~> 0.3)
faye-websocket (~> 0.4, >= 0.4.4)
http_parser.rb (~> 0.5.3)
multi_json (~> 1.0)
GEM
remote: http://rubygems.org/
specs:
......@@ -279,12 +291,6 @@ GEM
omniauth-oauth (~> 1.0)
orm_adapter (0.4.0)
pg (0.14.1)
poltergeist (1.0.2)
capybara (~> 1.1)
childprocess (~> 0.3)
faye-websocket (~> 0.4, >= 0.4.4)
http_parser.rb (~> 0.5.3)
multi_json (~> 1.0)
polyglot (0.3.3)
posix-spawn (0.3.6)
pry (0.9.10)
......@@ -490,7 +496,7 @@ DEPENDENCIES
omniauth-ldap!
omniauth-twitter
pg
poltergeist
poltergeist!
pry
pygments.rb!
quiet_assets (~> 1.0.1)
......
......@@ -77,3 +77,7 @@ a {
a:focus {
outline: none;
}
.monospace {
font-family: 'Menlo', 'Liberation Mono', 'Consolas', 'Courier New', 'andale mono','lucida console',monospace;
}
......@@ -48,15 +48,17 @@ class Admin::GroupsController < AdminController
def project_update
project_ids = params[:project_ids]
Project.where(id: project_ids).update_all(group_id: @group.id)
Project.where(id: project_ids).each do |project|
project.transfer(@group)
end
redirect_to :back, notice: 'Group was successfully updated.'
end
def remove_project
@project = Project.find(params[:project_id])
@project.group_id = nil
@project.save
@project.transfer(nil)
redirect_to :back, notice: 'Group was successfully updated.'
end
......@@ -70,6 +72,6 @@ class Admin::GroupsController < AdminController
private
def group
@group = Group.find_by_code(params[:id])
@group = Group.find_by_path(params[:id])
end
end
class Admin::ProjectsController < AdminController
before_filter :admin_project, only: [:edit, :show, :update, :destroy, :team_update]
before_filter :project, only: [:edit, :show, :update, :destroy, :team_update]
def index
@admin_projects = Project.scoped
@admin_projects = @admin_projects.search(params[:name]) if params[:name].present?
@admin_projects = @admin_projects.order("name ASC").page(params[:page]).per(20)
@projects = Project.scoped
@projects = @projects.where(namespace_id: params[:namespace_id]) if params[:namespace_id].present?
@projects = @projects.search(params[:name]) if params[:name].present?
@projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20)
end
def show
@users = User.scoped
@users = @users.not_in_project(@admin_project) if @admin_project.users.present?
@users = @users.not_in_project(@project) if @project.users.present?
@users = @users.all
end
def new
@admin_project = Project.new
end
def edit
end
def team_update
@admin_project.add_users_ids_to_team(params[:user_ids], params[:project_access])
redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
end
@project.add_users_ids_to_team(params[:user_ids], params[:project_access])
def create
@admin_project = Project.new(params[:project])
@admin_project.owner = current_user
if @admin_project.save
redirect_to [:admin, @admin_project], notice: 'Project was successfully created.'
else
render action: "new"
end
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
end
def update
owner_id = params[:project].delete(:owner_id)
if owner_id
@admin_project.owner = User.find(owner_id)
@project.owner = User.find(owner_id)
end
if @admin_project.update_attributes(params[:project])
redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
if @project.update_attributes(params[:project], as: :admin)
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
else
render action: "edit"
end
end
def destroy
@admin_project.destroy
@project.destroy
redirect_to admin_projects_url, notice: 'Project was successfully deleted.'
redirect_to projects_url, notice: 'Project was successfully deleted.'
end
private
protected
def project
id = params[:project_id] || params[:id]
def admin_project
@admin_project = Project.find_by_code(params[:id])
@project = Project.find_with_namespace(id)
@project || render_404
end
end
......@@ -63,7 +63,9 @@ class ApplicationController < ActionController::Base
end
def project
@project ||= current_user.projects.find_by_code(params[:project_id] || params[:id])
id = params[:project_id] || params[:id]
@project ||= current_user.projects.find_with_namespace(id)
@project || render_404
end
......
......@@ -4,7 +4,7 @@ class DashboardController < ApplicationController
before_filter :event_filter, only: :index
def index
@groups = Group.where(id: current_user.projects.pluck(:group_id))
@groups = Group.where(id: current_user.projects.pluck(:namespace_id))
@projects = current_user.projects_sorted_by_activity
@projects = @projects.page(params[:page]).per(30)
......
......@@ -4,6 +4,7 @@ class GroupsController < ApplicationController
before_filter :group
before_filter :projects
before_filter :add_project_abilities
def show
@events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0)
......@@ -50,11 +51,11 @@ class GroupsController < ApplicationController
protected
def group
@group ||= Group.find_by_code(params[:id])
@group ||= Group.find_by_path(params[:id])
end
def projects
@projects ||= current_user.projects_sorted_by_activity.where(group_id: @group.id)
@projects ||= current_user.projects_sorted_by_activity.where(namespace_id: @group.id)
end
def project_ids
......
......@@ -34,8 +34,16 @@ class ProjectsController < ProjectResourceController
end
def update
namespace_id = params[:project].delete(:namespace_id)
if namespace_id
namespace = Namespace.find(namespace_id)
project.transfer(namespace)
end
respond_to do |format|
if project.update_attributes(params[:project])
flash[:notice] = 'Project was successfully updated.'
format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' }
format.js
else
......
......@@ -74,6 +74,27 @@ module ApplicationHelper
grouped_options_for_select(options, @ref || @project.default_branch)
end
def namespaces_options(selected = :current_user, scope = :default)
groups = current_user.namespaces.select {|n| n.type == 'Group'}
users = if scope == :all
Namespace.root
else
current_user.namespaces.reject {|n| n.type == 'Group'}
end
options = [
["Groups", groups.map {|g| [g.human_name, g.id]} ],
[ "Users", users.map {|u| [u.human_name, u.id]} ]
]
if selected == :current_user && current_user.namespace
selected = current_user.namespace.id
end
grouped_options_for_select(options, selected)
end
def search_autocomplete_source
projects = current_user.projects.map{ |p| { label: p.name, url: project_path(p) } }
......
......@@ -7,6 +7,7 @@ class Ability
when "Note" then note_abilities(object, subject)
when "Snippet" then snippet_abilities(object, subject)
when "MergeRequest" then merge_request_abilities(object, subject)
when "Group" then group_abilities(object, subject)
else []
end
end
......@@ -61,6 +62,16 @@ class Ability
rules.flatten
end
def group_abilities user, group
rules = []
rules << [
:manage_group
] if group.owner == user
rules.flatten
end
[:issue, :note, :snippet, :merge_request].each do |name|
define_method "#{name}_abilities" do |user, subject|
if subject.author == user
......
# == Schema Information
#
# Table name: groups
# Table name: namespaces
#
# id :integer not null, primary key
# name :string(255) not null
# code :string(255) not null
# path :string(255) not null
# owner_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255)
#
class Group < ActiveRecord::Base
attr_accessible :code, :name, :owner_id
has_many :projects
belongs_to :owner, class_name: "User"
validates :name, presence: true, uniqueness: true
validates :code, presence: true, uniqueness: true
validates :owner, presence: true
delegate :name, to: :owner, allow_nil: true, prefix: true
def self.search query
where("name LIKE :query OR code LIKE :query", query: "%#{query}%")
end
def to_param
code
end
class Group < Namespace
def users
User.joins(:users_projects).where(users_projects: {project_id: project_ids}).uniq
end
def human_name
name
end
end
# == Schema Information
#
# Table name: namespaces
#
# id :integer not null, primary key
# name :string(255) not null
# path :string(255) not null
# owner_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255)
#
class Namespace < ActiveRecord::Base
attr_accessible :name, :path
has_many :projects, dependent: :destroy
belongs_to :owner, class_name: "User"
validates :name, presence: true, uniqueness: true
validates :path, uniqueness: true, presence: true, length: { within: 1..255 },
format: { with: /\A[a-zA-Z][a-zA-Z0-9_\-\.]*\z/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :owner, presence: true
delegate :name, to: :owner, allow_nil: true, prefix: true
after_create :ensure_dir_exist
after_update :move_dir
scope :root, where('type IS NULL')
def self.search query
where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
end
def to_param
path
end
def human_name
owner_name
end
def ensure_dir_exist
namespace_dir_path = File.join(Gitlab.config.git_base_path, path)
Dir.mkdir(namespace_dir_path) unless File.exists?(namespace_dir_path)
end
def move_dir
old_path = File.join(Gitlab.config.git_base_path, path_was)
new_path = File.join(Gitlab.config.git_base_path, path)
system("mv #{old_path} #{new_path}")
end
end
......@@ -9,14 +9,13 @@
# created_at :datetime not null
# updated_at :datetime not null
# private_flag :boolean default(TRUE), not null
# code :string(255)
# owner_id :integer
# default_branch :string(255)
# issues_enabled :boolean default(TRUE), not null
# wall_enabled :boolean default(TRUE), not null
# merge_requests_enabled :boolean default(TRUE), not null
# wiki_enabled :boolean default(TRUE), not null
# group_id :integer
# namespace_id :integer
#
require "grit"
......@@ -27,12 +26,16 @@ class Project < ActiveRecord::Base
include Authority
include Team
attr_accessible :name, :path, :description, :code, :default_branch, :issues_enabled,
:wall_enabled, :merge_requests_enabled, :wiki_enabled
attr_accessible :name, :path, :description, :default_branch, :issues_enabled,
:wall_enabled, :merge_requests_enabled, :wiki_enabled, as: [:default, :admin]
attr_accessible :namespace_id, as: :admin
attr_accessor :error_code
# Relations
belongs_to :group
belongs_to :group, foreign_key: "namespace_id", conditions: "type = 'Group'"
belongs_to :namespace
belongs_to :owner, class_name: "User"
has_many :users, through: :users_projects
has_many :events, dependent: :destroy
......@@ -54,15 +57,16 @@ class Project < ActiveRecord::Base
# Validations
validates :owner, presence: true
validates :description, length: { within: 0..2000 }
validates :name, uniqueness: true, presence: true, length: { within: 0..255 }
validates :path, uniqueness: true, presence: true, length: { within: 0..255 },
format: { with: /\A[a-zA-Z][a-zA-Z0-9_\-\.]*\z/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :code, presence: true, uniqueness: true, length: { within: 1..255 },
validates :name, presence: true, length: { within: 0..255 }
validates :path, presence: true, length: { within: 0..255 },
format: { with: /\A[a-zA-Z][a-zA-Z0-9_\-\.]*\z/,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :issues_enabled, :wall_enabled, :merge_requests_enabled,
:wiki_enabled, inclusion: { in: [true, false] }
validates_uniqueness_of :name, scope: :namespace_id
validates_uniqueness_of :path, scope: :namespace_id
validate :check_limit, :repo_name
# Scopes
......@@ -76,14 +80,46 @@ class Project < ActiveRecord::Base
end
def search query
where("name LIKE :query OR code LIKE :query OR path LIKE :query", query: "%#{query}%")
where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%")
end
def find_with_namespace(id)
if id.include?("/")
id = id.split("/")
namespace_id = Namespace.find_by_path(id.first).id
where(namespace_id: namespace_id).find_by_path(id.last)
else
find_by_path(id)
end
end
def create_by_user(params, user)
namespace_id = params.delete(:namespace_id)
project = Project.new params
Project.transaction do
# Parametrize path for project
#
# Ex.
# 'GitLab HQ'.parameterize => "gitlab-hq"
#
project.path = project.name.dup.parameterize
project.owner = user
# Apply namespace if user has access to it
# else fallback to user namespace
project.namespace_id = user.namespace_id
if namespace_id
group = Group.find_by_id(namespace_id)
if user.can? :manage_group, group
project.namespace_id = namespace_id
end
end
project.save!
# Add user as project master
......@@ -134,11 +170,15 @@ class Project < ActiveRecord::Base
end
def to_param
code
if namespace
namespace.path + "/" + path
else
path
end
end
def web_url
[Gitlab.config.url, code].join("/")
[Gitlab.config.url, path].join("/")
end
def common_notes
......@@ -192,4 +232,31 @@ class Project < ActiveRecord::Base
def gitlab_ci?
gitlab_ci_service && gitlab_ci_service.active
end
def path_with_namespace
if namespace
namespace.path + '/' + path
else
path
end
end
# For compatibility with old code
def code
path
end
def transfer(new_namespace)
Project.transaction do
old_namespace = namespace
self.namespace = new_namespace
old_dir = old_namespace.try(:path) || ''
new_dir = new_namespace.try(:path) || ''
Gitlab::ProjectMover.new(self, old_dir, new_dir).execute
save!
end
end
end
......@@ -30,6 +30,7 @@
# locked_at :datetime
# extern_uid :string(255)
# provider :string(255)
# username :string(255)
#
class User < ActiveRecord::Base
......@@ -38,13 +39,17 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :token_authenticatable, :lockable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name,
attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username,
:skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password,
:extern_uid, :provider, :as => [:default, :admin]
attr_accessible :projects_limit, :as => :admin
attr_accessor :force_random_password
# Namespace for personal projects
has_one :namespace, class_name: "Namespace", foreign_key: :owner_id, conditions: 'type IS NULL', dependent: :destroy
has_many :groups, class_name: "Group", foreign_key: :owner_id
has_many :keys, dependent: :destroy
has_many :projects, through: :users_projects
has_many :users_projects, dependent: :destroy
......@@ -60,11 +65,14 @@ class User < ActiveRecord::Base
validates :bio, length: { within: 0..255 }
validates :extern_uid, :allow_blank => true, :uniqueness => {:scope => :provider}
validates :projects_limit, presence: true, numericality: {greater_than_or_equal_to: 0}
validates :username, presence: true
before_validation :generate_password, on: :create
before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token
delegate :path, to: :namespace, allow_nil: true, prefix: true
# Scopes
scope :not_in_project, ->(project) { where("id not in (:ids)", ids: project.users.map(&:id) ) }
scope :admins, where(admin: true)
......
......@@ -3,7 +3,7 @@ class IssueObserver < ActiveRecord::Observer
def after_create(issue)
if issue.assignee && issue.assignee != current_user
Notify.new_issue_email(issue.id).deliver
Notify.new_issue_email(issue.id).deliver
end
end
......@@ -14,8 +14,8 @@ class IssueObserver < ActiveRecord::Observer
status = 'closed' if issue.is_being_closed?
status = 'reopened' if issue.is_being_reopened?
if status
Note.create_status_change_note(issue, current_user, status)
[issue.author, issue.assignee].compact.each do |recipient|
Note.create_status_change_note(issue, current_user, status)
[issue.author, issue.assignee].compact.each do |recipient|
Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user)
end
end
......
class UserObserver < ActiveRecord::Observer
def after_create(user)
user.create_namespace(path: user.username, name: user.name)
log_info("User \"#{user.name}\" (#{user.email}) was created")
Notify.new_user_email(user.id, user.password).deliver
......@@ -9,6 +11,16 @@ class UserObserver < ActiveRecord::Observer
log_info("User \"#{user.name}\" (#{user.email}) was removed")
end
def after_save user
if user.username_changed?
if user.namespace
user.namespace.update_attributes(path: user.username)
else
user.create_namespace!(path: user.username, name: user.name)
end
end
end
protected
def log_info message
......
......@@ -26,6 +26,18 @@ module Account
is_admin?
end
def abilities
@abilities ||= begin
abilities = Six.new
abilities << Ability
abilities
end
end
def can? action, subject
abilities.allowed?(self, action, subject)
end
def last_activity_project
projects.first
end
......@@ -70,4 +82,27 @@ module Account
def projects_sorted_by_activity
projects.order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC")
end
def namespaces
namespaces = []
# Add user account namespace
namespaces << self.namespace if self.namespace
# Add groups you can manage
namespaces += if admin
Group.all
else
groups.all
end
namespaces
end
def several_namespaces?
namespaces.size > 1
end
def namespace_id
namespace.try :id
end
end
......@@ -114,7 +114,7 @@ module PushObserver
id: commit.id,
message: commit.safe_message,
timestamp: commit.date.xmlschema,
url: "#{Gitlab.config.url}/#{code}/commits/#{commit.id}",
url: "#{Gitlab.config.url}/#{path}/commits/#{commit.id}",
author: {
name: commit.author_name,
email: commit.author_email
......
......@@ -79,11 +79,15 @@ module Repository
end
def url_to_repo
git_host.url_to_repo(path)
git_host.url_to_repo(path_with_namespace)
end
def path_to_repo
File.join(Gitlab.config.git_base_path, "#{path}.git")
File.join(Gitlab.config.git_base_path, namespace_dir, "#{path}.git")
end
def namespace_dir
namespace.try(:path) || ''
end
def update_repository
......@@ -160,12 +164,12 @@ module Repository
return nil unless commit
# Build file path
file_name = self.code + "-" + commit.id.to_s + ".tar.gz"
storage_path = Rails.root.join("tmp", "repositories", self.code)
file_name = self.path + "-" + commit.id.to_s + ".tar.gz"
storage_path = Rails.root.join("tmp", "repositories", self.path)
file_path = File.join(storage_path, file_name)
# Put files into a directory before archiving
prefix = self.code + "/"
prefix = self.path + "/"
# Create file if not exists
unless File.exists?(file_path)
......
......@@ -27,7 +27,7 @@
= link_to admin_projects_path do
%h1= Project.count
%hr
= link_to 'New Project', new_admin_project_path, class: "btn small"
= link_to 'New Project', new_project_path, class: "btn small"
.span4
.ui-box
%h5 Users
......
......@@ -8,12 +8,12 @@
.input
= f.text_field :name, placeholder: "Example Group", class: "xxlarge"
.clearfix
= f.label :code do
= f.label :path do
URL
.input
.input-prepend
%span.add-on= web_app_url + 'groups/'
= f.text_field :code, placeholder: "example"
= f.text_field :path, placeholder: "example"
.form-actions
= f.submit 'Save group', class: "btn save-btn"
......@@ -14,7 +14,7 @@
%table
%thead
%th Name
%th Code
%th Path
%th Projects
%th Edit
%th.cred Danger Zone!
......@@ -22,7 +22,7 @@
- @groups.each do |group|
%tr
%td= link_to group.name, [:admin, group]
%td= group.code
%td= group.path
%td= group.projects.count
%td= link_to 'Edit', edit_admin_group_path(group), id: "edit_#{dom_id(group)}", class: "btn small"
%td.bgred= link_to 'Destroy', [:admin, group], confirm: "REMOVE #{group.name}? Are you sure?", method: :delete, class: "btn small danger"
......
......@@ -20,9 +20,9 @@
%tr
%td
%b
Code:
Path:
%td
= @group.code
= @group.path
%tr
%td
%b
......
......@@ -11,25 +11,19 @@
.input
= f.text_field :name, placeholder: "Example Project", class: "xxlarge"
%hr
.adv_settings
%h6 Advanced settings:
%fieldset.adv_settings
%legend Advanced settings:
.clearfix
= f.label :path do
Path
.input
.input-prepend
%strong
= text_field_tag :ppath, @admin_project.path_to_repo, class: "xlarge", disabled: true
.clearfix
= f.label :code do
URL
.input
.input-prepend
%span.add-on= web_app_url
= f.text_field :code, placeholder: "example"
= text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true
- unless project.new_record?
.clearfix
= f.label :namespace_id
.input= f.select :namespace_id, namespaces_options, {}, {class: 'chosen'}
.clearfix
= f.label :owner_id
.input= f.select :owner_id, User.all.map { |user| [user.name, user.id] }, {}, {class: 'chosen'}
......@@ -40,9 +34,8 @@
.input= f.select(:default_branch, project.heads.map(&:name), {}, style: "width:210px;")
- unless project.new_record?
%hr
.adv_settings
%h6 Features:
%fieldset.adv_settings
%legend Features:
.clearfix
= f.label :issues_enabled, "Issues"
......
= form_for [:admin, @admin_project] do |f|
- if @admin_project.errors.any?
.alert-message.block-message.error
%span= @admin_project.errors.full_messages.first
.clearfix.project_name_holder
= f.label :name do
Project name is
.input
= f.text_field :name, placeholder: "Example Project", class: "xxlarge"
= f.submit 'Create project', class: "btn primary project-submit"
%hr
%div.adv_settings
%h6 Advanced settings:
.clearfix
= f.label :path do
Git Clone
.input
.input-prepend
%span.add-on= Gitlab.config.ssh_path
= f.text_field :path, placeholder: "example_project", disabled: !@admin_project.new_record?
%span.add-on= ".git"
.clearfix
= f.label :code do
URL
.input
.input-prepend
%span.add-on= web_app_url
= f.text_field :code, placeholder: "example"
%h3.page_title #{@admin_project.name} &rarr; Edit project
%h3.page_title #{@project.name} &rarr; Edit project
%hr
= render 'form', project: @admin_project
= render 'form', project: @project
= render 'admin/shared/projects_head'
%h3.page_title
Projects
= link_to 'New Project', new_admin_project_path, class: "btn small right"
= link_to 'New Project', new_project_path, class: "btn small right"
%br
= form_tag admin_projects_path, method: :get, class: 'form-inline' do
= select_tag :namespace_id, namespaces_options(params[:namespace_id], :all), class: "chosen xlarge", include_blank: true
= text_field_tag :name, params[:name], class: "xlarge"
= submit_tag "Search", class: "btn submit primary"
%table
%thead
%th Name
%th Path
%th Project
%th Team Members
%th Last Commit
%th Edit
%th.cred Danger Zone!
- @admin_projects.each do |project|
- @projects.each do |project|
%tr
%td= link_to project.name, [:admin, project]
%td= project.path
%td
- if project.namespace
= link_to project.namespace.human_name, [:admin, project]
&rarr;
= link_to project.name, [:admin, project]
%td
%span.monospace= project.path_with_namespace + ".git"
%td= project.users_projects.count
%td= last_commit(project)
%td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small"
%td.bgred= link_to 'Destroy', [:admin, project], confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn small danger"
= paginate @admin_projects, theme: "admin"
= paginate @projects, theme: "admin"
.project_new_holder
%h3.page_title
New Project
%hr
= render 'new_form'
%div.save-project-loader.hide
%center
= image_tag "ajax_loader.gif"
%h3 Creating project &amp; repository. Please wait a few minutes
:javascript
$(function(){ new Projects(); });
= render 'admin/shared/projects_head'
%h3.page_title
Project: #{@admin_project.name}
= link_to edit_admin_project_path(@admin_project), class: "btn right" do
Project: #{@project.name}
= link_to edit_admin_project_path(@project), class: "btn right" do
%i.icon-edit
Edit
- if !@admin_project.has_post_receive_file? && @admin_project.has_commits?
- if !@project.has_post_receive_file? && @project.has_commits?
%br
.alert.alert-error
%span
......@@ -25,36 +25,30 @@
%b
Name:
%td
= @admin_project.name
%tr
%td
%b
Code:
%td
= @admin_project.code
= @project.name
%tr
%td
%b
Path:
%td
= @admin_project.path
%code= @project.path_to_repo
%tr
%td
%b
Owner:
%td
= @admin_project.owner_name || '(deleted)'
= @project.owner_name || '(deleted)'
%tr
%td
%b
Post Receive File:
%td
= check_box_tag :post_receive_file, 1, @admin_project.has_post_receive_file?, disabled: true
= check_box_tag :post_receive_file, 1, @project.has_post_receive_file?, disabled: true
%br
%h3
Team
%small
(#{@admin_project.users_projects.count})
(#{@project.users_projects.count})
%br
%table.zebra-striped
%thead
......@@ -64,7 +58,7 @@
%th Repository Access
%th
- @admin_project.users_projects.each do |tm|
- @project.users_projects.each do |tm|
%tr
%td
= link_to tm.user_name, admin_user_path(tm.user)
......@@ -75,7 +69,7 @@
%br
%h3 Add new team member
%br
= form_tag team_update_admin_project_path(@admin_project), class: "bulk_import", method: :put do
= form_tag team_update_admin_project_path(@project), class: "bulk_import", method: :put do
%table.zebra-striped
%thead
%tr
......
......@@ -15,6 +15,11 @@
.input
= f.text_field :name
%span.help-inline * required
.clearfix
= f.label :username
.input
= f.text_field :username
%span.help-inline * required
.clearfix
= f.label :email
.input
......@@ -26,11 +31,11 @@
= f.label :force_random_password do
%span Generate random password
.input= f.check_box :force_random_password, {}, true, nil
%div.password-fields
.clearfix
= f.label :password
.input= f.password_field :password, disabled: f.object.force_random_password
.input= f.password_field :password, disabled: f.object.force_random_password
.clearfix
= f.label :password_confirmation
.input= f.password_field :password_confirmation, disabled: f.object.force_random_password
......
......@@ -11,7 +11,7 @@
%ul.unstyled
- groups.each do |group|
%li.wll
= link_to group_path(id: group.code), class: dom_class(group) do
= link_to group_path(id: group.path), class: dom_class(group) do
%strong.group_name= truncate(group.name, length: 25)
%span.arrow
&rarr;
......
......@@ -12,7 +12,11 @@
- projects.each do |project|
%li.wll
= link_to project_path(project), class: dom_class(project) do
%strong.project_name= truncate(project.name, length: 25)
- if project.namespace
= project.namespace.human_name
\/
%strong.project_name
= truncate(project.name, length: 25)
%span.arrow
&rarr;
%span.last_activity
......
......@@ -3,6 +3,11 @@
Projects
%small
(#{projects.count})
- if can? current_user, :manage_group, @group
%span.right
= link_to new_project_path(namespace_id: @group.id), class: "btn very_small info" do
%i.icon-plus
New Project
%ul.unstyled
- projects.each do |project|
%li.wll
......
......@@ -9,4 +9,6 @@
= image_tag gravatar_icon(user.email, 16), class: "avatar s16"
%strong= user.name
%span.cgray= user.email
- if @group.owner == user
%span.btn.btn-small.disabled.right Owner
:javascript
$(function() {
GitLab.GfmAutoComplete.Members.url = "#{ "/api/v2/projects/#{@project.code}/members" if @project }";
GitLab.GfmAutoComplete.Members.url = "#{ "/api/v2/projects/#{@project.path}/members" if @project }";
GitLab.GfmAutoComplete.Members.params.private_token = "#{current_user.private_token}";
GitLab.GfmAutoComplete.Emoji.data = #{raw emoji_autocomplete_source};
......
......@@ -7,7 +7,7 @@
.container
%ul.main_menu
= nav_link(html_options: {class: "home #{project_tab_class}"}) do
= link_to @project.code, project_path(@project), title: "Project"
= link_to @project.path, project_path(@project), title: "Project"
- if @project.repo_exists?
- if can? current_user, :download_code, @project
......
......@@ -8,6 +8,7 @@
= link_to authbutton(provider, 32), omniauth_authorize_path(User, provider)
%fieldset
%legend
Private token
......@@ -44,11 +45,25 @@
.input= f.password_field :password
.clearfix
= f.label :password_confirmation
.input= f.password_field :password_confirmation
.actions
= f.submit 'Save', class: "btn save-btn"
.input
= f.password_field :password_confirmation
.clearfix
.input
= f.submit 'Save password', class: "btn save-btn"
%fieldset
%legend
Username
%small.right
Changing your username can have unintended side effects!
= form_for @user, url: profile_update_path, method: :put do |f|
.padded
= f.label :username
.input
= f.text_field :username
.input
= f.submit 'Save username', class: "btn save-btn"
......@@ -9,48 +9,45 @@
Project name is
.input
= f.text_field :name, placeholder: "Example Project", class: "xxlarge"
%fieldset
%legend Advanced settings:
.clearfix
.control-group
= f.label :path do
Path
.input
.input-prepend
%strong
= text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true
.clearfix
= f.label :code do
URL
.input
.input-prepend
%span.add-on= web_app_url
= f.text_field :code, placeholder: "example"
- unless @project.new_record? || @project.heads.empty?
.controls
= text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true
.control-group
= f.label :namespace_id do
%span Namespace
.controls
= f.select :namespace_id, namespaces_options(@project.namespace_id), {}, {class: 'chosen'}
&nbsp;
%span.cred Be careful. Changing project namespace can have unintended side effects
- unless @project.heads.empty?
.clearfix
= f.label :default_branch, "Default Branch"
.input= f.select(:default_branch, @project.heads.map(&:name), {}, style: "width:210px;")
- unless @project.new_record?
%fieldset
%legend Features:
%fieldset
%legend Features:
.clearfix
= f.label :issues_enabled, "Issues"
.input= f.check_box :issues_enabled
.clearfix
= f.label :issues_enabled, "Issues"
.input= f.check_box :issues_enabled
.clearfix
= f.label :merge_requests_enabled, "Merge Requests"
.input= f.check_box :merge_requests_enabled
.clearfix
= f.label :merge_requests_enabled, "Merge Requests"
.input= f.check_box :merge_requests_enabled
.clearfix
= f.label :wall_enabled, "Wall"
.input= f.check_box :wall_enabled
.clearfix
= f.label :wall_enabled, "Wall"
.input= f.check_box :wall_enabled
.clearfix
= f.label :wiki_enabled, "Wiki"
.input= f.check_box :wiki_enabled
.clearfix
= f.label :wiki_enabled, "Wiki"
.input= f.check_box :wiki_enabled
%br
......
......@@ -9,21 +9,12 @@
= f.text_field :name, placeholder: "Example Project", class: "xxlarge"
= f.submit 'Create project', class: "btn primary project-submit"
%hr
%div.adv_settings
%h6 Advanced settings:
.clearfix
= f.label :path do
Git Clone
.input
.input-prepend
%span.add-on= Gitlab.config.ssh_path
= f.text_field :path, placeholder: "example_project", disabled: !@project.new_record?
%span.add-on= ".git"
- if current_user.several_namespaces?
.clearfix
= f.label :code do
URL
= f.label :namespace_id do
%span.cgray Namespace
.input
.input-prepend
%span.add-on= web_app_url
= f.text_field :code, placeholder: "example"
= f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user), {}, {class: 'chosen'}
%hr
%p.padded
All created project are private. You choose who can see project and commit to repository.
- if @project.valid?
:plain
location.href = "#{edit_project_path(@project, notice: 'Project was successfully updated.')}";
location.href = "#{edit_project_path(@project)}";
- else
:plain
$('.project_edit_holder').show();
......
......@@ -15,8 +15,12 @@
%span.options
= link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn very_small", target: "_blank"
.file_content.code
%div{class: current_user.dark_scheme ? "black" : ""}
= raw @snippet.colorize(options: { linenos: 'True'})
- unless @snippet.content.empty?
%div{class: current_user.dark_scheme ? "black" : "white"}
= preserve do
= raw Pygments.highlight(@snippet.content, formatter: :gitlab)
- else
%h4.nothing_here_message Empty file
%div
......
......@@ -18,7 +18,7 @@ Gitlab::Application.routes.draw do
project_root: Gitlab.config.git_base_path,
upload_pack: Gitlab.config.git_upload_pack,
receive_pack: Gitlab.config.git_receive_pack
}), at: '/:path', constraints: { path: /[\w\.-]+\.git/ }
}), at: '/:path', constraints: { path: /[-\/\w\.-]+\.git/ }
#
# Help
......@@ -49,7 +49,7 @@ Gitlab::Application.routes.draw do
delete :remove_project
end
end
resources :projects, constraints: { id: /[^\/]+/ } do
resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, except: [:new, :create] do
member do
get :team
put :team_update
......@@ -107,7 +107,7 @@ Gitlab::Application.routes.draw do
#
# Project Area
#
resources :projects, constraints: { id: /[^\/]+/ }, except: [:new, :create, :index], path: "/" do
resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, except: [:new, :create, :index], path: "/" do
member do
get "wall"
get "graph"
......
unless User.count > 0
admin = User.create(
:email => "admin@local.host",
:name => "Administrator",
:password => "5iveL!fe",
:password_confirmation => "5iveL!fe"
email: "admin@local.host",
name: "Administrator",
username: 'root',
password: "5iveL!fe",
password_confirmation: "5iveL!fe"
)
admin.projects_limit = 10000
......
Project.seed(:id, [
{ id: 1, name: "Underscore.js", path: "underscore", code: "underscore", owner_id: 1 },
{ id: 2, name: "Diaspora", path: "diaspora", code: "diaspora", owner_id: 1 },
{ id: 3, name: "Ruby on Rails", path: "rails", code: "rails", owner_id: 1 }
{ id: 1, name: "Underscore.js", path: "underscore", owner_id: 1 },
{ id: 2, name: "Diaspora", path: "diaspora", owner_id: 1 },
{ id: 3, name: "Ruby on Rails", path: "rails", owner_id: 1 }
])
User.seed(:id, [
{ :id => 2, :name => Faker::Internet.user_name, :email => Faker::Internet.email},
{ :id => 3, :name => Faker::Internet.user_name, :email => Faker::Internet.email},
{ :id => 4, :name => Faker::Internet.user_name, :email => Faker::Internet.email},
{ :id => 5, :name => Faker::Internet.user_name, :email => Faker::Internet.email},
{ :id => 6, :name => Faker::Internet.user_name, :email => Faker::Internet.email},
{ :id => 7, :name => Faker::Internet.user_name, :email => Faker::Internet.email},
{ :id => 8, :name => Faker::Internet.user_name, :email => Faker::Internet.email},
{ :id => 9, :name => Faker::Internet.user_name, :email => Faker::Internet.email}
{ id: 2, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},
{ id: 3, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},
{ id: 4, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},
{ id: 5, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},
{ id: 6, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},
{ id: 7, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},
{ id: 8, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},
{ id: 9, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email}
])
admin = User.create(
:email => "admin@local.host",
:name => "Administrator",
:password => "5iveL!fe",
:password_confirmation => "5iveL!fe"
email: "admin@local.host",
name: "Administrator",
username: 'root',
password: "5iveL!fe",
password_confirmation: "5iveL!fe"
)
admin.projects_limit = 10000
......
class ConvertGroupToNamespace < ActiveRecord::Migration
def up
rename_table 'groups', 'namespaces'
add_column :namespaces, :type, :string, null: true
# Migrate old groups
Namespace.update_all(type: 'Group')
end
def down
raise 'Rollback is not allowed'
end
end
class AddNamespaceIdToProject < ActiveRecord::Migration
def change
rename_column :projects, :group_id, :namespace_id
end
end
class AddUsernameToUser < ActiveRecord::Migration
def change
add_column :users, :username, :string, null: true
end
end
class RenameCodeToPath < ActiveRecord::Migration
def up
remove_column :projects, :code
rename_column :namespaces, :code, :path
end
def down
add_column :projects, :code, :string
rename_column :namespaces, :path, :code
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20121120113838) do
ActiveRecord::Schema.define(:version => 20121123164910) do
create_table "events", :force => true do |t|
t.string "target_type"
......@@ -25,14 +25,6 @@ ActiveRecord::Schema.define(:version => 20121120113838) do
t.integer "author_id"
end
create_table "groups", :force => true do |t|
t.string "name", :null => false
t.string "code", :null => false
t.integer "owner_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "issues", :force => true do |t|
t.string "title"
t.integer "assignee_id"
......@@ -88,6 +80,15 @@ ActiveRecord::Schema.define(:version => 20121120113838) do
t.datetime "updated_at", :null => false
end
create_table "namespaces", :force => true do |t|
t.string "name", :null => false
t.string "path", :null => false
t.integer "owner_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "type"
end
create_table "notes", :force => true do |t|
t.text "note"
t.string "noteable_id"
......@@ -110,14 +111,13 @@ ActiveRecord::Schema.define(:version => 20121120113838) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "private_flag", :default => true, :null => false
t.string "code"
t.integer "owner_id"
t.string "default_branch"
t.boolean "issues_enabled", :default => true, :null => false
t.boolean "wall_enabled", :default => true, :null => false
t.boolean "merge_requests_enabled", :default => true, :null => false
t.boolean "wiki_enabled", :default => true, :null => false
t.integer "group_id"
t.integer "namespace_id"
end
create_table "protected_branches", :force => true do |t|
......@@ -194,6 +194,7 @@ ActiveRecord::Schema.define(:version => 20121120113838) do
t.datetime "locked_at"
t.string "extern_uid"
t.string "provider"
t.string "username"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
......
......@@ -57,13 +57,14 @@ Feature: Project Issues
Then I should see "Release 0.3" in issues
And I should not see "Release 0.4" in issues
@javascript
Scenario: I clear search
Given I click link "All"
And I fill in issue search with "Something"
And I fill in issue search with ""
Then I should see "Release 0.4" in issues
And I should see "Release 0.3" in issues
# TODO: find out solution for poltergeist/phantomjs or remove
# @javascript
# Scenario: I clear search
# Given I click link "All"
# And I fill in issue search with "Something"
# And I fill in issue search with ""
# Then I should see "Release 0.4" in issues
# And I should see "Release 0.3" in issues
@javascript
Scenario: I create Issue with pre-selected milestone
......
......@@ -9,7 +9,7 @@ class AdminGroups < Spinach::FeatureSteps
And 'submit form with new group info' do
fill_in 'group_name', :with => 'gitlab'
fill_in 'group_code', :with => 'gitlab'
fill_in 'group_path', :with => 'gitlab'
click_button "Save group"
end
......
......@@ -4,8 +4,6 @@ class CreateProject < Spinach::FeatureSteps
And 'fill project form with valid data' do
fill_in 'project_name', :with => 'NewProject'
fill_in 'project_code', :with => 'NPR'
fill_in 'project_path', :with => 'newproject'
click_button "Create project"
end
......
......@@ -73,7 +73,6 @@ class ProjectIssues < Spinach::FeatureSteps
end
And 'I fill in issue search with ""' do
page.execute_script("$('.issue_search').val('').keyup();");
fill_in 'issue_search', with: ""
end
......
......@@ -5,7 +5,7 @@ require 'rspec'
require 'database_cleaner'
require 'spinach/capybara'
%w(gitolite_stub stubbed_repository valid_commit).each do |f|
%w(namespaces_stub gitolite_stub stubbed_repository valid_commit).each do |f|
require Rails.root.join('spec', 'support', f)
end
......
......@@ -6,7 +6,7 @@ module Gitlab
def user_project
if @project ||= current_user.projects.find_by_id(params[:id]) ||
current_user.projects.find_by_code(params[:id])
current_user.projects.find_by_path(params[:id])
else
not_found!
end
......
......@@ -38,11 +38,7 @@ module Gitlab
# Example Request
# POST /projects
post do
params[:code] ||= params[:name]
params[:path] ||= params[:name]
attrs = attributes_for_keys [:code,
:path,
:name,
attrs = attributes_for_keys [:name,
:description,
:default_branch,
:issues_enabled,
......
......@@ -38,7 +38,7 @@ module Gitlab
# POST /users
post do
authenticated_as_admin!
attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit]
attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username]
user = User.new attrs, as: :admin
if user.save
present user, with: Entities::User
......
......@@ -34,6 +34,7 @@ module Gitlab
extern_uid: uid,
provider: provider,
name: name,
username: email.match(/^[^@]*/)[0],
email: email,
password: password,
password_confirmation: password,
......
......@@ -126,7 +126,7 @@ module Gitlab
end
def update_project_config(project, conf)
repo_name = project.path
repo_name = project.path_with_namespace
repo = if conf.has_repo?(repo_name)
conf.get_repo(repo_name)
......
# ProjectMover class
#
# Used for moving project repositories from one subdir to another
module Gitlab
class ProjectMover
class ProjectMoveError < StandardError; end
attr_reader :project, :old_dir, :new_dir
def initialize(project, old_dir, new_dir)
@project = project
@old_dir = old_dir
@new_dir = new_dir
end
def execute
# Create new dir if missing
new_dir_path = File.join(Gitlab.config.git_base_path, new_dir)
Dir.mkdir(new_dir_path) unless File.exists?(new_dir_path)
old_path = File.join(Gitlab.config.git_base_path, old_dir, "#{project.path}.git")
new_path = File.join(new_dir_path, "#{project.path}.git")
if system("mv #{old_path} #{new_path}")
log_info "Project #{project.name} was moved from #{old_path} to #{new_path}"
true
else
message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
log_info "Error! #{message}"
raise ProjectMoveError.new(message)
false
end
end
protected
def log_info message
Gitlab::AppLogger.info message
end
end
end
namespace :gitlab do
desc "GITLAB | Enable usernames and namespaces for user projects"
task activate_namespaces: :environment do
User.find_each(batch_size: 500) do |user|
next if user.namespace
User.transaction do
username = user.email.match(/^[^@]*/)[0]
if user.update_attributes!(username: username)
print '.'.green
else
print 'F'.red
end
end
end
end
end
......@@ -13,7 +13,7 @@ describe CommitsController do
describe "GET show" do
context "as atom feed" do
it "should render as atom" do
get :show, project_id: project.code, id: "master.atom"
get :show, project_id: project.path, id: "master.atom"
response.should be_success
response.content_type.should == 'application/atom+xml'
end
......
......@@ -12,6 +12,7 @@ FactoryGirl.define do
factory :user, aliases: [:author, :assignee, :owner] do
email { Faker::Internet.email }
name
username { Faker::Internet.user_name }
password "123456"
password_confirmation { password }
......@@ -25,13 +26,19 @@ FactoryGirl.define do
factory :project do
sequence(:name) { |n| "project#{n}" }
path { name.downcase.gsub(/\s/, '_') }
code { name.downcase.gsub(/\s/, '_') }
owner
end
factory :group do
sequence(:name) { |n| "group#{n}" }
code { name.downcase.gsub(/\s/, '_') }
path { name.downcase.gsub(/\s/, '_') }
owner
type 'Group'
end
factory :namespace do
sequence(:name) { |n| "group#{n}" }
path { name.downcase.gsub(/\s/, '_') }
owner
end
......
......@@ -169,9 +169,7 @@ describe Notify do
end
describe 'project access changed' do
let(:project) { create(:project,
path: "Fuu",
code: "Fuu") }
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:users_project) { create(:users_project,
project: project,
......
# == Schema Information
#
# Table name: groups
# Table name: namespaces
#
# id :integer not null, primary key
# name :string(255) not null
# code :string(255) not null
# path :string(255) not null
# owner_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255)
#
require 'spec_helper'
......@@ -18,7 +19,7 @@ describe Group do
it { should have_many :projects }
it { should validate_presence_of :name }
it { should validate_uniqueness_of(:name) }
it { should validate_presence_of :code }
it { should validate_uniqueness_of(:code) }
it { should validate_presence_of :path }
it { should validate_uniqueness_of(:path) }
it { should validate_presence_of :owner }
end
# == Schema Information
#
# Table name: namespaces
#
# id :integer not null, primary key
# name :string(255) not null
# path :string(255) not null
# owner_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# type :string(255)
#
require 'spec_helper'
describe Namespace do
let!(:namespace) { create(:namespace) }
it { should have_many :projects }
it { should validate_presence_of :name }
it { should validate_uniqueness_of(:name) }
it { should validate_presence_of :path }
it { should validate_uniqueness_of(:path) }
it { should validate_presence_of :owner }
describe "Mass assignment" do
it { should allow_mass_assignment_of(:name) }
it { should allow_mass_assignment_of(:path) }
end
describe "Respond to" do
it { should respond_to(:human_name) }
it { should respond_to(:to_param) }
end
end
......@@ -9,14 +9,13 @@
# created_at :datetime not null
# updated_at :datetime not null
# private_flag :boolean default(TRUE), not null
# code :string(255)
# owner_id :integer
# default_branch :string(255)
# issues_enabled :boolean default(TRUE), not null
# wall_enabled :boolean default(TRUE), not null
# merge_requests_enabled :boolean default(TRUE), not null
# wiki_enabled :boolean default(TRUE), not null
# group_id :integer
# namespace_id :integer
#
require 'spec_helper'
......@@ -24,6 +23,7 @@ require 'spec_helper'
describe Project do
describe "Associations" do
it { should belong_to(:group) }
it { should belong_to(:namespace) }
it { should belong_to(:owner).class_name('User') }
it { should have_many(:users) }
it { should have_many(:events).dependent(:destroy) }
......@@ -40,6 +40,7 @@ describe Project do
end
describe "Mass assignment" do
it { should_not allow_mass_assignment_of(:namespace_id) }
it { should_not allow_mass_assignment_of(:owner_id) }
it { should_not allow_mass_assignment_of(:private_flag) }
end
......@@ -58,9 +59,6 @@ describe Project do
it { should ensure_length_of(:description).is_within(0..2000) }
it { should validate_presence_of(:code) }
it { should validate_uniqueness_of(:code) }
it { should ensure_length_of(:code).is_within(1..255) }
# TODO: Formats
it { should validate_presence_of(:owner) }
......@@ -151,7 +149,7 @@ describe Project do
end
it "returns the full web URL for this repo" do
project = Project.new(code: "somewhere")
project = Project.new(path: "somewhere")
project.web_url.should == "#{Gitlab.config.url}/somewhere"
end
......@@ -162,7 +160,7 @@ describe Project do
end
it "should be invalid repo" do
project = Project.new(name: "ok_name", path: "/INVALID_PATH/", code: "NEOK")
project = Project.new(name: "ok_name", path: "/INVALID_PATH/", path: "NEOK")
project.valid_repo?.should be_false
end
end
......
......@@ -30,14 +30,17 @@
# locked_at :datetime
# extern_uid :string(255)
# provider :string(255)
# username :string(255)
#
require 'spec_helper'
describe User do
describe "Associations" do
it { should have_one(:namespace) }
it { should have_many(:users_projects).dependent(:destroy) }
it { should have_many(:projects) }
it { should have_many(:groups) }
it { should have_many(:my_own_projects).class_name('Project') }
it { should have_many(:keys).dependent(:destroy) }
it { should have_many(:events).class_name('Event').dependent(:destroy) }
......
......@@ -13,7 +13,12 @@ describe UserObserver do
end
context 'when a new user is created' do
let(:user) { double(:user, id: 42, password: 'P@ssword!', name: 'John', email: 'u@mail.local') }
let(:user) { double(:user, id: 42,
password: 'P@ssword!',
name: 'John',
email: 'u@mail.local',
username: 'root',
create_namespace: true) }
let(:notification) { double :notification }
it 'sends an email' do
......
......@@ -2,9 +2,7 @@ require 'spec_helper'
describe UsersProjectObserver do
let(:user) { create(:user) }
let(:project) { create(:project,
code: "Fuu",
path: "Fuu" ) }
let(:project) { create(:project) }
let(:users_project) { create(:users_project,
project: project,
user: user )}
......
......@@ -2,9 +2,7 @@ require 'spec_helper'
describe "Admin::Hooks" do
before do
@project = create(:project,
name: "LeGiT",
code: "LGT")
@project = create(:project)
login_as :admin
@system_hook = create(:system_hook)
......
......@@ -2,9 +2,7 @@ require 'spec_helper'
describe "Admin::Projects" do
before do
@project = create(:project,
name: "LeGiT",
code: "LGT")
@project = create(:project)
login_as :admin
end
......@@ -29,7 +27,7 @@ describe "Admin::Projects" do
end
it "should have project info" do
page.should have_content(@project.code)
page.should have_content(@project.path)
page.should have_content(@project.name)
end
end
......@@ -41,67 +39,27 @@ describe "Admin::Projects" do
end
it "should have project edit page" do
page.should have_content("Project name")
page.should have_content("URL")
page.should have_content("Edit project")
page.should have_button("Save Project")
end
describe "Update project" do
before do
fill_in "project_name", with: "Big Bang"
fill_in "project_code", with: "BB1"
click_button "Save Project"
@project.reload
end
it "should show page with new data" do
page.should have_content("BB1")
page.should have_content("Big Bang")
end
it "should change project entry" do
@project.name.should == "Big Bang"
@project.code.should == "BB1"
end
end
end
describe "GET /admin/projects/new" do
before do
visit admin_projects_path
click_link "New Project"
end
it "should be correct path" do
current_path.should == new_admin_project_path
end
it "should have labels for new project" do
page.should have_content("Project name is")
page.should have_content("Git Clone")
page.should have_content("URL")
end
end
describe "POST /admin/projects" do
before do
visit new_admin_project_path
fill_in 'project_name', with: 'NewProject'
fill_in 'project_code', with: 'NPR'
fill_in 'project_path', with: 'gitlabhq_1'
expect { click_button "Create project" }.to change { Project.count }.by(1)
@project = Project.last
end
it "should be correct path" do
current_path.should == admin_project_path(@project)
end
it "should show project" do
page.should have_content(@project.name)
page.should have_content(@project.path)
end
end
describe "Add new team member" do
before do
@new_user = create(:user)
......
......@@ -23,6 +23,7 @@ describe "Admin::Users" do
@password = "123ABC"
visit new_admin_user_path
fill_in "user_name", with: "Big Bang"
fill_in "user_username", with: "bang"
fill_in "user_email", with: "bigbang@mail.com"
fill_in "user_password", with: @password
fill_in "user_password_confirmation", with: @password
......
......@@ -28,7 +28,7 @@ describe Gitlab::API do
describe "GET /projects/:id/issues" do
it "should return project issues" do
get api("/projects/#{project.code}/issues", user)
get api("/projects/#{project.path}/issues", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['title'].should == issue.title
......@@ -37,7 +37,7 @@ describe Gitlab::API do
describe "GET /projects/:id/issues/:issue_id" do
it "should return a project issue by id" do
get api("/projects/#{project.code}/issues/#{issue.id}", user)
get api("/projects/#{project.path}/issues/#{issue.id}", user)
response.status.should == 200
json_response['title'].should == issue.title
end
......@@ -45,7 +45,7 @@ describe Gitlab::API do
describe "POST /projects/:id/issues" do
it "should create a new project issue" do
post api("/projects/#{project.code}/issues", user),
post api("/projects/#{project.path}/issues", user),
title: 'new issue', labels: 'label, label2'
response.status.should == 201
json_response['title'].should == 'new issue'
......@@ -56,7 +56,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/issues/:issue_id" do
it "should update a project issue" do
put api("/projects/#{project.code}/issues/#{issue.id}", user),
put api("/projects/#{project.path}/issues/#{issue.id}", user),
title: 'updated title', labels: 'label2', closed: 1
response.status.should == 200
json_response['title'].should == 'updated title'
......@@ -67,7 +67,7 @@ describe Gitlab::API do
describe "DELETE /projects/:id/issues/:issue_id" do
it "should delete a project issue" do
delete api("/projects/#{project.code}/issues/#{issue.id}", user)
delete api("/projects/#{project.path}/issues/#{issue.id}", user)
response.status.should == 405
end
end
......
......@@ -11,14 +11,14 @@ describe Gitlab::API do
describe "GET /projects/:id/merge_requests" do
context "when unauthenticated" do
it "should return authentication error" do
get api("/projects/#{project.code}/merge_requests")
get api("/projects/#{project.path}/merge_requests")
response.status.should == 401
end
end
context "when authenticated" do
it "should return an array of merge_requests" do
get api("/projects/#{project.code}/merge_requests", user)
get api("/projects/#{project.path}/merge_requests", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['title'].should == merge_request.title
......@@ -28,7 +28,7 @@ describe Gitlab::API do
describe "GET /projects/:id/merge_request/:merge_request_id" do
it "should return merge_request" do
get api("/projects/#{project.code}/merge_request/#{merge_request.id}", user)
get api("/projects/#{project.path}/merge_request/#{merge_request.id}", user)
response.status.should == 200
json_response['title'].should == merge_request.title
end
......@@ -36,7 +36,7 @@ describe Gitlab::API do
describe "POST /projects/:id/merge_requests" do
it "should return merge_request" do
post api("/projects/#{project.code}/merge_requests", user),
post api("/projects/#{project.path}/merge_requests", user),
title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user
response.status.should == 201
json_response['title'].should == 'Test merge_request'
......@@ -45,7 +45,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/merge_request/:merge_request_id" do
it "should return merge_request" do
put api("/projects/#{project.code}/merge_request/#{merge_request.id}", user), title: "New title"
put api("/projects/#{project.path}/merge_request/#{merge_request.id}", user), title: "New title"
response.status.should == 200
json_response['title'].should == 'New title'
end
......@@ -53,7 +53,7 @@ describe Gitlab::API do
describe "POST /projects/:id/merge_request/:merge_request_id/comments" do
it "should return comment" do
post api("/projects/#{project.code}/merge_request/#{merge_request.id}/comments", user), note: "My comment"
post api("/projects/#{project.path}/merge_request/#{merge_request.id}/comments", user), note: "My comment"
response.status.should == 201
json_response['note'].should == 'My comment'
end
......
......@@ -11,7 +11,7 @@ describe Gitlab::API do
describe "GET /projects/:id/milestones" do
it "should return project milestones" do
get api("/projects/#{project.code}/milestones", user)
get api("/projects/#{project.path}/milestones", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['title'].should == milestone.title
......@@ -20,7 +20,7 @@ describe Gitlab::API do
describe "GET /projects/:id/milestones/:milestone_id" do
it "should return a project milestone by id" do
get api("/projects/#{project.code}/milestones/#{milestone.id}", user)
get api("/projects/#{project.path}/milestones/#{milestone.id}", user)
response.status.should == 200
json_response['title'].should == milestone.title
end
......@@ -28,7 +28,7 @@ describe Gitlab::API do
describe "POST /projects/:id/milestones" do
it "should create a new project milestone" do
post api("/projects/#{project.code}/milestones", user),
post api("/projects/#{project.path}/milestones", user),
title: 'new milestone'
response.status.should == 201
json_response['title'].should == 'new milestone'
......@@ -38,7 +38,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/milestones/:milestone_id" do
it "should update a project milestone" do
put api("/projects/#{project.code}/milestones/#{milestone.id}", user),
put api("/projects/#{project.path}/milestones/#{milestone.id}", user),
title: 'updated title'
response.status.should == 200
json_response['title'].should == 'updated title'
......
......@@ -33,7 +33,7 @@ describe Gitlab::API do
end
describe "POST /projects" do
it "should create new project without code and path" do
it "should create new project without path" do
expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1)
end
......@@ -53,8 +53,6 @@ describe Gitlab::API do
it "should assign attributes to project" do
project = attributes_for(:project, {
path: 'path',
code: 'code',
description: Faker::Lorem.sentence,
default_branch: 'stable',
issues_enabled: false,
......@@ -79,8 +77,8 @@ describe Gitlab::API do
json_response['owner']['email'].should == user.email
end
it "should return a project by code name" do
get api("/projects/#{project.code}", user)
it "should return a project by path name" do
get api("/projects/#{project.path}", user)
response.status.should == 200
json_response['name'].should == project.name
end
......@@ -94,7 +92,7 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/branches" do
it "should return an array of project branches" do
get api("/projects/#{project.code}/repository/branches", user)
get api("/projects/#{project.path}/repository/branches", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name
......@@ -103,7 +101,7 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/branches/:branch" do
it "should return the branch information for a single branch" do
get api("/projects/#{project.code}/repository/branches/new_design", user)
get api("/projects/#{project.path}/repository/branches/new_design", user)
response.status.should == 200
json_response['name'].should == 'new_design'
......@@ -113,7 +111,7 @@ describe Gitlab::API do
describe "GET /projects/:id/members" do
it "should return project team members" do
get api("/projects/#{project.code}/members", user)
get api("/projects/#{project.path}/members", user)
response.status.should == 200
json_response.should be_an Array
json_response.count.should == 2
......@@ -123,7 +121,7 @@ describe Gitlab::API do
describe "GET /projects/:id/members/:user_id" do
it "should return project team member" do
get api("/projects/#{project.code}/members/#{user.id}", user)
get api("/projects/#{project.path}/members/#{user.id}", user)
response.status.should == 200
json_response['email'].should == user.email
json_response['access_level'].should == UsersProject::MASTER
......@@ -133,7 +131,7 @@ describe Gitlab::API do
describe "POST /projects/:id/members" do
it "should add user to project team" do
expect {
post api("/projects/#{project.code}/members", user), user_id: user2.id,
post api("/projects/#{project.path}/members", user), user_id: user2.id,
access_level: UsersProject::DEVELOPER
}.to change { UsersProject.count }.by(1)
......@@ -145,7 +143,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/members/:user_id" do
it "should update project team member" do
put api("/projects/#{project.code}/members/#{user3.id}", user), access_level: UsersProject::MASTER
put api("/projects/#{project.path}/members/#{user3.id}", user), access_level: UsersProject::MASTER
response.status.should == 200
json_response['email'].should == user3.email
json_response['access_level'].should == UsersProject::MASTER
......@@ -155,14 +153,14 @@ describe Gitlab::API do
describe "DELETE /projects/:id/members/:user_id" do
it "should remove user from project team" do
expect {
delete api("/projects/#{project.code}/members/#{user3.id}", user)
delete api("/projects/#{project.path}/members/#{user3.id}", user)
}.to change { UsersProject.count }.by(-1)
end
end
describe "GET /projects/:id/hooks" do
it "should return project hooks" do
get api("/projects/#{project.code}/hooks", user)
get api("/projects/#{project.path}/hooks", user)
response.status.should == 200
......@@ -174,7 +172,7 @@ describe Gitlab::API do
describe "GET /projects/:id/hooks/:hook_id" do
it "should return a project hook" do
get api("/projects/#{project.code}/hooks/#{hook.id}", user)
get api("/projects/#{project.path}/hooks/#{hook.id}", user)
response.status.should == 200
json_response['url'].should == hook.url
end
......@@ -183,7 +181,7 @@ describe Gitlab::API do
describe "POST /projects/:id/hooks" do
it "should add hook to project" do
expect {
post api("/projects/#{project.code}/hooks", user),
post api("/projects/#{project.path}/hooks", user),
"url" => "http://example.com"
}.to change {project.hooks.count}.by(1)
end
......@@ -191,7 +189,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/hooks/:hook_id" do
it "should update an existing project hook" do
put api("/projects/#{project.code}/hooks/#{hook.id}", user),
put api("/projects/#{project.path}/hooks/#{hook.id}", user),
url: 'http://example.org'
response.status.should == 200
json_response['url'].should == 'http://example.org'
......@@ -202,7 +200,7 @@ describe Gitlab::API do
describe "DELETE /projects/:id/hooks" do
it "should delete hook from project" do
expect {
delete api("/projects/#{project.code}/hooks", user),
delete api("/projects/#{project.path}/hooks", user),
hook_id: hook.id
}.to change {project.hooks.count}.by(-1)
end
......@@ -210,7 +208,7 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/tags" do
it "should return an array of project tags" do
get api("/projects/#{project.code}/repository/tags", user)
get api("/projects/#{project.path}/repository/tags", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name
......@@ -222,7 +220,7 @@ describe Gitlab::API do
before { project.add_access(user2, :read) }
it "should return project commits" do
get api("/projects/#{project.code}/repository/commits", user)
get api("/projects/#{project.path}/repository/commits", user)
response.status.should == 200
json_response.should be_an Array
......@@ -232,7 +230,7 @@ describe Gitlab::API do
context "unauthorized user" do
it "should not return project commits" do
get api("/projects/#{project.code}/repository/commits")
get api("/projects/#{project.path}/repository/commits")
response.status.should == 401
end
end
......@@ -240,7 +238,7 @@ describe Gitlab::API do
describe "GET /projects/:id/snippets" do
it "should return an array of project snippets" do
get api("/projects/#{project.code}/snippets", user)
get api("/projects/#{project.path}/snippets", user)
response.status.should == 200
json_response.should be_an Array
json_response.first['title'].should == snippet.title
......@@ -249,7 +247,7 @@ describe Gitlab::API do
describe "GET /projects/:id/snippets/:snippet_id" do
it "should return a project snippet" do
get api("/projects/#{project.code}/snippets/#{snippet.id}", user)
get api("/projects/#{project.path}/snippets/#{snippet.id}", user)
response.status.should == 200
json_response['title'].should == snippet.title
end
......@@ -257,7 +255,7 @@ describe Gitlab::API do
describe "POST /projects/:id/snippets" do
it "should create a new project snippet" do
post api("/projects/#{project.code}/snippets", user),
post api("/projects/#{project.path}/snippets", user),
title: 'api test', file_name: 'sample.rb', code: 'test'
response.status.should == 201
json_response['title'].should == 'api test'
......@@ -266,7 +264,7 @@ describe Gitlab::API do
describe "PUT /projects/:id/snippets/:shippet_id" do
it "should update an existing project snippet" do
put api("/projects/#{project.code}/snippets/#{snippet.id}", user),
put api("/projects/#{project.path}/snippets/#{snippet.id}", user),
code: 'updated code'
response.status.should == 200
json_response['title'].should == 'example'
......@@ -277,31 +275,31 @@ describe Gitlab::API do
describe "DELETE /projects/:id/snippets/:snippet_id" do
it "should delete existing project snippet" do
expect {
delete api("/projects/#{project.code}/snippets/#{snippet.id}", user)
delete api("/projects/#{project.path}/snippets/#{snippet.id}", user)
}.to change { Snippet.count }.by(-1)
end
end
describe "GET /projects/:id/snippets/:snippet_id/raw" do
it "should get a raw project snippet" do
get api("/projects/#{project.code}/snippets/#{snippet.id}/raw", user)
get api("/projects/#{project.path}/snippets/#{snippet.id}/raw", user)
response.status.should == 200
end
end
describe "GET /projects/:id/:sha/blob" do
it "should get the raw file contents" do
get api("/projects/#{project.code}/repository/commits/master/blob?filepath=README.md", user)
get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.md", user)
response.status.should == 200
end
it "should return 404 for invalid branch_name" do
get api("/projects/#{project.code}/repository/commits/invalid_branch_name/blob?filepath=README.md", user)
get api("/projects/#{project.path}/repository/commits/invalid_branch_name/blob?filepath=README.md", user)
response.status.should == 404
end
it "should return 404 for invalid file" do
get api("/projects/#{project.code}/repository/commits/master/blob?filepath=README.invalid", user)
get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.invalid", user)
response.status.should == 404
end
end
......
......@@ -3,16 +3,6 @@ require 'spec_helper'
describe "Projects" do
before { login_as :user }
describe 'GET /project/new' do
it "should work autocomplete", :js => true do
visit new_project_path
fill_in 'project_name', with: 'Awesome'
find("#project_path").value.should == 'awesome'
find("#project_code").value.should == 'awesome'
end
end
describe "GET /projects/show" do
before do
@project = create(:project, owner: @user)
......@@ -53,7 +43,6 @@ describe "Projects" do
visit edit_project_path(@project)
fill_in 'project_name', with: 'Awesome'
fill_in 'project_code', with: 'gitlabhq'
click_button "Save"
@project = @project.reload
end
......
......@@ -78,14 +78,6 @@ describe Admin::ProjectsController, "routing" do
get("/admin/projects").should route_to('admin/projects#index')
end
it "to #create" do
post("/admin/projects").should route_to('admin/projects#create')
end
it "to #new" do
get("/admin/projects/new").should route_to('admin/projects#new')
end
it "to #edit" do
get("/admin/projects/gitlab/edit").should route_to('admin/projects#edit', id: 'gitlab')
end
......
require 'namespace'
require 'gitlab/project_mover'
class Namespace
def ensure_dir_exist
true
end
def move_dir
true
end
end
class Gitlab::ProjectMover
def execute
true
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