| |   |
| 29 | 29 | @comment.project = @project |
| 30 | 30 | respond_to do |format| |
| 31 | 31 | if @comment.save |
| 32 | | current_user.create_event(Action::COMMENT, @comment) |
| 32 | @project.create_event(Action::COMMENT, @comment, current_user) |
| 33 | 33 | format.html do |
| 34 | 34 | flash[:success] = "Your comment was added" |
| 35 | 35 | redirect_to project_repository_comments_path(@project, @repository) |
| toggle raw diff |
--- a/app/controllers/comments_controller.rb
+++ b/app/controllers/comments_controller.rb
@@ -29,7 +29,7 @@ class CommentsController < ApplicationController
@comment.project = @project
respond_to do |format|
if @comment.save
- current_user.create_event(Action::COMMENT, @comment)
+ @project.create_event(Action::COMMENT, @comment, current_user)
format.html do
flash[:success] = "Your comment was added"
redirect_to project_repository_comments_path(@project, @repository) |
| |   |
| 22 | 22 | respond_to do |format| |
| 23 | 23 | if @repository.add_committer(@committer) |
| 24 | 24 | @committership = @repository.committerships.find_by_user_id(@committer.id) |
| 25 | | current_user.create_event(Action::ADD_COMMITTER, @committership) |
| 25 | @project.create_event(Action::ADD_COMMITTER, @committership, current_user) |
| 26 | 26 | format.html { redirect_to([@repository.project, @repository]) } |
| 27 | 27 | format.xml do |
| 28 | 28 | render :xml => @committer |
| … | … | |
| 40 | 40 | |
| 41 | 41 | respond_to do |format| |
| 42 | 42 | if @committership.destroy |
| 43 | | current_user.create_event(Action::REMOVE_COMMITTER, @repository, params[:id]) |
| 43 | @project.create_event(Action::REMOVE_COMMITTER, @repository, current_user, params[:id]) |
| 44 | 44 | flash[:success] = "User removed from repository" |
| 45 | 45 | format.html { redirect_to [@repository.project, @repository] } |
| 46 | 46 | format.xml { render :nothing, :status => :ok } |
| toggle raw diff |
--- a/app/controllers/committers_controller.rb
+++ b/app/controllers/committers_controller.rb
@@ -22,7 +22,7 @@ class CommittersController < ApplicationController
respond_to do |format|
if @repository.add_committer(@committer)
@committership = @repository.committerships.find_by_user_id(@committer.id)
- current_user.create_event(Action::ADD_COMMITTER, @committership)
+ @project.create_event(Action::ADD_COMMITTER, @committership, current_user)
format.html { redirect_to([@repository.project, @repository]) }
format.xml do
render :xml => @committer
@@ -40,7 +40,7 @@ class CommittersController < ApplicationController
respond_to do |format|
if @committership.destroy
- current_user.create_event(Action::REMOVE_COMMITTER, @repository, params[:id])
+ @project.create_event(Action::REMOVE_COMMITTER, @repository, current_user, params[:id])
flash[:success] = "User removed from repository"
format.html { redirect_to [@repository.project, @repository] }
format.xml { render :nothing, :status => :ok } |
| |   |
| 31 | 31 | @merge_request.user = current_user |
| 32 | 32 | respond_to do |format| |
| 33 | 33 | if @merge_request.save |
| 34 | | current_user.create_event(Action::REQUEST_MERGE, @merge_request) |
| 34 | @project.create_event(Action::REQUEST_MERGE, @merge_request, current_user) |
| 35 | 35 | format.html { |
| 36 | 36 | flash[:success] = %Q{You sent a merge request to "#{@merge_request.target_repository.name}"} |
| 37 | 37 | redirect_to project_repository_path(@project, @repository) and return |
| … | … | |
| 51 | 51 | # TODO: put to change status |
| 52 | 52 | @merge_request.status = params[:merge_request][:status] |
| 53 | 53 | if @merge_request.save |
| 54 | | current_user.create_event(Action::RESOLVE_MERGE_REQUEST, @merge_request) |
| 54 | @project.create_event(Action::RESOLVE_MERGE_REQUEST, @merge_request, current_user) |
| 55 | 55 | flash[:notice] = "The merge request was marked as #{@merge_request.status_string}" |
| 56 | 56 | end |
| 57 | 57 | redirect_to [@project, @repository, @merge_request] |
| … | … | |
| 64 | 64 | def update |
| 65 | 65 | @merge_request.attributes = params[:merge_request] |
| 66 | 66 | if @merge_request.save |
| 67 | | current_user.create_event(Action::UPDATE_MERGE_REQUEST, @merge_request) |
| 67 | @project.create_event(Action::UPDATE_MERGE_REQUEST, @merge_request, current_user) |
| 68 | 68 | flash[:success] = "Merge request was updated" |
| 69 | 69 | redirect_to [@project, @repository, @merge_request] |
| 70 | 70 | else |
| … | … | |
| 75 | 75 | |
| 76 | 76 | def destroy |
| 77 | 77 | @merge_request.destroy |
| 78 | | current_user.create_event(Action::DELETE_MERGE_REQUEST, @repository) |
| 78 | @project.create_event(Action::DELETE_MERGE_REQUEST, @repository, current_user) |
| 79 | 79 | flash[:success] = "Merge request was retracted" |
| 80 | 80 | redirect_to project_repository_path(@project, @repository) |
| 81 | 81 | end |
| toggle raw diff |
--- a/app/controllers/merge_requests_controller.rb
+++ b/app/controllers/merge_requests_controller.rb
@@ -31,7 +31,7 @@ class MergeRequestsController < ApplicationController
@merge_request.user = current_user
respond_to do |format|
if @merge_request.save
- current_user.create_event(Action::REQUEST_MERGE, @merge_request)
+ @project.create_event(Action::REQUEST_MERGE, @merge_request, current_user)
format.html {
flash[:success] = %Q{You sent a merge request to "#{@merge_request.target_repository.name}"}
redirect_to project_repository_path(@project, @repository) and return
@@ -51,7 +51,7 @@ class MergeRequestsController < ApplicationController
# TODO: put to change status
@merge_request.status = params[:merge_request][:status]
if @merge_request.save
- current_user.create_event(Action::RESOLVE_MERGE_REQUEST, @merge_request)
+ @project.create_event(Action::RESOLVE_MERGE_REQUEST, @merge_request, current_user)
flash[:notice] = "The merge request was marked as #{@merge_request.status_string}"
end
redirect_to [@project, @repository, @merge_request]
@@ -64,7 +64,7 @@ class MergeRequestsController < ApplicationController
def update
@merge_request.attributes = params[:merge_request]
if @merge_request.save
- current_user.create_event(Action::UPDATE_MERGE_REQUEST, @merge_request)
+ @project.create_event(Action::UPDATE_MERGE_REQUEST, @merge_request, current_user)
flash[:success] = "Merge request was updated"
redirect_to [@project, @repository, @merge_request]
else
@@ -75,7 +75,7 @@ class MergeRequestsController < ApplicationController
def destroy
@merge_request.destroy
- current_user.create_event(Action::DELETE_MERGE_REQUEST, @repository)
+ @project.create_event(Action::DELETE_MERGE_REQUEST, @repository, current_user)
flash[:success] = "Merge request was retracted"
redirect_to project_repository_path(@project, @repository)
end |
| |   |
| 46 | 46 | @project = Project.new(params[:project]) |
| 47 | 47 | @project.user = current_user |
| 48 | 48 | if @project.save |
| 49 | | current_user.create_event(Action::CREATE_PROJECT, @project) |
| 49 | @project.create_event(Action::CREATE_PROJECT, @project, current_user) |
| 50 | 50 | redirect_to projects_path |
| 51 | 51 | else |
| 52 | 52 | render :action => 'new' |
| … | … | |
| 65 | 65 | end |
| 66 | 66 | @project.attributes = params[:project] |
| 67 | 67 | if @project.save |
| 68 | | current_user.create_event(Action::UPDATE_PROJECT, @project) |
| 68 | @project.create_event(Action::UPDATE_PROJECT, @project, current_user) |
| 69 | 69 | redirect_to project_path(@project) |
| 70 | 70 | else |
| 71 | 71 | render :action => 'new' |
| … | … | |
| 81 | 81 | if @project.can_be_deleted_by?(current_user) |
| 82 | 82 | project_title = @project.title |
| 83 | 83 | @project.destroy |
| 84 | | current_user.create_event(Action::DELETE_PROJECT, nil, project_title) |
| 84 | #current_user.create_event(Action::DELETE_PROJECT, nil, project_title) |
| 85 | 85 | else |
| 86 | 86 | flash[:error] = "You're not the owner of this project, or the project has clones" |
| 87 | 87 | end |
| toggle raw diff |
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -46,7 +46,7 @@ class ProjectsController < ApplicationController
@project = Project.new(params[:project])
@project.user = current_user
if @project.save
- current_user.create_event(Action::CREATE_PROJECT, @project)
+ @project.create_event(Action::CREATE_PROJECT, @project, current_user)
redirect_to projects_path
else
render :action => 'new'
@@ -65,7 +65,7 @@ class ProjectsController < ApplicationController
end
@project.attributes = params[:project]
if @project.save
- current_user.create_event(Action::UPDATE_PROJECT, @project)
+ @project.create_event(Action::UPDATE_PROJECT, @project, current_user)
redirect_to project_path(@project)
else
render :action => 'new'
@@ -81,7 +81,7 @@ class ProjectsController < ApplicationController
if @project.can_be_deleted_by?(current_user)
project_title = @project.title
@project.destroy
- current_user.create_event(Action::DELETE_PROJECT, nil, project_title)
+ #current_user.create_event(Action::DELETE_PROJECT, nil, project_title)
else
flash[:error] = "You're not the owner of this project, or the project has clones"
end |
| |   |
| 61 | 61 | |
| 62 | 62 | respond_to do |format| |
| 63 | 63 | if @repository.save |
| 64 | | current_user.create_event(Action::CLONE_REPOSITORY, @repository, @repository_to_clone.id) |
| 64 | @project.create_event(Action::CLONE_REPOSITORY, @repository, current_user, @repository_to_clone.id) |
| 65 | 65 | |
| 66 | 66 | location = project_repository_path(@project, @repository) |
| 67 | 67 | format.html { redirect_to location } |
| … | … | |
| 94 | 94 | repo_name = @repository.name |
| 95 | 95 | flash[:notice] = "The repository was deleted" |
| 96 | 96 | @repository.destroy |
| 97 | | current_user.create_event(Action::DELETE_REPOSITORY, @project, repo_name) |
| 97 | @project.create_event(Action::DELETE_REPOSITORY, @project, current_user, repo_name) |
| 98 | 98 | else |
| 99 | 99 | flash[:error] = "You're not the owner of this repository" |
| 100 | 100 | end |
| toggle raw diff |
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -61,7 +61,7 @@ class RepositoriesController < ApplicationController
respond_to do |format|
if @repository.save
- current_user.create_event(Action::CLONE_REPOSITORY, @repository, @repository_to_clone.id)
+ @project.create_event(Action::CLONE_REPOSITORY, @repository, current_user, @repository_to_clone.id)
location = project_repository_path(@project, @repository)
format.html { redirect_to location }
@@ -94,7 +94,7 @@ class RepositoriesController < ApplicationController
repo_name = @repository.name
flash[:notice] = "The repository was deleted"
@repository.destroy
- current_user.create_event(Action::DELETE_REPOSITORY, @project, repo_name)
+ @project.create_event(Action::DELETE_REPOSITORY, @project, current_user, repo_name)
else
flash[:error] = "You're not the owner of this repository"
end |
| |   |
| 9 | 9 | :class_name => "Repository" |
| 10 | 10 | has_many :repository_clones, :conditions => ["mainline = ?", false], |
| 11 | 11 | :class_name => "Repository" |
| 12 | | has_many :events, :as => :target, :dependent => :destroy |
| 12 | has_many :events, :order => "created_at asc" |
| 13 | 13 | |
| 14 | 14 | is_indexed :fields => ["title", "description", "slug"], |
| 15 | 15 | :concatenate => [ |
| … | … | |
| 133 | 133 | } |
| 134 | 134 | super({:procs => [info]}.merge(opts)) |
| 135 | 135 | end |
| 136 | |
| 137 | def create_event(action_id, target, user, data = nil, body = nil) |
| 138 | events.create(:action => action_id, :target => target, :user => user, :body => body, :data => data) |
| 139 | end |
| 136 | 140 | |
| 137 | 141 | protected |
| 138 | 142 | def create_mainline_repository |
| toggle raw diff |
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -9,7 +9,7 @@ class Project < ActiveRecord::Base
:class_name => "Repository"
has_many :repository_clones, :conditions => ["mainline = ?", false],
:class_name => "Repository"
- has_many :events, :as => :target, :dependent => :destroy
+ has_many :events, :order => "created_at asc"
is_indexed :fields => ["title", "description", "slug"],
:concatenate => [
@@ -133,6 +133,10 @@ class Project < ActiveRecord::Base
}
super({:procs => [info]}.merge(opts))
end
+
+ def create_event(action_id, target, user, data = nil, body = nil)
+ events.create(:action => action_id, :target => target, :user => user, :body => body, :data => data)
+ end
protected
def create_mainline_repository |
| |   |
| 120 | 120 | super({:except => [:activation_code, :crypted_password, :remember_token, :remember_token_expires_at, :salt, :ssh_key_id]}.merge(opts)) |
| 121 | 121 | end |
| 122 | 122 | |
| 123 | | def create_event(action_id, target, data = nil, body = nil) |
| 124 | | events.create(:action => action_id, :target => target, :body => body, :data => data) |
| 125 | | end |
| 126 | | |
| 127 | 123 | protected |
| 128 | 124 | # before filter |
| 129 | 125 | def encrypt_password |
| toggle raw diff |
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -120,10 +120,6 @@ class User < ActiveRecord::Base
super({:except => [:activation_code, :crypted_password, :remember_token, :remember_token_expires_at, :salt, :ssh_key_id]}.merge(opts))
end
- def create_event(action_id, target, data = nil, body = nil)
- events.create(:action => action_id, :target => target, :body => body, :data => data)
- end
-
protected
# before filter
def encrypt_password |
| |   |
| 4 | 4 | <li> |
| 5 | 5 | <div style="margin: 20px; padding-bottom: 10px;" > |
| 6 | 6 | <% unless action.empty? %> |
| 7 | | <%= link_to event.user.login, user_path(event.user) %> <%= action %> <%= time_ago_in_words(event.date) %> |
| 7 | <%= link_to event.user.login, user_path(event.user) %> <%= action %> <%= time_ago_in_words(event.created_at) %> |
| 8 | 8 | <% end %><br/> |
| 9 | 9 | <div style="float: left; margin: 5px;"> |
| 10 | 10 | <%= gravatar(event.user.email, :size => 32) %> |
| toggle raw diff |
--- a/app/views/events/_events.html.erb
+++ b/app/views/events/_events.html.erb
@@ -4,7 +4,7 @@
<li>
<div style="margin: 20px; padding-bottom: 10px;" >
<% unless action.empty? %>
- <%= link_to event.user.login, user_path(event.user) %> <%= action %> <%= time_ago_in_words(event.date) %>
+ <%= link_to event.user.login, user_path(event.user) %> <%= action %> <%= time_ago_in_words(event.created_at) %>
<% end %><br/>
<div style="float: left; margin: 5px;">
<%= gravatar(event.user.email, :size => 32) %> |
| |   |
| 70 | 70 | |
| 71 | 71 | user = User.find_by_email(hash[:email]) |
| 72 | 72 | if user.nil? |
| 73 | # TODO: no user should be ok, no need to skip |
| 73 | 74 | $stdout.puts "** The email '#{hash[:email]}' is not registered." |
| 74 | 75 | next |
| 75 | 76 | end |
| … | … | |
| 123 | 123 | |
| 124 | 124 | next unless action_id |
| 125 | 125 | |
| 126 | | puts "#{hash[:author]}: #{Action.name(action_id)} #{ref} on #{slug} [#{hash[:date]}]" |
| 127 | | puts " #{hash[:message]}" |
| 126 | # puts "#{hash[:author]}: #{Action.name(action_id)} #{ref} on #{slug} [#{hash[:date]}]" |
| 127 | # puts " #{hash[:message]}" |
| 128 | 128 | |
| 129 | | user.create_event(action_id, repository, ref, hash[:message]) |
| 129 | project.create_event(action_id, repository, user, ref, hash[:message]) |
| 130 | 130 | end |
| 131 | 131 | |
| 132 | 132 | puts "=> Thanks! http://#{GitoriousConfig['gitorious_host']}/events" |
| toggle raw diff |
--- a/data/hooks/post-receive
+++ b/data/hooks/post-receive
@@ -70,6 +70,7 @@ while line = gets
user = User.find_by_email(hash[:email])
if user.nil?
+ # TODO: no user should be ok, no need to skip
$stdout.puts "** The email '#{hash[:email]}' is not registered."
next
end
@@ -122,10 +123,10 @@ while line = gets
next unless action_id
- puts "#{hash[:author]}: #{Action.name(action_id)} #{ref} on #{slug} [#{hash[:date]}]"
- puts " #{hash[:message]}"
+ # puts "#{hash[:author]}: #{Action.name(action_id)} #{ref} on #{slug} [#{hash[:date]}]"
+ # puts " #{hash[:message]}"
- user.create_event(action_id, repository, ref, hash[:message])
+ project.create_event(action_id, repository, user, ref, hash[:message])
end
puts "=> Thanks! http://#{GitoriousConfig['gitorious_host']}/events" |
| |   |
| 2 | 2 | def self.up |
| 3 | 3 | create_table :events do |t| |
| 4 | 4 | t.integer :user_id, :null => false |
| 5 | t.integer :project_id, :null => false |
| 5 | 6 | t.integer :action, :null => false |
| 6 | 7 | t.string :data # Additional data |
| 7 | 8 | t.text :body |
| … | … | |
| 14 | 14 | end |
| 15 | 15 | |
| 16 | 16 | add_index :events, :user_id |
| 17 | add_index :events, :project_id |
| 17 | 18 | end |
| 18 | 19 | |
| 19 | 20 | def self.down |
| toggle raw diff |
--- a/db/migrate/024_create_events.rb
+++ b/db/migrate/024_create_events.rb
@@ -2,6 +2,7 @@ class CreateEvents < ActiveRecord::Migration
def self.up
create_table :events do |t|
t.integer :user_id, :null => false
+ t.integer :project_id, :null => false
t.integer :action, :null => false
t.string :data # Additional data
t.text :body
@@ -13,6 +14,7 @@ class CreateEvents < ActiveRecord::Migration
end
add_index :events, :user_id
+ add_index :events, :project_id
end
def self.down |
| |   |
| 12 | 12 | end |
| 13 | 13 | |
| 14 | 14 | it "shows news" do |
| 15 | | users(:johan).create_event(Action::CREATE_PROJECT, @repository, "", "") |
| 15 | projects(:johans).create_event(Action::CREATE_PROJECT, @repository, users(:johan), "", "") |
| 16 | 16 | do_get |
| 17 | 17 | response.should be_success |
| 18 | 18 | end |
| toggle raw diff |
--- a/spec/controllers/events_controller_spec.rb
+++ b/spec/controllers/events_controller_spec.rb
@@ -12,7 +12,7 @@ describe EventsController do
end
it "shows news" do
- users(:johan).create_event(Action::CREATE_PROJECT, @repository, "", "")
+ projects(:johans).create_event(Action::CREATE_PROJECT, @repository, users(:johan), "", "")
do_get
response.should be_success
end |
| |   |
| 5 | 5 | @event = new_event |
| 6 | 6 | @user = users(:johan) |
| 7 | 7 | @repository = repositories(:johans) |
| 8 | @project = @repository.project |
| 8 | 9 | end |
| 9 | 10 | |
| 10 | 11 | def new_event(opts={}) |
| … | … | |
| 14 | 14 | :body => "blabla" |
| 15 | 15 | }.merge(opts)) |
| 16 | 16 | c.user = opts[:user] || users(:johan) |
| 17 | c.project = opts[:project] || @project |
| 17 | 18 | c |
| 18 | 19 | end |
| 19 | 20 | |
| 20 | 21 | it "should have valid associations" do |
| 21 | 22 | @event.should have_valid_associations |
| 22 | | end |
| 23 | | |
| 24 | | it "should create an event from the action name" do |
| 25 | | @user.create_event(Action::CREATE_PROJECT, @repository, "", "").should_not == nil |
| 26 | | end |
| 27 | | |
| 28 | | it "should create an event even without a valid id" do |
| 29 | | @user.create_event(52342, @repository).should_not == nil |
| 30 | | end |
| 31 | | |
| 23 | end |
| 32 | 24 | |
| 33 | 25 | end |
| 34 | 26 | |
| toggle raw diff |
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -5,6 +5,7 @@ describe Event do
@event = new_event
@user = users(:johan)
@repository = repositories(:johans)
+ @project = @repository.project
end
def new_event(opts={})
@@ -13,21 +14,13 @@ describe Event do
:body => "blabla"
}.merge(opts))
c.user = opts[:user] || users(:johan)
+ c.project = opts[:project] || @project
c
end
it "should have valid associations" do
@event.should have_valid_associations
- end
-
- it "should create an event from the action name" do
- @user.create_event(Action::CREATE_PROJECT, @repository, "", "").should_not == nil
- end
-
- it "should create an event even without a valid id" do
- @user.create_event(52342, @repository).should_not == nil
- end
-
+ end
end
|
| |   |
| 113 | 113 | project.send(attr).should be_blank |
| 114 | 114 | end |
| 115 | 115 | end |
| 116 | |
| 117 | describe "Project events" do |
| 118 | before(:each) do |
| 119 | @project = projects(:johans) |
| 120 | @user = users(:johan) |
| 121 | @repository = @project.repositories.first |
| 122 | end |
| 123 | |
| 124 | it "should create an event from the action name" do |
| 125 | @project.create_event(Action::CREATE_PROJECT, @repository, @user, "", "").should_not == nil |
| 126 | end |
| 127 | |
| 128 | it "should create an event even without a valid id" do |
| 129 | @project.create_event(52342, @repository, @user).should_not == nil |
| 130 | end |
| 131 | |
| 132 | it "creates valid attributes on the event" do |
| 133 | e = @project.create_event(Action::COMMIT, @repository, @user, "somedata", "a body") |
| 134 | e.should be_valid |
| 135 | e.new_record?.should == false |
| 136 | e.reload |
| 137 | e.action.should == Action::COMMIT |
| 138 | e.target.should == @repository |
| 139 | e.project.should == @project |
| 140 | e.user.should == @user |
| 141 | e.data.should == "somedata" |
| 142 | e.body.should == "a body" |
| 143 | end |
| 144 | end |
| 116 | 145 | |
| 117 | 146 | end |
| toggle raw diff |
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -113,5 +113,34 @@ describe Project do
project.send(attr).should be_blank
end
end
+
+ describe "Project events" do
+ before(:each) do
+ @project = projects(:johans)
+ @user = users(:johan)
+ @repository = @project.repositories.first
+ end
+
+ it "should create an event from the action name" do
+ @project.create_event(Action::CREATE_PROJECT, @repository, @user, "", "").should_not == nil
+ end
+
+ it "should create an event even without a valid id" do
+ @project.create_event(52342, @repository, @user).should_not == nil
+ end
+
+ it "creates valid attributes on the event" do
+ e = @project.create_event(Action::COMMIT, @repository, @user, "somedata", "a body")
+ e.should be_valid
+ e.new_record?.should == false
+ e.reload
+ e.action.should == Action::COMMIT
+ e.target.should == @repository
+ e.project.should == @project
+ e.user.should == @user
+ e.data.should == "somedata"
+ e.body.should == "a body"
+ end
+ end
end |