Commit 0727edd8 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Removed issues,mr delete buttons. Refactored models

parent 3fe9d297
...@@ -30,7 +30,7 @@ class MergeRequestsController < ApplicationController ...@@ -30,7 +30,7 @@ class MergeRequestsController < ApplicationController
else @merge_requests.opened else @merge_requests.opened
end end
@merge_requests = @merge_requests.includes(:author, :project) @merge_requests = @merge_requests.includes(:author, :project).order("created_at desc")
end end
def show def show
......
...@@ -14,8 +14,6 @@ class Key < ActiveRecord::Base ...@@ -14,8 +14,6 @@ class Key < ActiveRecord::Base
before_save :set_identifier before_save :set_identifier
before_validation :strip_white_space before_validation :strip_white_space
after_save :update_repository
after_destroy :repository_delete_key
delegate :name, :email, :to => :user, :prefix => true delegate :name, :email, :to => :user, :prefix => true
validate :unique_key validate :unique_key
......
class KeyObserver < ActiveRecord::Observer
def after_save(key)
key.update_repository
end
def after_destroy(key)
key.repository_delete_key
end
end
...@@ -3,19 +3,17 @@ require "grit" ...@@ -3,19 +3,17 @@ require "grit"
class Project < ActiveRecord::Base class Project < ActiveRecord::Base
belongs_to :owner, :class_name => "User" belongs_to :owner, :class_name => "User"
has_many :users, :through => :users_projects
has_many :events, :dependent => :destroy has_many :events, :dependent => :destroy
has_many :merge_requests, :dependent => :destroy has_many :merge_requests, :dependent => :destroy
has_many :issues, :dependent => :destroy, :order => "position" has_many :issues, :dependent => :destroy, :order => "position"
has_many :users_projects, :dependent => :destroy has_many :users_projects, :dependent => :destroy
has_many :users, :through => :users_projects
has_many :notes, :dependent => :destroy has_many :notes, :dependent => :destroy
has_many :snippets, :dependent => :destroy has_many :snippets, :dependent => :destroy
has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key" has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key"
has_many :web_hooks, :dependent => :destroy has_many :web_hooks, :dependent => :destroy
has_many :protected_branches, :dependent => :destroy
has_many :wikis, :dependent => :destroy has_many :wikis, :dependent => :destroy
has_many :protected_branches, :dependent => :destroy
acts_as_taggable
validates :name, validates :name,
:uniqueness => true, :uniqueness => true,
...@@ -39,15 +37,10 @@ class Project < ActiveRecord::Base ...@@ -39,15 +37,10 @@ class Project < ActiveRecord::Base
:message => "only letters, digits & '_' '-' '.' allowed" }, :message => "only letters, digits & '_' '-' '.' allowed" },
:length => { :within => 3..255 } :length => { :within => 3..255 }
validates :owner, validates :owner, :presence => true
:presence => true
validate :check_limit validate :check_limit
validate :repo_name validate :repo_name
after_destroy :destroy_repository
after_save :update_repository
attr_protected :private_flag, :owner_id attr_protected :private_flag, :owner_id
scope :public_only, where(:private_flag => false) scope :public_only, where(:private_flag => false)
...@@ -163,18 +156,6 @@ class Project < ActiveRecord::Base ...@@ -163,18 +156,6 @@ class Project < ActiveRecord::Base
users_projects.find_by_user_id(user_id) users_projects.find_by_user_id(user_id)
end end
def fresh_merge_requests(n)
merge_requests.includes(:project, :author).order("created_at desc").first(n)
end
def fresh_issues(n)
issues.includes(:project, :author).order("created_at desc").first(n)
end
def fresh_notes(n)
notes.inc_author_project.order("created_at desc").first(n)
end
def common_notes def common_notes
notes.where(:noteable_type => ["", nil]).inc_author_project notes.where(:noteable_type => ["", nil]).inc_author_project
end end
...@@ -277,9 +258,7 @@ class Project < ActiveRecord::Base ...@@ -277,9 +258,7 @@ class Project < ActiveRecord::Base
end end
def last_activity def last_activity
events.last events.last || nil
rescue
nil
end end
def last_activity_date def last_activity_date
...@@ -294,43 +273,6 @@ class Project < ActiveRecord::Base ...@@ -294,43 +273,6 @@ class Project < ActiveRecord::Base
last_activity_date last_activity_date
end end
# Get project updates from cache
# or calculate.
def cached_updates(limit, expire = 2.minutes)
activities_key = "project_#{id}_activities"
cached_activities = Rails.cache.read(activities_key)
if cached_activities
activities = cached_activities
else
activities = updates(limit)
Rails.cache.write(activities_key, activities, :expires_in => expire)
end
activities
end
# Get 20 events for project like
# commits, issues or notes
def updates(n = 3)
[
fresh_commits(n),
fresh_issues(n),
fresh_notes(n)
].compact.flatten.sort do |x, y|
y.created_at <=> x.created_at
end[0...n]
end
def activities(n=3)
[
fresh_issues(n),
fresh_merge_requests(n),
notes.inc_author_project.where("noteable_type is not null").order("created_at desc").first(n)
].compact.flatten.sort do |x, y|
y.created_at <=> x.created_at
end[0...n]
end
def check_limit def check_limit
unless owner.can_create_project? unless owner.can_create_project?
errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it") errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it")
......
class ProjectObserver < ActiveRecord::Observer
def after_save(project)
project.update_repository
end
def after_destroy(project)
project.destroy_repository
end
end
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
- @issue.errors.full_messages.each do |msg| - @issue.errors.full_messages.each do |msg|
%li= msg %li= msg
.clearfix
= f.label :title
.input= f.text_area :title, :maxlength => 255, :class => "xxlarge"
.clearfix .clearfix
= f.label :assignee_id = f.label :assignee_id
.input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" }) .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" })
...@@ -21,9 +25,6 @@ ...@@ -21,9 +25,6 @@
= f.label :closed = f.label :closed
.input= f.check_box :closed .input= f.check_box :closed
.clearfix
= f.label :title
.input= f.text_area :title, :maxlength => 255, :class => "xxlarge"
.actions .actions
= f.submit 'Save', :class => "primary btn" = f.submit 'Save', :class => "primary btn"
...@@ -34,8 +35,3 @@ ...@@ -34,8 +35,3 @@
= link_to "Cancel", project_issues_path(@project), :class => "btn" = link_to "Cancel", project_issues_path(@project), :class => "btn"
- else - else
= link_to "Cancel", project_issue_path(@project, @issue), :class => "btn" = link_to "Cancel", project_issue_path(@project, @issue), :class => "btn"
- unless @issue.new_record?
.right
= link_to 'Remove', [@project, @issue], :confirm => 'Are you sure?', :method => :delete, :class => "danger btn"
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
- else - else
= link_to 'Resolve', project_issue_path(issue.project, issue, :issue => {:closed => true }, :status_only => true), :method => :put, :class => "success btn small", :remote => true = link_to 'Resolve', project_issue_path(issue.project, issue, :issue => {:closed => true }, :status_only => true), :method => :put, :class => "success btn small", :remote => true
= link_to 'Edit', edit_project_issue_path(issue.project, issue), :class => "btn small edit-issue-link", :remote => true = link_to 'Edit', edit_project_issue_path(issue.project, issue), :class => "btn small edit-issue-link", :remote => true
-#- if can?(current_user, :admin_issue, @project) || issue.author == current_user
= link_to 'Remove', [issue.project, issue], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "danger btn small delete-issue", :id => "destroy_issue_#{issue.id}"
= image_tag gravatar_icon(issue.assignee_email), :class => "avatar" = image_tag gravatar_icon(issue.assignee_email), :class => "avatar"
%span.update-author %span.update-author
assigned to assigned to
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
- @merge_request.errors.full_messages.each do |msg| - @merge_request.errors.full_messages.each do |msg|
%li= msg %li= msg
.clearfix
= f.label :title
.input= f.text_area :title, :class => "xxlarge", :maxlength => 255, :rows => 5
.clearfix .clearfix
= f.label :source_branch, "From" = f.label :source_branch, "From"
.input= f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") .input= f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px")
...@@ -15,9 +18,6 @@ ...@@ -15,9 +18,6 @@
= f.label :assignee_id, "Assign to" = f.label :assignee_id, "Assign to"
.input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" }, :style => "width:250px") .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" }, :style => "width:250px")
.clearfix
= f.label :title
.input= f.text_area :title, :class => "xlarge", :maxlength => 255, :rows => 5
.actions .actions
= f.submit 'Save', :class => "primary btn" = f.submit 'Save', :class => "primary btn"
- if @merge_request.new_record? - if @merge_request.new_record?
...@@ -26,11 +26,6 @@ ...@@ -26,11 +26,6 @@
- else - else
= link_to project_merge_request_path(@project, @merge_request), :class => "btn" do = link_to project_merge_request_path(@project, @merge_request), :class => "btn" do
Cancel Cancel
&nbsp;
- unless @merge_request.new_record?
.right
= link_to 'Remove', [@project, @merge_request], :confirm => 'Are you sure?', :method => :delete, :class => "btn danger"
......
- unless @projects.empty? .row
.row
.span4 .span4
%div.leftbar.ui-box %div.leftbar.ui-box
%h5 %h5
...@@ -18,9 +17,6 @@ ...@@ -18,9 +17,6 @@
.show_holder.ui-box.padded .show_holder.ui-box.padded
.loading .loading
- else
%h2 Nothing here
:javascript :javascript
$(function(){ $(function(){
......
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ] # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running. # Activate observers that should always be running.
config.active_record.observers = :mailer_observer, :activity_observer config.active_record.observers = :mailer_observer, :activity_observer, :project_observer, :key_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
......
...@@ -24,25 +24,13 @@ ActiveRecord::Schema.define(:version => 20120301185805) do ...@@ -24,25 +24,13 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t.integer "action" t.integer "action"
end end
create_table "features", :force => true do |t|
t.string "name"
t.string "branch_name"
t.integer "assignee_id"
t.integer "author_id"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "version"
t.integer "status", :default => 0, :null => false
end
create_table "issues", :force => true do |t| create_table "issues", :force => true do |t|
t.string "title" t.string "title"
t.integer "assignee_id" t.integer "assignee_id"
t.integer "author_id" t.integer "author_id"
t.integer "project_id" t.integer "project_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.boolean "closed", :default => false, :null => false t.boolean "closed", :default => false, :null => false
t.integer "position", :default => 0 t.integer "position", :default => 0
t.boolean "critical", :default => false, :null => false t.boolean "critical", :default => false, :null => false
...@@ -53,8 +41,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do ...@@ -53,8 +41,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
create_table "keys", :force => true do |t| create_table "keys", :force => true do |t|
t.integer "user_id" t.integer "user_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.text "key" t.text "key"
t.string "title" t.string "title"
t.string "identifier" t.string "identifier"
...@@ -69,8 +57,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do ...@@ -69,8 +57,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t.integer "assignee_id" t.integer "assignee_id"
t.string "title" t.string "title"
t.boolean "closed", :default => false, :null => false t.boolean "closed", :default => false, :null => false
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
add_index "merge_requests", ["project_id"], :name => "index_merge_requests_on_project_id" add_index "merge_requests", ["project_id"], :name => "index_merge_requests_on_project_id"
...@@ -80,8 +68,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do ...@@ -80,8 +68,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t.string "noteable_id" t.string "noteable_id"
t.string "noteable_type" t.string "noteable_type"
t.integer "author_id" t.integer "author_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "project_id" t.integer "project_id"
t.string "attachment" t.string "attachment"
t.string "line_code" t.string "line_code"
...@@ -94,8 +82,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do ...@@ -94,8 +82,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t.string "name" t.string "name"
t.string "path" t.string "path"
t.text "description" t.text "description"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.boolean "private_flag", :default => true, :null => false t.boolean "private_flag", :default => true, :null => false
t.string "code" t.string "code"
t.integer "owner_id" t.integer "owner_id"
...@@ -118,8 +106,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do ...@@ -118,8 +106,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t.text "content" t.text "content"
t.integer "author_id", :null => false t.integer "author_id", :null => false
t.integer "project_id", :null => false t.integer "project_id", :null => false
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "file_name" t.string "file_name"
t.datetime "expires_at" t.datetime "expires_at"
end end
...@@ -152,8 +140,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do ...@@ -152,8 +140,8 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.string "name" t.string "name"
t.boolean "admin", :default => false, :null => false t.boolean "admin", :default => false, :null => false
t.integer "projects_limit", :default => 10 t.integer "projects_limit", :default => 10
...@@ -171,16 +159,16 @@ ActiveRecord::Schema.define(:version => 20120301185805) do ...@@ -171,16 +159,16 @@ ActiveRecord::Schema.define(:version => 20120301185805) do
create_table "users_projects", :force => true do |t| create_table "users_projects", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.integer "project_id", :null => false t.integer "project_id", :null => false
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
t.integer "project_access", :default => 0, :null => false t.integer "project_access", :default => 0, :null => false
end end
create_table "web_hooks", :force => true do |t| create_table "web_hooks", :force => true do |t|
t.string "url" t.string "url"
t.integer "project_id" t.integer "project_id"
t.datetime "created_at" t.datetime "created_at", :null => false
t.datetime "updated_at" t.datetime "updated_at", :null => false
end end
create_table "wikis", :force => true do |t| create_table "wikis", :force => true do |t|
......
...@@ -2,13 +2,17 @@ require 'spec_helper' ...@@ -2,13 +2,17 @@ require 'spec_helper'
describe Project do describe Project do
describe "Associations" do describe "Associations" do
it { should have_many(:events) }
it { should have_many(:users) } it { should have_many(:users) }
it { should have_many(:users_projects) } it { should have_many(:protected_branches).dependent(:destroy) }
it { should have_many(:issues) } it { should have_many(:events).dependent(:destroy) }
it { should have_many(:notes) } it { should have_many(:wikis).dependent(:destroy) }
it { should have_many(:snippets) } it { should have_many(:merge_requests).dependent(:destroy) }
it { should have_many(:users_projects).dependent(:destroy) }
it { should have_many(:issues).dependent(:destroy) }
it { should have_many(:notes).dependent(:destroy) }
it { should have_many(:snippets).dependent(:destroy) }
it { should have_many(:web_hooks).dependent(:destroy) } it { should have_many(:web_hooks).dependent(:destroy) }
it { should have_many(:deploy_keys).dependent(:destroy) }
end end
describe "Validation" do describe "Validation" do
...@@ -70,30 +74,6 @@ describe Project do ...@@ -70,30 +74,6 @@ describe Project do
end end
end end
describe "updates" do
let(:project) { Factory :project }
before do
@issue = Factory :issue,
:project => project,
:author => Factory(:user),
:assignee => Factory(:user)
@note = Factory :note,
:project => project,
:author => Factory(:user)
@commit = project.fresh_commits(1).first
end
describe "return commit, note & issue" do
it { project.updates(3).count.should == 3 }
it { project.updates(3).last.id.should == @commit.id }
it { project.updates(3).include?(@issue).should be_true }
it { project.updates(3).include?(@note).should be_true }
end
end
describe "last_activity" do describe "last_activity" do
let(:project) { Factory :project } let(:project) { Factory :project }
......
...@@ -46,21 +46,6 @@ describe "Issues" do ...@@ -46,21 +46,6 @@ describe "Issues" do
page.body.should have_selector("entry summary", :text => @issue.title) page.body.should have_selector("entry summary", :text => @issue.title)
end end
describe "Destroy" do
before do
# admin access to remove issue
@user.users_projects.destroy_all
project.add_access(@user, :read, :write, :admin)
visit edit_project_issue_path(project, @issue)
end
it "should remove entry" do
expect {
click_link "Remove"
}.to change { Issue.count }.by(-1)
end
end
describe "statuses" do describe "statuses" do
before do before do
@closed_issue = Factory :issue, @closed_issue = Factory :issue,
......
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