From 990a46018cfb10e9afcaf9cabed9f781ffb44a62 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 25 Jan 2012 12:31:49 +0400 Subject: [PATCH 01/52] [refs #123] Add base logic for activity feed --- app/controllers/activity_feeds_controller.rb | 7 +++ app/controllers/stub_controller.rb | 24 ++++++++ app/helpers/activity_feeds_helper.rb | 2 + app/models/activity_feed.rb | 11 ++++ app/models/activity_feed_observer.rb | 55 +++++++++++++++++++ app/models/comment.rb | 39 ++++++++----- app/models/issue.rb | 26 ++++----- app/models/user.rb | 2 + .../partials/issue_assign_notification.haml | 7 +++ .../partials/new_comment_notification.haml | 9 +++ .../new_comment_reply_notification.haml | 9 +++ .../partials/new_issue_notification.haml | 7 +++ .../partials/new_user_notification.haml | 12 ++++ config/application.rb | 2 +- .../20120124065207_create_activity_feeds.rb | 14 +++++ db/schema.rb | 24 +++----- .../activity_feeds_controller_spec.rb | 5 ++ spec/factories/activity_feeds.rb | 6 ++ spec/helpers/activity_feeds_helper_spec.rb | 15 +++++ spec/models/activity_feed_observer_spec.rb | 5 ++ spec/models/activity_feed_spec.rb | 5 ++ 21 files changed, 243 insertions(+), 43 deletions(-) create mode 100644 app/controllers/activity_feeds_controller.rb create mode 100644 app/controllers/stub_controller.rb create mode 100644 app/helpers/activity_feeds_helper.rb create mode 100644 app/models/activity_feed.rb create mode 100644 app/models/activity_feed_observer.rb create mode 100644 app/views/activity_feeds/partials/issue_assign_notification.haml create mode 100644 app/views/activity_feeds/partials/new_comment_notification.haml create mode 100644 app/views/activity_feeds/partials/new_comment_reply_notification.haml create mode 100644 app/views/activity_feeds/partials/new_issue_notification.haml create mode 100644 app/views/activity_feeds/partials/new_user_notification.haml create mode 100644 db/migrate/20120124065207_create_activity_feeds.rb create mode 100644 spec/controllers/activity_feeds_controller_spec.rb create mode 100644 spec/factories/activity_feeds.rb create mode 100644 spec/helpers/activity_feeds_helper_spec.rb create mode 100644 spec/models/activity_feed_observer_spec.rb create mode 100644 spec/models/activity_feed_spec.rb diff --git a/app/controllers/activity_feeds_controller.rb b/app/controllers/activity_feeds_controller.rb new file mode 100644 index 000000000..3b9a173af --- /dev/null +++ b/app/controllers/activity_feeds_controller.rb @@ -0,0 +1,7 @@ +class ActivityFeedsController < ApplicationController + before_filter :authenticate_user! + + def index + @activity_feeds = current_user.activity_feeds + end +end diff --git a/app/controllers/stub_controller.rb b/app/controllers/stub_controller.rb new file mode 100644 index 000000000..67a69c51a --- /dev/null +++ b/app/controllers/stub_controller.rb @@ -0,0 +1,24 @@ +class StubController < AbstractController::Base + include AbstractController::Rendering + include AbstractController::Layouts + include AbstractController::Helpers + include AbstractController::Translation + include AbstractController::AssetPaths + include ActionController::UrlWriter + + # Uncomment if you want to use helpers + # defined in ApplicationHelper in your views + # helper ApplicationHelper + + # Make sure your controller can find views + self.view_paths = "app/views" + + # You can define custom helper methods to be used in views here + # helper_method :current_admin + # def current_admin; nil; end + + def partial_to_string(partial_name, locals) + render_to_string(partial_name, :locals => locals) + end + +end diff --git a/app/helpers/activity_feeds_helper.rb b/app/helpers/activity_feeds_helper.rb new file mode 100644 index 000000000..54a624bad --- /dev/null +++ b/app/helpers/activity_feeds_helper.rb @@ -0,0 +1,2 @@ +module ActivityFeedsHelper +end diff --git a/app/models/activity_feed.rb b/app/models/activity_feed.rb new file mode 100644 index 000000000..d636301e9 --- /dev/null +++ b/app/models/activity_feed.rb @@ -0,0 +1,11 @@ +class ActivityFeed < ActiveRecord::Base + belongs_to :user + + def render_body(partial_name, locals={}) + av = ActionView::Base.new(Rails::Configuration.new.view_path) + av.render( + :partial => 'app/views/activity_feeds/partials/' + partial_name + '.haml', + :locals => locals + ) + end +end diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb new file mode 100644 index 000000000..22f16dfe3 --- /dev/null +++ b/app/models/activity_feed_observer.rb @@ -0,0 +1,55 @@ +class ActivityFeedObserver < ActiveRecord::Observer + observe :issue, :comment + + def after_create(record) + case record.class.to_s + when 'User' + ActivityFeed.create(:user => record, :body => render_body('new_user_notification')) + when 'Issue' + recipients = record.collect_recipient_ids + recipients.each do |recipient_id| + recipient = User.find(recipient_id) + UserMailer.delay.new_issue_notification(record, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue + ActivityFeed.create(:user => record, :body => render_body('new_issue_notification', {:user => recipient, :issue => record})) + end + + UserMailer.delay.issue_assign_notification(record, record.user) if record.user_id_was != record.user_id && record.user.notifier.issue_assign && record.user.notifier.can_notify + ActivityFeed.create(:user => record.user, :body => render_body('issue_assign_notification', {:user => record.user, :issue => record})) + when 'Comment' + subscribes = record.commentable.subscribes + subscribes.each do |subscribe| + if record.user_id != subscribe.user_id + if record.reply? subscribe + UserMailer.delay.new_comment_reply_notification(record, subscribe.user) if record.can_notify_on_reply?(subscribe) + ActivityFeed.create(:user => record.user, :body => render_body('new_comment_reply_notification', {:user => subscribe.user, :comment => record})) + else + UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe) + ActivityFeed.create(:user => record.user, :body => render_body('new_comment_notification', {:user => subscribe.user, :comment => record})) + end + end + end + end + end + + def after_update(record) + case record.class.to_s + when 'Issue' + UserMailer.delay.issue_assign_notification(record, record.user) if record.user_id_was != record.user_id && record.user.notifier.issue_assign && record.user.notifier.can_notify + ActivityFeed.create(:user => record.user, :body => render_body('issue_assign_notification', {:user => record.user, :issue => record})) + end + end + + def render_body(partial_name, locals={}) + #ac = ActionController::Base.new + #ac.render_to_string( + # 'app/views/activity_feeds/partials/' + partial_name + '.haml', + # :locals => locals + #) + + #ac = ActionView::Base.new([], locals) + #ac.render(:inline => 'app/views/activity_feeds/partials/' + partial_name + '.haml') + + StubController.new.partial_to_string('activity_feeds/partials/' + partial_name, locals) + end + +end diff --git a/app/models/comment.rb b/app/models/comment.rb index 8ba9c05d0..6b6f5a92a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -7,22 +7,35 @@ class Comment < ActiveRecord::Base # FIXME after_create :subscribe_on_reply, :unless => "commentable_type == 'Grit::Commit'" - after_create :deliver_new_comment_notification, :unless => "commentable_type == 'Grit::Commit'" + #after_create :deliver_new_comment_notification, :unless => "commentable_type == 'Grit::Commit'" + + def reply?(subscribe) + self.commentable.comments.exists?(:user_id => subscribe.user.id) + end + + def can_notify_on_reply?(subscribe) + User.find(subscribe.user).notifier.new_comment_reply && User.find(subscribe.user).notifier.can_notify + end + + def can_notify_on_new_comment?(subscribe) + User.find(subscribe.user).notifier.new_comment && User.find(subscribe.user).notifier.can_notify + end protected - def deliver_new_comment_notification - subscribes = self.commentable.subscribes - subscribes.each do |subscribe| - if self.user_id != subscribe.user_id && User.find(subscribe.user).notifier.new_comment_reply && User.find(subscribe.user).notifier.can_notify - if self.commentable.comments.exists?(:user_id => subscribe.user.id) - UserMailer.delay.new_comment_reply_notification(self, subscribe.user) - else - UserMailer.delay.new_comment_notification(self, subscribe.user) - end - end - end - end + #def deliver_new_comment_notification + # subscribes = self.commentable.subscribes + # subscribes.each do |subscribe| + # # TODO: new_comment and new_comment_reply - you need to check each variant, not only new_comment_reply... + # if self.user_id != subscribe.user_id && User.find(subscribe.user).notifier.new_comment_reply && User.find(subscribe.user).notifier.can_notify + # if self.reply? subscribe + # UserMailer.delay.new_comment_reply_notification(self, subscribe.user) + # else + # UserMailer.delay.new_comment_notification(self, subscribe.user) + # end + # end + # end + #end def subscribe_on_reply self.commentable.subscribes.create(:user_id => self.user_id) if !self.commentable.subscribes.exists?(:user_id => self.user_id) diff --git a/app/models/issue.rb b/app/models/issue.rb index efeffbf13..0a0084c95 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -19,9 +19,9 @@ class Issue < ActiveRecord::Base after_create :set_serial_id after_create :subscribe_users - after_create :deliver_new_issue_notification - after_create :deliver_issue_assign_notification - after_update :deliver_issue_assign_notification + #after_create :deliver_new_issue_notification + #after_create :deliver_issue_assign_notification + #after_update :deliver_issue_assign_notification after_update :subscribe_issue_assigned_user def assign_uname @@ -45,17 +45,17 @@ class Issue < ActiveRecord::Base self.save! end - def deliver_new_issue_notification - recipients = collect_recipient_ids - recipients.each do |recipient_id| - recipient = User.find(recipient_id) - UserMailer.delay.new_issue_notification(self, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue - end - end + #def deliver_new_issue_notification + # recipients = collect_recipient_ids + # recipients.each do |recipient_id| + # recipient = User.find(recipient_id) + # UserMailer.delay.new_issue_notification(self, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue + # end + #end - def deliver_issue_assign_notification - UserMailer.delay.issue_assign_notification(self, self.user) if self.user_id_was != self.user_id && self.user.notifier.issue_assign && self.user.notifier.can_notify - end + #def deliver_issue_assign_notification + # UserMailer.delay.issue_assign_notification(self, self.user) if self.user_id_was != self.user_id && self.user.notifier.issue_assign && self.user.notifier.can_notify + #end def subscribe_users recipients = collect_recipient_ids diff --git a/app/models/user.rb b/app/models/user.rb index 16a399caa..5183b86b8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,6 +8,8 @@ class User < ActiveRecord::Base has_one :notifier, :class_name => 'Settings::Notifier' #:notifier + has_many :activity_feeds + has_many :authentications, :dependent => :destroy has_many :build_lists, :dependent => :destroy diff --git a/app/views/activity_feeds/partials/issue_assign_notification.haml b/app/views/activity_feeds/partials/issue_assign_notification.haml new file mode 100644 index 000000000..414f8e6c3 --- /dev/null +++ b/app/views/activity_feeds/partials/issue_assign_notification.haml @@ -0,0 +1,7 @@ +%p== Здравствуйте, #{user.name}. + + +%p Вам была назначена задача #{ link_to issue.title, [issue.project, issue] } + + +%p== Команда поддержки «ROSA Build System» diff --git a/app/views/activity_feeds/partials/new_comment_notification.haml b/app/views/activity_feeds/partials/new_comment_notification.haml new file mode 100644 index 000000000..dd09ab701 --- /dev/null +++ b/app/views/activity_feeds/partials/new_comment_notification.haml @@ -0,0 +1,9 @@ +%p== Здравствуйте, #{user.name}. + + +%p К задаче #{ link_to comment.commentable.title, [comment.commentable.project, comment.commentable] } был добавлен новый комментарий. + +%p "#{ comment.body }" + + +%p== Команда поддержки «ROSA Build System» diff --git a/app/views/activity_feeds/partials/new_comment_reply_notification.haml b/app/views/activity_feeds/partials/new_comment_reply_notification.haml new file mode 100644 index 000000000..9aa223deb --- /dev/null +++ b/app/views/activity_feeds/partials/new_comment_reply_notification.haml @@ -0,0 +1,9 @@ +%p== Здравствуйте, #{user.name}. + + +%p На Ваш комментарий в задаче #{ link_to comment.commentable.title, [comment.commentable.project, comment.commentable] } был дан ответ. + +%p "#{ comment.body }" + + +%p== Команда поддержки «ROSA Build System» diff --git a/app/views/activity_feeds/partials/new_issue_notification.haml b/app/views/activity_feeds/partials/new_issue_notification.haml new file mode 100644 index 000000000..a5a139fd6 --- /dev/null +++ b/app/views/activity_feeds/partials/new_issue_notification.haml @@ -0,0 +1,7 @@ +%p== Здравствуйте, #{user.name}. + + +%p К проекту #{ link_to issue.project.name, project_path(issue.project) } была добавлена задача #{ link_to issue.title, [issue.project, issue] } + + +%p== Команда поддержки «ROSA Build System» diff --git a/app/views/activity_feeds/partials/new_user_notification.haml b/app/views/activity_feeds/partials/new_user_notification.haml new file mode 100644 index 000000000..191e2ad5f --- /dev/null +++ b/app/views/activity_feeds/partials/new_user_notification.haml @@ -0,0 +1,12 @@ +%p== Здравствуйте, #{user.name}. + + +%p Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему. + + +%p + ==Ваш email : #{user.email} + %br/ + ==Ваш пароль: #{user.password} + +%p== Команда поддержки «ROSA Build System» diff --git a/config/application.rb b/config/application.rb index 901d86784..c9d1d710a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -24,7 +24,7 @@ module Rosa # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running. - config.active_record.observers = :event_log_observer + config.active_record.observers = :event_log_observer, :activity_feed_observer # 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. diff --git a/db/migrate/20120124065207_create_activity_feeds.rb b/db/migrate/20120124065207_create_activity_feeds.rb new file mode 100644 index 000000000..6321f4b58 --- /dev/null +++ b/db/migrate/20120124065207_create_activity_feeds.rb @@ -0,0 +1,14 @@ +class CreateActivityFeeds < ActiveRecord::Migration + def self.up + create_table :activity_feeds do |t| + t.integer :user_id, :null => false + t.text :body + + t.timestamps + end + end + + def self.down + drop_table :activity_feeds + end +end diff --git a/db/schema.rb b/db/schema.rb index 825f237ba..038fc0423 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,14 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120117110723) do +ActiveRecord::Schema.define(:version => 20120124065207) do + + create_table "activity_feeds", :force => true do |t| + t.integer "user_id", :null => false + t.text "body" + t.datetime "created_at" + t.datetime "updated_at" + end create_table "arches", :force => true do |t| t.string "name", :null => false @@ -167,13 +174,6 @@ ActiveRecord::Schema.define(:version => 20120117110723) do add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true - create_table "permissions", :force => true do |t| - t.integer "right_id" - t.integer "role_id" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "platforms", :force => true do |t| t.string "description" t.string "name" @@ -270,14 +270,6 @@ ActiveRecord::Schema.define(:version => 20120117110723) do t.string "owner_type" end - create_table "rights", :force => true do |t| - t.string "name", :null => false - t.string "controller", :null => false - t.string "action", :null => false - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "rpms", :force => true do |t| t.string "name", :null => false t.integer "arch_id", :null => false diff --git a/spec/controllers/activity_feeds_controller_spec.rb b/spec/controllers/activity_feeds_controller_spec.rb new file mode 100644 index 000000000..54ce3026a --- /dev/null +++ b/spec/controllers/activity_feeds_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe ActivityFeedsController do + +end diff --git a/spec/factories/activity_feeds.rb b/spec/factories/activity_feeds.rb new file mode 100644 index 000000000..d0e1984cc --- /dev/null +++ b/spec/factories/activity_feeds.rb @@ -0,0 +1,6 @@ +# Read about factories at http://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :activity_feed do + end +end \ No newline at end of file diff --git a/spec/helpers/activity_feeds_helper_spec.rb b/spec/helpers/activity_feeds_helper_spec.rb new file mode 100644 index 000000000..623c526ec --- /dev/null +++ b/spec/helpers/activity_feeds_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the ActivityFeedsHelper. For example: +# +# describe ActivityFeedsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe ActivityFeedsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/activity_feed_observer_spec.rb b/spec/models/activity_feed_observer_spec.rb new file mode 100644 index 000000000..378ee2377 --- /dev/null +++ b/spec/models/activity_feed_observer_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe ActivityFeedObserver do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/activity_feed_spec.rb b/spec/models/activity_feed_spec.rb new file mode 100644 index 000000000..c77e1d83a --- /dev/null +++ b/spec/models/activity_feed_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe ActivityFeed do + pending "add some examples to (or delete) #{__FILE__}" +end From dd1493d67716208173c16d2106f6708ecc69047b Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 25 Jan 2012 17:05:39 +0400 Subject: [PATCH 02/52] [refs #123] Add activity feed page. Remove some unnessary code. Some logic fixes. --- app/models/activity_feed.rb | 8 -------- app/models/activity_feed_observer.rb | 20 +++++++------------- app/views/activity_feeds/index.html.haml | 21 +++++++++++++++++++++ config/locales/ru.yml | 3 +++ config/routes.rb | 5 ++++- 5 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 app/views/activity_feeds/index.html.haml diff --git a/app/models/activity_feed.rb b/app/models/activity_feed.rb index d636301e9..0708e6df6 100644 --- a/app/models/activity_feed.rb +++ b/app/models/activity_feed.rb @@ -1,11 +1,3 @@ class ActivityFeed < ActiveRecord::Base belongs_to :user - - def render_body(partial_name, locals={}) - av = ActionView::Base.new(Rails::Configuration.new.view_path) - av.render( - :partial => 'app/views/activity_feeds/partials/' + partial_name + '.haml', - :locals => locals - ) - end end diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index 22f16dfe3..89eff315b 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -5,26 +5,28 @@ class ActivityFeedObserver < ActiveRecord::Observer case record.class.to_s when 'User' ActivityFeed.create(:user => record, :body => render_body('new_user_notification')) + when 'Issue' recipients = record.collect_recipient_ids recipients.each do |recipient_id| recipient = User.find(recipient_id) UserMailer.delay.new_issue_notification(record, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue - ActivityFeed.create(:user => record, :body => render_body('new_issue_notification', {:user => recipient, :issue => record})) + ActivityFeed.create(:user => recipient, :body => render_body('new_issue_notification', {:user => recipient, :issue => record})) end UserMailer.delay.issue_assign_notification(record, record.user) if record.user_id_was != record.user_id && record.user.notifier.issue_assign && record.user.notifier.can_notify ActivityFeed.create(:user => record.user, :body => render_body('issue_assign_notification', {:user => record.user, :issue => record})) + when 'Comment' subscribes = record.commentable.subscribes subscribes.each do |subscribe| if record.user_id != subscribe.user_id if record.reply? subscribe UserMailer.delay.new_comment_reply_notification(record, subscribe.user) if record.can_notify_on_reply?(subscribe) - ActivityFeed.create(:user => record.user, :body => render_body('new_comment_reply_notification', {:user => subscribe.user, :comment => record})) + ActivityFeed.create(:user => subscribe.user, :body => render_body('new_comment_reply_notification', {:user => subscribe.user, :comment => record})) else UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe) - ActivityFeed.create(:user => record.user, :body => render_body('new_comment_notification', {:user => subscribe.user, :comment => record})) + ActivityFeed.create(:user => subscribe.user, :body => render_body('new_comment_notification', {:user => subscribe.user, :comment => record})) end end end @@ -40,16 +42,8 @@ class ActivityFeedObserver < ActiveRecord::Observer end def render_body(partial_name, locals={}) - #ac = ActionController::Base.new - #ac.render_to_string( - # 'app/views/activity_feeds/partials/' + partial_name + '.haml', - # :locals => locals - #) - - #ac = ActionView::Base.new([], locals) - #ac.render(:inline => 'app/views/activity_feeds/partials/' + partial_name + '.haml') - - StubController.new.partial_to_string('activity_feeds/partials/' + partial_name, locals) + @@stub_controller ||= StubController.new + @@stub_controller.partial_to_string('activity_feeds/partials/' + partial_name, locals) end end diff --git a/app/views/activity_feeds/index.html.haml b/app/views/activity_feeds/index.html.haml new file mode 100644 index 000000000..85f1ba5c6 --- /dev/null +++ b/app/views/activity_feeds/index.html.haml @@ -0,0 +1,21 @@ +%a{ :name => "comments" } +.block#block-list + .content + %h2.title + = t("layout.activity_feed.header") + .inner + %ul.list + - @activity_feeds.each do |activity_feed| + %li + .left + = link_to activity_feed.user.uname, user_path(activity_feed.user.uname) + %br + %br + = activity_feed.created_at + %br + %br + .item + = raw activity_feed.body + %br + %br + %br diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 469a1293a..6ba1c7ea6 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -46,6 +46,9 @@ ru: edit_header: Настройки оповещений processing: Обрабатывается... + activity_feed: + header: Лента активности + downloads: title: Статистика закачек пакетов message: Обновляется автоматически каждые 5 минут diff --git a/config/routes.rb b/config/routes.rb index bda7c96eb..327bc5543 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -132,6 +132,8 @@ Rosa::Application.routes.draw do end end + resources :activity_feeds, :only => [:index] + resources :users, :groups do resources :platforms, :only => [:new, :create] @@ -167,6 +169,7 @@ Rosa::Application.routes.draw do match '/projects/:project_id/git/raw/:treeish/*path', :controller => "git/blobs", :action => :raw, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :raw match '/projects/:project_id/git/commit/raw/:commit_hash/*path', :controller => "git/blobs", :action => :raw, :as => :raw_commit - root :to => "platforms#index" + #root :to => "platforms#index" + root :to => "activity_feeds#index" match '/forbidden', :to => 'platforms#forbidden', :as => 'forbidden' end From 0eb0eb971393b9d1ef8d1e3a15320fb2faf566d6 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 26 Jan 2012 21:04:58 +0400 Subject: [PATCH 03/52] [refs #123] Activity Feed logic global refactoring. --- app/helpers/activity_feeds_helper.rb | 3 ++ app/models/activity_feed.rb | 6 +++ app/models/activity_feed_observer.rb | 40 ++++++++++++++----- app/views/activity_feeds/index.html.haml | 2 +- .../partials/issue_assign_notification.haml | 8 +--- .../partials/new_comment_notification.haml | 10 ++--- .../new_comment_reply_notification.haml | 10 ++--- .../partials/new_issue_notification.haml | 8 +--- .../partials/new_user_notification.haml | 10 ++--- config/locales/ru.yml | 20 ++++++++++ .../20120124065207_create_activity_feeds.rb | 3 +- db/schema.rb | 3 +- 12 files changed, 78 insertions(+), 45 deletions(-) diff --git a/app/helpers/activity_feeds_helper.rb b/app/helpers/activity_feeds_helper.rb index 54a624bad..f3facbf94 100644 --- a/app/helpers/activity_feeds_helper.rb +++ b/app/helpers/activity_feeds_helper.rb @@ -1,2 +1,5 @@ module ActivityFeedsHelper + def render_activity_feed(activity_feed) + render :partial => activity_feed.partial, :locals => activity_feed.data + end end diff --git a/app/models/activity_feed.rb b/app/models/activity_feed.rb index 0708e6df6..934ef56ea 100644 --- a/app/models/activity_feed.rb +++ b/app/models/activity_feed.rb @@ -1,3 +1,9 @@ class ActivityFeed < ActiveRecord::Base belongs_to :user + + serialize :data + + def partial + 'activity_feeds/partials/' + self.kind + end end diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index 89eff315b..eaf3c6772 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -4,18 +4,26 @@ class ActivityFeedObserver < ActiveRecord::Observer def after_create(record) case record.class.to_s when 'User' - ActivityFeed.create(:user => record, :body => render_body('new_user_notification')) + ActivityFeed.create(:user => record, :kind => 'new_user_notification', :date => {:user_name => record.name, :user_email => record.email, :password => user.password}) when 'Issue' recipients = record.collect_recipient_ids recipients.each do |recipient_id| recipient = User.find(recipient_id) UserMailer.delay.new_issue_notification(record, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue - ActivityFeed.create(:user => recipient, :body => render_body('new_issue_notification', {:user => recipient, :issue => record})) + ActivityFeed.create( + :user => recipient, + :kind => 'new_issue_notification', + :data => {:user_name => recipient.name, :issue_id => record.id, :issue_title => record.title, :project_id => record.project.id, :project_name => record.project.name} + ) end UserMailer.delay.issue_assign_notification(record, record.user) if record.user_id_was != record.user_id && record.user.notifier.issue_assign && record.user.notifier.can_notify - ActivityFeed.create(:user => record.user, :body => render_body('issue_assign_notification', {:user => record.user, :issue => record})) + ActivityFeed.create( + :user_name => record.user.name, + :kind => 'issue_assign_notification', + :data => {:user_name => record.user.name, :issue_id => record.id, :project_id => record.project.id, :issue_title => record.title} + ) when 'Comment' subscribes = record.commentable.subscribes @@ -23,10 +31,18 @@ class ActivityFeedObserver < ActiveRecord::Observer if record.user_id != subscribe.user_id if record.reply? subscribe UserMailer.delay.new_comment_reply_notification(record, subscribe.user) if record.can_notify_on_reply?(subscribe) - ActivityFeed.create(:user => subscribe.user, :body => render_body('new_comment_reply_notification', {:user => subscribe.user, :comment => record})) + ActivityFeed.create( + :user => subscribe.user, + :kind => 'new_comment_reply_notification', + :data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_id => record.commentable.id, :project_id => record.commentable.project.id} + ) else UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe) - ActivityFeed.create(:user => subscribe.user, :body => render_body('new_comment_notification', {:user => subscribe.user, :comment => record})) + ActivityFeed.create( + :user => subscribe.user, + :kind => 'new_comment_notification', + :data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_id => record.commentable.id, :project_id => record.commentable.project.id} + ) end end end @@ -37,13 +53,17 @@ class ActivityFeedObserver < ActiveRecord::Observer case record.class.to_s when 'Issue' UserMailer.delay.issue_assign_notification(record, record.user) if record.user_id_was != record.user_id && record.user.notifier.issue_assign && record.user.notifier.can_notify - ActivityFeed.create(:user => record.user, :body => render_body('issue_assign_notification', {:user => record.user, :issue => record})) + ActivityFeed.create( + :user_name => record.user.name, + :kind => 'issue_assign_notification', + :data => {:user_name => record.user.name, :issue_id => record.id, :project_id => record.project.id, :issue_title => record.title} + ) end end - def render_body(partial_name, locals={}) - @@stub_controller ||= StubController.new - @@stub_controller.partial_to_string('activity_feeds/partials/' + partial_name, locals) - end + #def (partial_name, locals={}) + # @@stub_controller ||= StubController.new + # @@stub_controller.partial_to_string('activity_feeds/partials/' + partial_name, locals) + #end end diff --git a/app/views/activity_feeds/index.html.haml b/app/views/activity_feeds/index.html.haml index 85f1ba5c6..838d9a62a 100644 --- a/app/views/activity_feeds/index.html.haml +++ b/app/views/activity_feeds/index.html.haml @@ -15,7 +15,7 @@ %br %br .item - = raw activity_feed.body + = render_activity_feed(activity_feed) %br %br %br diff --git a/app/views/activity_feeds/partials/issue_assign_notification.haml b/app/views/activity_feeds/partials/issue_assign_notification.haml index 414f8e6c3..1dc74a671 100644 --- a/app/views/activity_feeds/partials/issue_assign_notification.haml +++ b/app/views/activity_feeds/partials/issue_assign_notification.haml @@ -1,7 +1,3 @@ -%p== Здравствуйте, #{user.name}. +%p== #{ t("notifications.bodies.issue_assign_notification.title", :user_name => user_name) } - -%p Вам была назначена задача #{ link_to issue.title, [issue.project, issue] } - - -%p== Команда поддержки «ROSA Build System» +%p #{ t("notifications.bodies.issue_assign_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id])) } diff --git a/app/views/activity_feeds/partials/new_comment_notification.haml b/app/views/activity_feeds/partials/new_comment_notification.haml index dd09ab701..bbd60a77b 100644 --- a/app/views/activity_feeds/partials/new_comment_notification.haml +++ b/app/views/activity_feeds/partials/new_comment_notification.haml @@ -1,9 +1,5 @@ -%p== Здравствуйте, #{user.name}. +%p== #{ t("notifications.bodies.new_comment_notification.title", :user_name => user_name) } +%p #{ t("notifications.bodies.new_comment_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id])) } -%p К задаче #{ link_to comment.commentable.title, [comment.commentable.project, comment.commentable] } был добавлен новый комментарий. - -%p "#{ comment.body }" - - -%p== Команда поддержки «ROSA Build System» +%p "#{ comment_body }" diff --git a/app/views/activity_feeds/partials/new_comment_reply_notification.haml b/app/views/activity_feeds/partials/new_comment_reply_notification.haml index 9aa223deb..a0367f840 100644 --- a/app/views/activity_feeds/partials/new_comment_reply_notification.haml +++ b/app/views/activity_feeds/partials/new_comment_reply_notification.haml @@ -1,9 +1,5 @@ -%p== Здравствуйте, #{user.name}. +%p== #{ t("notifications.bodies.new_comment_reply_notification.title", :user_name => user_name) } +%p #{ t("notifications.bodies.new_comment_reply_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id])) } -%p На Ваш комментарий в задаче #{ link_to comment.commentable.title, [comment.commentable.project, comment.commentable] } был дан ответ. - -%p "#{ comment.body }" - - -%p== Команда поддержки «ROSA Build System» +%p "#{ comment_body }" diff --git a/app/views/activity_feeds/partials/new_issue_notification.haml b/app/views/activity_feeds/partials/new_issue_notification.haml index a5a139fd6..75d2269a7 100644 --- a/app/views/activity_feeds/partials/new_issue_notification.haml +++ b/app/views/activity_feeds/partials/new_issue_notification.haml @@ -1,7 +1,3 @@ -%p== Здравствуйте, #{user.name}. +%p== #{ t("notifications.bodies.new_issue_notification.title", :user_name => user_name) } - -%p К проекту #{ link_to issue.project.name, project_path(issue.project) } была добавлена задача #{ link_to issue.title, [issue.project, issue] } - - -%p== Команда поддержки «ROSA Build System» +%p #{ t("notifications.bodies.new_issue_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id]), :project_link => link_to(project_name, project_path(project_id)) } diff --git a/app/views/activity_feeds/partials/new_user_notification.haml b/app/views/activity_feeds/partials/new_user_notification.haml index 191e2ad5f..13339f00d 100644 --- a/app/views/activity_feeds/partials/new_user_notification.haml +++ b/app/views/activity_feeds/partials/new_user_notification.haml @@ -1,12 +1,10 @@ -%p== Здравствуйте, #{user.name}. +%p== #{ t("notifications.bodies.new_user_notification.title", :user_name => user_name) } -%p Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему. +%p #{ t("notifications.bodies.new_user_notification.content") } %p - ==Ваш email : #{user.email} + #{ t("notifications.bodies.new_user_notification.email"), :user_email => user_email } %br/ - ==Ваш пароль: #{user.password} - -%p== Команда поддержки «ROSA Build System» + #{ t("notifications.bodies.new_user_notification.password"), :user_password => user_email } diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 6ba1c7ea6..58ab6c0fa 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -692,6 +692,26 @@ ru: notifications: subjects: new_comment_notification: Новый комментарий к Вашей задаче + new_comment_reply_notification: Новый комментарий к Вашей задаче new_issue_notification: Новая задача добавлена к проекту new_user_notification: Регистрация на проекте «%{ project_name }» issue_assign_notification: Вам назначили задачу + + bodies: + new_comment_notification: + title: Здравствуйте, %{user_name}. + content: К задаче %{ issue_link } был добавлен новый комментарий. + new_comment_reply_notification: + title: Здравствуйте, %{user_name}. + content: На Ваш комментарий в задаче %{ issue_link } был дан ответ. + new_issue_notification: + title: Здравствуйте, %{user_name}. + content: К проекту %{ project_link } была добавлена задача %{ issue_link } + new_user_notification: + title: Здравствуйте, %{user_name}. + content: Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему. + email: ==Ваш email : %{user_email} + password: ==Ваш пароль: %{user_password} + issue_assign_notification: + title: Здравствуйте, %{user_name}. + content: Вам была назначена задача %{ issue_link } diff --git a/db/migrate/20120124065207_create_activity_feeds.rb b/db/migrate/20120124065207_create_activity_feeds.rb index 6321f4b58..d5b13fc3a 100644 --- a/db/migrate/20120124065207_create_activity_feeds.rb +++ b/db/migrate/20120124065207_create_activity_feeds.rb @@ -2,7 +2,8 @@ class CreateActivityFeeds < ActiveRecord::Migration def self.up create_table :activity_feeds do |t| t.integer :user_id, :null => false - t.text :body + t.string :kind + t.text :data t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 038fc0423..c97d7408f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,7 +14,8 @@ ActiveRecord::Schema.define(:version => 20120124065207) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false - t.text "body" + t.string "kind" + t.text "data" t.datetime "created_at" t.datetime "updated_at" end From 72fd821bc8c2bc859bdc1a1741c98f3246bf9651 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 27 Jan 2012 16:06:04 +0400 Subject: [PATCH 04/52] [refs #123] Add fixes for activity feed --- app/models/activity_feed_observer.rb | 34 +++++++++++-------- app/models/issue.rb | 26 +++++++------- .../partials/_issue_assign_notification.haml | 3 ++ .../partials/_new_comment_notification.haml | 5 +++ .../_new_comment_reply_notification.haml | 5 +++ .../partials/_new_issue_notification.haml | 3 ++ .../partials/_new_user_notification.haml | 10 ++++++ .../partials/issue_assign_notification.haml | 3 -- .../partials/new_comment_notification.haml | 5 --- .../new_comment_reply_notification.haml | 5 --- .../partials/new_issue_notification.haml | 3 -- .../partials/new_user_notification.haml | 10 ------ config/locales/en.yml | 21 +++++++++++- config/locales/ru.yml | 12 +++---- 14 files changed, 84 insertions(+), 61 deletions(-) create mode 100644 app/views/activity_feeds/partials/_issue_assign_notification.haml create mode 100644 app/views/activity_feeds/partials/_new_comment_notification.haml create mode 100644 app/views/activity_feeds/partials/_new_comment_reply_notification.haml create mode 100644 app/views/activity_feeds/partials/_new_issue_notification.haml create mode 100644 app/views/activity_feeds/partials/_new_user_notification.haml delete mode 100644 app/views/activity_feeds/partials/issue_assign_notification.haml delete mode 100644 app/views/activity_feeds/partials/new_comment_notification.haml delete mode 100644 app/views/activity_feeds/partials/new_comment_reply_notification.haml delete mode 100644 app/views/activity_feeds/partials/new_issue_notification.haml delete mode 100644 app/views/activity_feeds/partials/new_user_notification.haml diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index eaf3c6772..94d975ff1 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -14,16 +14,18 @@ class ActivityFeedObserver < ActiveRecord::Observer ActivityFeed.create( :user => recipient, :kind => 'new_issue_notification', - :data => {:user_name => recipient.name, :issue_id => record.id, :issue_title => record.title, :project_id => record.project.id, :project_name => record.project.name} + :data => {:user_name => recipient.name, :issue_serial_id => record.serial_id, :issue_title => record.title, :project_id => record.project.id, :project_name => record.project.name} ) end - UserMailer.delay.issue_assign_notification(record, record.user) if record.user_id_was != record.user_id && record.user.notifier.issue_assign && record.user.notifier.can_notify - ActivityFeed.create( - :user_name => record.user.name, - :kind => 'issue_assign_notification', - :data => {:user_name => record.user.name, :issue_id => record.id, :project_id => record.project.id, :issue_title => record.title} - ) + if record.user_id_was != record.user_id + UserMailer.delay.issue_assign_notification(record, record.user) if record.user.notifier.issue_assign && record.user.notifier.can_notify + ActivityFeed.create( + :user => record.user, + :kind => 'issue_assign_notification', + :data => {:user_name => record.user.name, :issue_serial_id => record.serial_id, :project_id => record.project.id, :issue_title => record.title} + ) + end when 'Comment' subscribes = record.commentable.subscribes @@ -34,14 +36,14 @@ class ActivityFeedObserver < ActiveRecord::Observer ActivityFeed.create( :user => subscribe.user, :kind => 'new_comment_reply_notification', - :data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_id => record.commentable.id, :project_id => record.commentable.project.id} + :data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id} ) else UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe) ActivityFeed.create( :user => subscribe.user, :kind => 'new_comment_notification', - :data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_id => record.commentable.id, :project_id => record.commentable.project.id} + :data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id} ) end end @@ -52,12 +54,14 @@ class ActivityFeedObserver < ActiveRecord::Observer def after_update(record) case record.class.to_s when 'Issue' - UserMailer.delay.issue_assign_notification(record, record.user) if record.user_id_was != record.user_id && record.user.notifier.issue_assign && record.user.notifier.can_notify - ActivityFeed.create( - :user_name => record.user.name, - :kind => 'issue_assign_notification', - :data => {:user_name => record.user.name, :issue_id => record.id, :project_id => record.project.id, :issue_title => record.title} - ) + if record.user_id_was != record.user_id + UserMailer.delay.issue_assign_notification(record, record.user) if record.user.notifier.issue_assign && record.user.notifier.can_notify + ActivityFeed.create( + :user => record.user, + :kind => 'issue_assign_notification', + :data => {:user_name => record.user.name, :issue_serial_id => record.serial_id, :project_id => record.project.id, :issue_title => record.title} + ) + end end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 0a0084c95..8d1343595 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -38,6 +38,19 @@ class Issue < ActiveRecord::Base end end + def collect_recipient_ids + recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) } + recipients = recipients | [self.user_id] if self.user_id + recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User' + + # filter by notification settings + recipients = recipients.select do |recipient| + User.find(recipient).notifier.new_issue && User.find(recipient).notifier.can_notify + end + + recipients + end + protected def set_serial_id @@ -65,19 +78,6 @@ class Issue < ActiveRecord::Base end end - def collect_recipient_ids - recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) } - recipients = recipients | [self.user_id] if self.user_id - recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User' - - # filter by notification settings - recipients = recipients.select do |recipient| - User.find(recipient).notifier.new_issue && User.find(recipient).notifier.can_notify - end - - recipients - end - def subscribe_issue_assigned_user if self.user_id_was != self.user_id self.subscribes.where(:user_id => self.user_id_was).first.destroy unless self.user_id_was.blank? diff --git a/app/views/activity_feeds/partials/_issue_assign_notification.haml b/app/views/activity_feeds/partials/_issue_assign_notification.haml new file mode 100644 index 000000000..f3ddea3b2 --- /dev/null +++ b/app/views/activity_feeds/partials/_issue_assign_notification.haml @@ -0,0 +1,3 @@ +%p== #{ t("notifications.bodies.issue_assign_notification.title", :user_name => user_name) } + +%p= raw t("notifications.bodies.issue_assign_notification.content", :issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))) diff --git a/app/views/activity_feeds/partials/_new_comment_notification.haml b/app/views/activity_feeds/partials/_new_comment_notification.haml new file mode 100644 index 000000000..23c15ef74 --- /dev/null +++ b/app/views/activity_feeds/partials/_new_comment_notification.haml @@ -0,0 +1,5 @@ +%p== #{ t("notifications.bodies.new_comment_notification.title", :user_name => user_name) } + +%p= raw t("notifications.bodies.new_comment_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))}) + +%p "#{ comment_body }" diff --git a/app/views/activity_feeds/partials/_new_comment_reply_notification.haml b/app/views/activity_feeds/partials/_new_comment_reply_notification.haml new file mode 100644 index 000000000..a9f040c38 --- /dev/null +++ b/app/views/activity_feeds/partials/_new_comment_reply_notification.haml @@ -0,0 +1,5 @@ +%p== #{ t("notifications.bodies.new_comment_reply_notification.title", :user_name => user_name) } + +%p= raw t("notifications.bodies.new_comment_reply_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))}) + +%p "#{ comment_body }" diff --git a/app/views/activity_feeds/partials/_new_issue_notification.haml b/app/views/activity_feeds/partials/_new_issue_notification.haml new file mode 100644 index 000000000..6f1666c74 --- /dev/null +++ b/app/views/activity_feeds/partials/_new_issue_notification.haml @@ -0,0 +1,3 @@ +%p== #{ t("notifications.bodies.new_issue_notification.title", :user_name => user_name) } + +%p= raw t("notifications.bodies.new_issue_notification.content", :issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id)), :project_link => link_to(project_name, project_path(project_id))) diff --git a/app/views/activity_feeds/partials/_new_user_notification.haml b/app/views/activity_feeds/partials/_new_user_notification.haml new file mode 100644 index 000000000..b1ae04bd6 --- /dev/null +++ b/app/views/activity_feeds/partials/_new_user_notification.haml @@ -0,0 +1,10 @@ +%p== #{ t("notifications.bodies.new_user_notification.title", :user_name => user_name) } + + +%p #{ t("notifications.bodies.new_user_notification.content") } + + +%p + #{ t("notifications.bodies.new_user_notification.email", :user_email => user_email) } + %br/ + #{ t("notifications.bodies.new_user_notification.password", :user_password => user_email) } diff --git a/app/views/activity_feeds/partials/issue_assign_notification.haml b/app/views/activity_feeds/partials/issue_assign_notification.haml deleted file mode 100644 index 1dc74a671..000000000 --- a/app/views/activity_feeds/partials/issue_assign_notification.haml +++ /dev/null @@ -1,3 +0,0 @@ -%p== #{ t("notifications.bodies.issue_assign_notification.title", :user_name => user_name) } - -%p #{ t("notifications.bodies.issue_assign_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id])) } diff --git a/app/views/activity_feeds/partials/new_comment_notification.haml b/app/views/activity_feeds/partials/new_comment_notification.haml deleted file mode 100644 index bbd60a77b..000000000 --- a/app/views/activity_feeds/partials/new_comment_notification.haml +++ /dev/null @@ -1,5 +0,0 @@ -%p== #{ t("notifications.bodies.new_comment_notification.title", :user_name => user_name) } - -%p #{ t("notifications.bodies.new_comment_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id])) } - -%p "#{ comment_body }" diff --git a/app/views/activity_feeds/partials/new_comment_reply_notification.haml b/app/views/activity_feeds/partials/new_comment_reply_notification.haml deleted file mode 100644 index a0367f840..000000000 --- a/app/views/activity_feeds/partials/new_comment_reply_notification.haml +++ /dev/null @@ -1,5 +0,0 @@ -%p== #{ t("notifications.bodies.new_comment_reply_notification.title", :user_name => user_name) } - -%p #{ t("notifications.bodies.new_comment_reply_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id])) } - -%p "#{ comment_body }" diff --git a/app/views/activity_feeds/partials/new_issue_notification.haml b/app/views/activity_feeds/partials/new_issue_notification.haml deleted file mode 100644 index 75d2269a7..000000000 --- a/app/views/activity_feeds/partials/new_issue_notification.haml +++ /dev/null @@ -1,3 +0,0 @@ -%p== #{ t("notifications.bodies.new_issue_notification.title", :user_name => user_name) } - -%p #{ t("notifications.bodies.new_issue_notification.content", :issue_link => link_to(issue_title, [project_id, issue_id]), :project_link => link_to(project_name, project_path(project_id)) } diff --git a/app/views/activity_feeds/partials/new_user_notification.haml b/app/views/activity_feeds/partials/new_user_notification.haml deleted file mode 100644 index 13339f00d..000000000 --- a/app/views/activity_feeds/partials/new_user_notification.haml +++ /dev/null @@ -1,10 +0,0 @@ -%p== #{ t("notifications.bodies.new_user_notification.title", :user_name => user_name) } - - -%p #{ t("notifications.bodies.new_user_notification.content") } - - -%p - #{ t("notifications.bodies.new_user_notification.email"), :user_email => user_email } - %br/ - #{ t("notifications.bodies.new_user_notification.password"), :user_password => user_email } diff --git a/config/locales/en.yml b/config/locales/en.yml index cfeb90f79..a85a5be28 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -691,4 +691,23 @@ en: new_comment_notification: New comment to your task new_issue_notification: New task added to project new_user_notification: Registered on project «%{ project_name }» - issue_assign_notification: New task assigned \ No newline at end of file + issue_assign_notification: New task assigned + + bodies: + new_comment_notification: + title: Hello, %{user_name}. + content: To the issue %{issue_link} added a comment. + new_comment_reply_notification: + title: Hello, %{user_name}. + content: Your comment into issue %{issue_link} has been answered. + new_issue_notification: + title: Hello, %{user_name}. + content: To project %{project_link} has been added an issue %{issue_link} + new_user_notification: + title: Hello, %{user_name}. + content: You have been sign up to project «ROSA Build System» and now can sign in. + email: ==Your email %{user_email} + password: ==Your password %{user_password} + issue_assign_notification: + title: Hello, %{user_name}. + content: You have been assigned to issue %{issue_link} diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 58ab6c0fa..8fb21d916 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -700,18 +700,18 @@ ru: bodies: new_comment_notification: title: Здравствуйте, %{user_name}. - content: К задаче %{ issue_link } был добавлен новый комментарий. + content: К задаче %{issue_link} был добавлен новый комментарий. new_comment_reply_notification: title: Здравствуйте, %{user_name}. - content: На Ваш комментарий в задаче %{ issue_link } был дан ответ. + content: На Ваш комментарий в задаче %{issue_link} был дан ответ. new_issue_notification: title: Здравствуйте, %{user_name}. - content: К проекту %{ project_link } была добавлена задача %{ issue_link } + content: К проекту %{project_link} была добавлена задача %{issue_link} new_user_notification: title: Здравствуйте, %{user_name}. content: Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему. - email: ==Ваш email : %{user_email} - password: ==Ваш пароль: %{user_password} + email: ==Ваш email %{user_email} + password: ==Ваш пароль %{user_password} issue_assign_notification: title: Здравствуйте, %{user_name}. - content: Вам была назначена задача %{ issue_link } + content: Вам была назначена задача %{issue_link} From e01fe571b4c8dccc6e7906f1ef23943994bb2913 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 27 Jan 2012 18:59:28 +0400 Subject: [PATCH 05/52] [refs #123] Add activity feed en translation fixes --- app/models/activity_feed_observer.rb | 8 ++++++-- config/locales/en.yml | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index 94d975ff1..d500c2baa 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -1,10 +1,14 @@ class ActivityFeedObserver < ActiveRecord::Observer - observe :issue, :comment + observe :issue, :comment, :user def after_create(record) case record.class.to_s when 'User' - ActivityFeed.create(:user => record, :kind => 'new_user_notification', :date => {:user_name => record.name, :user_email => record.email, :password => user.password}) + ActivityFeed.create( + :user => record, + :kind => 'new_user_notification', + :date => {:user_name => record.name, :user_email => record.email, :password => user.password} + ) when 'Issue' recipients = record.collect_recipient_ids diff --git a/config/locales/en.yml b/config/locales/en.yml index a85a5be28..367014b0e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -46,6 +46,9 @@ en: edit_header: Notifier setting processing: working ... + activity_feed: + header: Activity Feed + downloads: title: Downloads statistic message: Automatically updated every 5 minutes From 9271c15a5f64c615ae348ec4151422e3cd64a7fb Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 10 Feb 2012 21:33:05 +0400 Subject: [PATCH 06/52] [refs #123] Add new commits support --- app/models/activity_feed_observer.rb | 25 +++++++++++++++++++ app/models/project.rb | 2 +- .../_git_delete_branch_notification.haml | 3 +++ .../partials/_git_new_push_notification.haml | 7 ++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/views/activity_feeds/partials/_git_delete_branch_notification.haml create mode 100644 app/views/activity_feeds/partials/_git_new_push_notification.haml diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index d500c2baa..ac404c168 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -52,6 +52,31 @@ class ActivityFeedObserver < ActiveRecord::Observer end end end + when 'GitHook' + change_type = record.change_type + branch_name = record.refname.match(/\/([\w\d]+)$/)[1] + #user_name = record. + + owner = record.owner + project = Project.find_by_name(record.repo) + + last_commits = project.git_repository.repo.log(branch_name, nil).first(3).collect do |commit| #:author => 'author' + [commit.sha, commit.message] + end + + if change_type == 'delete' + ActivityFeed.create( + :user => owner, + :kind => 'git_delete_branch_notification', + :data => {:user_id => owner.id, :user_name => owner.uname, :project_id => project.id, :project_name => project.name, :branch_name => branch_name, :change_type => change_type} + ) + else + ActivityFeed.create( + :user => owner,#record.user, + :kind => 'git_new_push_notification', + :data => {:user_id => owner.id, :user_name => owner.uname, :project_id => project.id, :project_name => project.name, :last_commits => last_commits, :branch_name => branch_name, :change_type => change_type} + ) + end end end diff --git a/app/models/project.rb b/app/models/project.rb index c15332d5e..4d548b39d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -164,7 +164,7 @@ class Project < ActiveRecord::Base def self.process_hook(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type) rec = GitHook.new(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type) - #ActivityFeedObserver.instance.after_create rec # for example + ActivityFeedObserver.instance.after_create rec end protected diff --git a/app/views/activity_feeds/partials/_git_delete_branch_notification.haml b/app/views/activity_feeds/partials/_git_delete_branch_notification.haml new file mode 100644 index 000000000..22794adab --- /dev/null +++ b/app/views/activity_feeds/partials/_git_delete_branch_notification.haml @@ -0,0 +1,3 @@ +%p== User #{ link_to user_name, user_path(user_id) } delete branch #{ branch_name } + +%p== Into project #{ link_to(project_name, project_path(project_id)) } diff --git a/app/views/activity_feeds/partials/_git_new_push_notification.haml b/app/views/activity_feeds/partials/_git_new_push_notification.haml new file mode 100644 index 000000000..cad03077f --- /dev/null +++ b/app/views/activity_feeds/partials/_git_new_push_notification.haml @@ -0,0 +1,7 @@ +%p== User #{ link_to user_name, user_path(user_id) } #{ change_type } branch #{ branch_name } +%p== Into project #{ link_to(project_name, project_path(project_id)) } + +- last_commits.each do |commit| + = link_to commit[0], commit_path(project_id, commit[0]) + = commit[1] + %br From 08ffd8c25d843d3edcc8106b6634dae465c1fbfd Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 14 Feb 2012 20:09:41 +0400 Subject: [PATCH 07/52] [refs #123] Add wiki to ActivityFeed --- app/controllers/activity_feeds_controller.rb | 2 +- app/controllers/wiki_controller.rb | 1 + app/models/activity_feed_observer.rb | 18 +++++++++++++++++ app/models/issue.rb | 20 ------------------- .../_wiki_new_commit_notification.haml | 2 ++ 5 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 app/views/activity_feeds/partials/_wiki_new_commit_notification.haml diff --git a/app/controllers/activity_feeds_controller.rb b/app/controllers/activity_feeds_controller.rb index 3b9a173af..b23311937 100644 --- a/app/controllers/activity_feeds_controller.rb +++ b/app/controllers/activity_feeds_controller.rb @@ -2,6 +2,6 @@ class ActivityFeedsController < ApplicationController before_filter :authenticate_user! def index - @activity_feeds = current_user.activity_feeds + @activity_feeds = current_user.activity_feeds.order('created_at DESC') end end diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index b334262e3..352e0c283 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -249,6 +249,7 @@ class WikiController < ApplicationController # @committer.after_commit do |committer, sha1| # here goes callback for notification # end + ActivityFeedObserver.instance.after_create(@committer) @committer end diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index ac404c168..fff220e5f 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -77,6 +77,24 @@ class ActivityFeedObserver < ActiveRecord::Observer :data => {:user_id => owner.id, :user_name => owner.uname, :project_id => project.id, :project_name => project.name, :last_commits => last_commits, :branch_name => branch_name, :change_type => change_type} ) end + when 'Gollum::Committer' + actor = User.find_by_uname(record.actor.name) + project_name = record.wiki.path.match(/\/(\w+)\.wiki\.git$/)[1] + project = Project.find_by_name(project_name) + commit_sha = record.commit + #wiki_name = record.wiki.name + + # TODO: Move this logic into Gollum::Wiki + recipients = project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) } + recipients = recipients | [project.owner_id] if project.owner_type == 'User' + + recipients.each do |recipient| + ActivityFeed.create( + :user => User.find(recipient),#record.user, + :kind => 'wiki_new_commit_notification', + :data => {:user_id => actor.id, :user_name => actor.name, :project_id => project.id, :project_name => project_name, :commit_sha => commit_sha} + ) + end end end diff --git a/app/models/issue.rb b/app/models/issue.rb index c8d540735..dfe73c71b 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -16,9 +16,6 @@ class Issue < ActiveRecord::Base after_create :set_serial_id after_create :subscribe_users - #after_create :deliver_new_issue_notification - #after_create :deliver_issue_assign_notification - #after_update :deliver_issue_assign_notification after_update :subscribe_issue_assigned_user def assign_uname @@ -40,11 +37,6 @@ class Issue < ActiveRecord::Base recipients = recipients | [self.user_id] if self.user_id recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User' - # filter by notification settings - recipients = recipients.select do |recipient| - User.find(recipient).notifier.new_issue && User.find(recipient).notifier.can_notify - end - recipients end @@ -55,18 +47,6 @@ class Issue < ActiveRecord::Base self.save! end - #def deliver_new_issue_notification - # recipients = collect_recipient_ids - # recipients.each do |recipient_id| - # recipient = User.find(recipient_id) - # UserMailer.delay.new_issue_notification(self, recipient) if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue - # end - #end - - #def deliver_issue_assign_notification - # UserMailer.delay.issue_assign_notification(self, self.user) if self.user_id_was != self.user_id && self.user.notifier.issue_assign && self.user.notifier.can_notify - #end - def subscribe_users recipients = collect_recipient_ids recipients.each do |recipient_id| diff --git a/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml b/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml new file mode 100644 index 000000000..eb33be273 --- /dev/null +++ b/app/views/activity_feeds/partials/_wiki_new_commit_notification.haml @@ -0,0 +1,2 @@ +%p== User #{ link_to user_name, user_path(user_id) } has been update wiki #{ link_to "history", compare_versions_project_wiki_index_path(project_id, commit_sha) } +%p== Into project #{ link_to(project_name, project_path(project_id)) } From 101fa63514f51ae19538e8631e2a7eda8673bdd9 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 14 Feb 2012 20:46:08 +0400 Subject: [PATCH 08/52] Small ActivityFeed refactoring --- app/controllers/wiki_controller.rb | 2 +- app/models/activity_feed_observer.rb | 26 +++++++++---------- app/models/project.rb | 6 +++++ .../_git_delete_branch_notification.haml | 2 +- .../partials/_git_new_push_notification.haml | 2 +- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 352e0c283..4c1d8854c 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -249,7 +249,7 @@ class WikiController < ApplicationController # @committer.after_commit do |committer, sha1| # here goes callback for notification # end - ActivityFeedObserver.instance.after_create(@committer) + ActivityFeedObserver.instance.after_create(@committer).delay @committer end diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index fff220e5f..d52726325 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -57,7 +57,7 @@ class ActivityFeedObserver < ActiveRecord::Observer branch_name = record.refname.match(/\/([\w\d]+)$/)[1] #user_name = record. - owner = record.owner + #owner = record.owner project = Project.find_by_name(record.repo) last_commits = project.git_repository.repo.log(branch_name, nil).first(3).collect do |commit| #:author => 'author' @@ -65,16 +65,18 @@ class ActivityFeedObserver < ActiveRecord::Observer end if change_type == 'delete' - ActivityFeed.create( - :user => owner, - :kind => 'git_delete_branch_notification', - :data => {:user_id => owner.id, :user_name => owner.uname, :project_id => project.id, :project_name => project.name, :branch_name => branch_name, :change_type => change_type} - ) + kind = 'git_delete_branch_notification' + options = {:project_id => project.id, :project_name => project.name, :branch_name => branch_name, :change_type => change_type} else + kind = 'git_new_push_notification' + options = {:project_id => project.id, :project_name => project.name, :last_commits => last_commits, :branch_name => branch_name, :change_type => change_type} + end + + project.owner_and_admin_ids.each do |recipient| ActivityFeed.create( - :user => owner,#record.user, - :kind => 'git_new_push_notification', - :data => {:user_id => owner.id, :user_name => owner.uname, :project_id => project.id, :project_name => project.name, :last_commits => last_commits, :branch_name => branch_name, :change_type => change_type} + :user => User.find(recipient), + :kind => kind, + :data => options ) end when 'Gollum::Committer' @@ -84,11 +86,7 @@ class ActivityFeedObserver < ActiveRecord::Observer commit_sha = record.commit #wiki_name = record.wiki.name - # TODO: Move this logic into Gollum::Wiki - recipients = project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) } - recipients = recipients | [project.owner_id] if project.owner_type == 'User' - - recipients.each do |recipient| + project.owner_and_admin_ids.each do |recipient| ActivityFeed.create( :user => User.find(recipient),#record.user, :kind => 'wiki_new_commit_notification', diff --git a/app/models/project.rb b/app/models/project.rb index 4d548b39d..9238119fa 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -167,6 +167,12 @@ class Project < ActiveRecord::Base ActivityFeedObserver.instance.after_create rec end + def owner_and_admin_ids + recipients = self.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) } + recipients = recipients | [self.owner_id] if self.owner_type == 'User' + recipients + end + protected def build_path(dir) diff --git a/app/views/activity_feeds/partials/_git_delete_branch_notification.haml b/app/views/activity_feeds/partials/_git_delete_branch_notification.haml index 22794adab..10acc1d61 100644 --- a/app/views/activity_feeds/partials/_git_delete_branch_notification.haml +++ b/app/views/activity_feeds/partials/_git_delete_branch_notification.haml @@ -1,3 +1,3 @@ -%p== User #{ link_to user_name, user_path(user_id) } delete branch #{ branch_name } +%p== Branch #{ branch_name } has been deleted %p== Into project #{ link_to(project_name, project_path(project_id)) } diff --git a/app/views/activity_feeds/partials/_git_new_push_notification.haml b/app/views/activity_feeds/partials/_git_new_push_notification.haml index cad03077f..46a62e834 100644 --- a/app/views/activity_feeds/partials/_git_new_push_notification.haml +++ b/app/views/activity_feeds/partials/_git_new_push_notification.haml @@ -1,4 +1,4 @@ -%p== User #{ link_to user_name, user_path(user_id) } #{ change_type } branch #{ branch_name } +%p== Branch #{ branch_name } has been #{ change_type }d %p== Into project #{ link_to(project_name, project_path(project_id)) } - last_commits.each do |commit| From 28e2494e14e900fa1f3f6c652a33abcdef5ee10e Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 24 Feb 2012 15:26:50 +0400 Subject: [PATCH 09/52] [refs #123] Remove stubs controller --- app/controllers/stub_controller.rb | 24 ------------------------ app/models/activity_feed_observer.rb | 5 ----- 2 files changed, 29 deletions(-) delete mode 100644 app/controllers/stub_controller.rb diff --git a/app/controllers/stub_controller.rb b/app/controllers/stub_controller.rb deleted file mode 100644 index 67a69c51a..000000000 --- a/app/controllers/stub_controller.rb +++ /dev/null @@ -1,24 +0,0 @@ -class StubController < AbstractController::Base - include AbstractController::Rendering - include AbstractController::Layouts - include AbstractController::Helpers - include AbstractController::Translation - include AbstractController::AssetPaths - include ActionController::UrlWriter - - # Uncomment if you want to use helpers - # defined in ApplicationHelper in your views - # helper ApplicationHelper - - # Make sure your controller can find views - self.view_paths = "app/views" - - # You can define custom helper methods to be used in views here - # helper_method :current_admin - # def current_admin; nil; end - - def partial_to_string(partial_name, locals) - render_to_string(partial_name, :locals => locals) - end - -end diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index d52726325..5c4b2a875 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -110,9 +110,4 @@ class ActivityFeedObserver < ActiveRecord::Observer end end - #def (partial_name, locals={}) - # @@stub_controller ||= StubController.new - # @@stub_controller.partial_to_string('activity_feeds/partials/' + partial_name, locals) - #end - end From 395fb812a6e69b343390320a054a2015ed8e74d1 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 24 Feb 2012 15:34:23 +0400 Subject: [PATCH 10/52] [refs #123] Move notifications locales into another file --- config/locales/en.yml | 33 --------------------------------- config/locales/ru.yml | 28 ---------------------------- 2 files changed, 61 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 0bb005ea5..0664293d0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1135,36 +1135,3 @@ en: platform: Platform counter: Downloads - notifications: - subjects: - new_comment_notification: New comment to your task - new_issue_notification: New task added to project - new_user_notification: Registered on project «%{ project_name }» - issue_assign_notification: New task assigned - - bodies: - new_comment_notification: - title: Hello, %{user_name}. - content: To the issue %{issue_link} added a comment. - new_comment_reply_notification: - title: Hello, %{user_name}. - content: Your comment into issue %{issue_link} has been answered. - new_issue_notification: - title: Hello, %{user_name}. - content: To project %{project_link} has been added an issue %{issue_link} - new_user_notification: - title: Hello, %{user_name}. - content: You have been sign up to project «ROSA Build System» and now can sign in. - email: ==Your email %{user_email} - password: ==Your password %{user_password} - issue_assign_notification: - title: Hello, %{user_name}. - content: You have been assigned to issue %{issue_link} - - download: - name: Name - version: Version - distro: Source - platform: Platform - counter: Downloads - diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 0f3cb2ddc..9be3f4015 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -793,31 +793,3 @@ ru: platform: Архитектура counter: Закачки - notifications: - subjects: - new_comment_notification: Новый комментарий к Вашей задаче - new_comment_reply_notification: Новый комментарий к Вашей задаче - new_issue_notification: Новая задача добавлена к проекту - new_user_notification: Регистрация на проекте «%{ project_name }» - issue_assign_notification: Вам назначили задачу - - bodies: - new_comment_notification: - title: Здравствуйте, %{user_name}. - content: К задаче %{issue_link} был добавлен новый комментарий. - new_comment_reply_notification: - title: Здравствуйте, %{user_name}. - content: На Ваш комментарий в задаче %{issue_link} был дан ответ. - new_issue_notification: - title: Здравствуйте, %{user_name}. - content: К проекту %{project_link} была добавлена задача %{issue_link} - new_user_notification: - title: Здравствуйте, %{user_name}. - content: Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему. - email: ==Ваш email %{user_email} - password: ==Ваш пароль %{user_password} - issue_assign_notification: - title: Здравствуйте, %{user_name}. - content: Вам была назначена задача %{issue_link} - new_commit_comment_notification: Новый комментарий к коммиту - invite_approve_notification: Приглашение в ABF From 45905babd815572af835ff653e2dea7e8b71316a Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 24 Feb 2012 15:51:30 +0400 Subject: [PATCH 11/52] [refs #123] Add lost notification locales --- config/locales/notifications.en.yml | 34 +++++++++++++++++++++++++++++ config/locales/notifications.ru.yml | 29 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 config/locales/notifications.en.yml create mode 100644 config/locales/notifications.ru.yml diff --git a/config/locales/notifications.en.yml b/config/locales/notifications.en.yml new file mode 100644 index 000000000..93d15993b --- /dev/null +++ b/config/locales/notifications.en.yml @@ -0,0 +1,34 @@ +notifications: + subjects: + new_comment_notification: New comment to your task + new_issue_notification: New task added to project + new_user_notification: Registered on project «%{ project_name }» + issue_assign_notification: New task assigned + + bodies: + new_comment_notification: + title: Hello, %{user_name}. + content: To the issue %{issue_link} added a comment. + new_comment_reply_notification: + title: Hello, %{user_name}. + content: Your comment into issue %{issue_link} has been answered. + new_issue_notification: + title: Hello, %{user_name}. + content: To project %{project_link} has been added an issue %{issue_link} + new_user_notification: + title: Hello, %{user_name}. + content: You have been sign up to project «ROSA Build System» and now can sign in. + email: ==Your email %{user_email} + password: ==Your password %{user_password} + issue_assign_notification: + title: Hello, %{user_name}. + content: You have been assigned to issue %{issue_link} + + download: + name: Name + version: Version + distro: Source + platform: Platform + counter: Downloads + + diff --git a/config/locales/notifications.ru.yml b/config/locales/notifications.ru.yml new file mode 100644 index 000000000..f4ddbe462 --- /dev/null +++ b/config/locales/notifications.ru.yml @@ -0,0 +1,29 @@ +notifications: + subjects: + new_comment_notification: Новый комментарий к Вашей задаче + new_comment_reply_notification: Новый комментарий к Вашей задаче + new_issue_notification: Новая задача добавлена к проекту + new_user_notification: Регистрация на проекте «%{ project_name }» + issue_assign_notification: Вам назначили задачу + + bodies: + new_comment_notification: + title: Здравствуйте, %{user_name}. + content: К задаче %{issue_link} был добавлен новый комментарий. + new_comment_reply_notification: + title: Здравствуйте, %{user_name}. + content: На Ваш комментарий в задаче %{issue_link} был дан ответ. + new_issue_notification: + title: Здравствуйте, %{user_name}. + content: К проекту %{project_link} была добавлена задача %{issue_link} + new_user_notification: + title: Здравствуйте, %{user_name}. + content: Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему. + email: ==Ваш email %{user_email} + password: ==Ваш пароль %{user_password} + issue_assign_notification: + title: Здравствуйте, %{user_name}. + content: Вам была назначена задача %{issue_link} + new_commit_comment_notification: Новый комментарий к коммиту + invite_approve_notification: Приглашение в ABF + From fd15a39f7a1c56c5e30c86a6cbd3e0a4e84a6261 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 14 Feb 2012 13:50:01 +0200 Subject: [PATCH 12/52] Fix cancan regsiter_requests specs. Temporary fix specs running bug through file rename. Refs #161 --- config/initializers/gollum.rb | 2 +- config/initializers/grit.rb | 2 +- db/schema.rb | 5 ++--- lib/{gollum.rb => gollum1.rb} | 0 lib/{grit.rb => grit1.rb} | 0 spec/factories/register_requests.rb | 13 ++++++++----- 6 files changed, 12 insertions(+), 10 deletions(-) rename lib/{gollum.rb => gollum1.rb} (100%) rename lib/{grit.rb => grit1.rb} (100%) diff --git a/config/initializers/gollum.rb b/config/initializers/gollum.rb index d5c28225a..143ec1535 100644 --- a/config/initializers/gollum.rb +++ b/config/initializers/gollum.rb @@ -1 +1 @@ -require './lib/gollum' +require './lib/gollum1' diff --git a/config/initializers/grit.rb b/config/initializers/grit.rb index 043d42d15..04420c3cb 100644 --- a/config/initializers/grit.rb +++ b/config/initializers/grit.rb @@ -1,3 +1,3 @@ # -*- encoding : utf-8 -*- -require './lib/grit' +require './lib/grit1' diff --git a/db/schema.rb b/db/schema.rb index bf68d3b7c..75b6b173f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -98,12 +98,12 @@ ActiveRecord::Schema.define(:version => 20120210141153) do end create_table "comments", :force => true do |t| + t.string "commentable_id" t.string "commentable_type" t.integer "user_id" t.text "body" t.datetime "created_at" t.datetime "updated_at" - t.decimal "commentable_id", :precision => 50, :scale => 0 end create_table "containers", :force => true do |t| @@ -125,7 +125,6 @@ ActiveRecord::Schema.define(:version => 20120210141153) do t.string "locked_by" t.datetime "created_at" t.datetime "updated_at" - t.string "queue" end add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority" @@ -347,6 +346,7 @@ ActiveRecord::Schema.define(:version => 20120210141153) do t.string "email", :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" + t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" @@ -354,7 +354,6 @@ ActiveRecord::Schema.define(:version => 20120210141153) do t.string "uname" t.string "role" t.string "language", :default => "en" - t.datetime "reset_password_sent_at" t.integer "own_projects_count", :default => 0, :null => false end diff --git a/lib/gollum.rb b/lib/gollum1.rb similarity index 100% rename from lib/gollum.rb rename to lib/gollum1.rb diff --git a/lib/grit.rb b/lib/grit1.rb similarity index 100% rename from lib/grit.rb rename to lib/grit1.rb diff --git a/spec/factories/register_requests.rb b/spec/factories/register_requests.rb index 7fd9c1446..96cc52d02 100644 --- a/spec/factories/register_requests.rb +++ b/spec/factories/register_requests.rb @@ -2,9 +2,12 @@ FactoryGirl.define do factory :register_request do - name "MyString" - email "MyString" - token "MyString" - approved false - end + name "MyString" + email { Factory.next(:email) } + token "MyString" + interest "MyString" + more "MyText" + approved false + rejected false + end end From de9071ae4f623a3ee9707a21552a47f0f8aba401 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 14 Feb 2012 17:52:33 +0600 Subject: [PATCH 13/52] fix collaborator tests --- spec/controllers/collaborators_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/collaborators_controller_spec.rb b/spec/controllers/collaborators_controller_spec.rb index 3457d1aee..c7dcaa4b5 100644 --- a/spec/controllers/collaborators_controller_spec.rb +++ b/spec/controllers/collaborators_controller_spec.rb @@ -69,7 +69,7 @@ describe CollaboratorsController do @user.relations set_session_for(@user) @group = Factory(:group) - @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') end it_should_behave_like 'project admin user' From 1bc4efcdc4814b388b5db9288c730f140fbad951 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Tue, 14 Feb 2012 18:54:18 +0400 Subject: [PATCH 14/52] [issue #64] Fixed encodings bugs --- app/helpers/diff_helper.rb | 2 +- app/views/wiki/_diff_data.html.haml | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 0addc764b..646135d1e 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -8,7 +8,7 @@ module DiffHelper res += "" res += "" - res += diff_display.render(Git::Diff::InlineCallback.new) + res += diff_display.render(Git::Diff::InlineCallback.new).encode_to_default res += "" res += "
" diff --git a/app/views/wiki/_diff_data.html.haml b/app/views/wiki/_diff_data.html.haml index cd8fb1f9a..d4f405c30 100644 --- a/app/views/wiki/_diff_data.html.haml +++ b/app/views/wiki/_diff_data.html.haml @@ -1,8 +1,7 @@ .blob_header - .size= h(diff.deleted_file ? diff.a_path : diff.b_path) - - puts 'in view' - - puts diff.a_path - - puts diff.b_path + .size= h(diff.deleted_file ? diff.a_path : diff.b_path).encode_to_default + - puts diff.a_path.encode_to_default + - puts diff.b_path.encode_to_default .clear .diff_data.highlight From 43c896021ed57f422624dc056905ff71f86fe733 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Tue, 14 Feb 2012 18:54:44 +0400 Subject: [PATCH 15/52] [issue #64] Added possibility to diff and revert last commit --- app/controllers/wiki_controller.rb | 48 +++++++++++++++++++++--------- app/views/wiki/_compare.html.haml | 2 +- lib/gollum/wiki.rb | 10 +++++++ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 4c1d8854c..51dc73dee 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -117,19 +117,37 @@ class WikiController < ApplicationController def compare_wiki if request.post? @versions = params[:versions] || [] - if @versions.size < 2 - redirect_to history_project_wiki_index_path(@project) - else - redirect_to compare_versions_project_wiki_index_path(@project, - sprintf('%s...%s', @versions.last, @versions.first)) + versions_string = case @versions.size + when 1 then @versions.first + when 2 then sprintf('%s...%s', @versions.last, @versions.first) + else begin + redirect_to history_project_wiki_index_path(@project) and return + end end + redirect_to compare_versions_project_wiki_index_path(@project, versions_string) +# if @versions.size < 2 +# redirect_to history_project_wiki_index_path(@project) +# else +# redirect_to compare_versions_project_wiki_index_path(@project, +# sprintf('%s...%s', @versions.last, @versions.first)) +# end elsif request.get? - @versions = params[:versions].split(/\.{2,3}/) - if @versions.size < 2 - redirect_to history_project_wiki_index_path(@project) - return + @versions = params[:versions].split(/\.{2,3}/) || [] + @diffs = case @versions.size + when 1 then @wiki.repo.commit_diff(@versions.first) + when 2 then @wiki.repo.diff(@versions.first, @versions.last) + else begin + redirect_to history_project_wiki_index_path(@project) + return + end end - @diffs = @wiki.repo.diff(@versions.first, @versions.last) + puts 'DIFFS' + puts @diffs.inspect +# if @versions.size < 2 +# redirect_to history_project_wiki_index_path(@project) +# return +# end +# @diffs = @wiki.repo.diff(@versions.first, @versions.last) render :compare else redirect_to project_wiki_path(@project, CGI.escape(@name)) @@ -141,8 +159,9 @@ class WikiController < ApplicationController @page = @wiki.page(@name) sha1 = params[:sha1] sha2 = params[:sha2] + sha2 = nil if params[:sha2] == 'prev' - if @wiki.revert_page(@page, sha1, sha2, {:committer => committer}).commit + if c = @wiki.revert_page(@page, sha1, sha2, {:committer => committer}) and c.commit flash[:notice] = t("flash.wiki.revert_success") redirect_to project_wiki_path(@project, CGI.escape(@name)) else @@ -162,14 +181,15 @@ class WikiController < ApplicationController def revert_wiki sha1 = params[:sha1] sha2 = params[:sha2] - if @wiki.revert_commit(sha1, sha2, {:committer => committer}).commit + sha2 = nil if sha2 == 'prev' + if c = @wiki.revert_commit(sha1, sha2, {:committer => committer}) and c.commit flash[:notice] = t("flash.wiki.revert_success") redirect_to project_wiki_index_path(@project) else sha2, sha1 = sha1, "#{sha1}^" if !sha2 @versions = [sha1, sha2] - diffs = @wiki.repo.diff(@versions.first, @versions.last) - @diffs = [diffs.first] + @diffs = @wiki.repo.diff(@versions.first, @versions.last) +# @diffs = [diffs.first] flash[:error] = t("flash.wiki.patch_does_not_apply") render :compare end diff --git a/app/views/wiki/_compare.html.haml b/app/views/wiki/_compare.html.haml index 0b58242e7..4796ba908 100644 --- a/app/views/wiki/_compare.html.haml +++ b/app/views/wiki/_compare.html.haml @@ -5,7 +5,7 @@ - if action_name != 'revert' %ul.actions %li.minibutton - = form_tag revert_path(@project, @versions[0][0..6], @versions[1][0..6], @name), + = form_tag revert_path(@project, @versions.first[0..6], (@versions.size == 1) ? 'prev' : @versions.last[0..6], @name), :name => "gollum-revert", :id => "gollum-revert-form" do = revert_button if can? :write, @project diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 14e8ae614..1c2b53d27 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -47,6 +47,8 @@ module Gollum multi_commit = false patch = full_reverse_diff_for(page, sha1, sha2) + puts 'patch' + puts patch committer = if obj = commit[:committer] multi_commit = true obj @@ -83,10 +85,18 @@ module Gollum end end + puts 'IN MY RELOADED FILE' + multi_commit ? committer : committer.commit end alias_method_chain :revert_page, :committer + def revert_commit_with_committer(sha1, sha2 = nil, commit = {}) + puts "i'm here" + revert_page_with_committer(nil, sha1, sha2, commit) + end + alias_method_chain :revert_commit, :committer + private def force_grit_encoding(str) From bab3a90155d1b93e7083beccebe60241afa6ce51 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 14 Feb 2012 20:15:52 +0200 Subject: [PATCH 16/52] Apply approved and rejected filters for register requests. Tune abilities. Link to user profile if user have already registered. Refs #174 --- app/controllers/register_requests_controller.rb | 2 +- app/models/ability.rb | 2 ++ app/views/register_requests/index.html.haml | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/register_requests_controller.rb b/app/controllers/register_requests_controller.rb index 74ddd6627..85c915a52 100644 --- a/app/controllers/register_requests_controller.rb +++ b/app/controllers/register_requests_controller.rb @@ -5,7 +5,7 @@ class RegisterRequestsController < ApplicationController before_filter :find_register_request, :only => [:approve, :reject] def index - @register_requests = @register_requests.unprocessed.paginate(:page => params[:page]) + @register_requests = @register_requests.send((params[:scope] || 'unprocessed').to_sym).paginate(:page => params[:page]) end def new diff --git a/app/models/ability.rb b/app/models/ability.rb index 113b50dd1..2b58c1329 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -17,6 +17,8 @@ class Ability cannot :destroy, Subscribe cannot :create, Subscribe cannot :create, RegisterRequest + cannot :approve, RegisterRequest, :approved => true + cannot :reject, RegisterRequest, :rejected => true else # Shared rights between guests and registered users can :forbidden, Platform diff --git a/app/views/register_requests/index.html.haml b/app/views/register_requests/index.html.haml index a860887aa..9df74cd1b 100644 --- a/app/views/register_requests/index.html.haml +++ b/app/views/register_requests/index.html.haml @@ -5,6 +5,10 @@ %li= link_to t("layout.users.new"), new_user_path %li.active= link_to t("layout.users.register_requests"), register_requests_path .content + %div{:style => 'float: right; margin: 20px'} + = link_to t("layout.register_request.approved"), register_requests_path(:scope => :approved) + \| + = link_to t("layout.register_request.rejected"), register_requests_path(:scope => :rejected) %h2.title = t("layout.register_request.list_header") .inner @@ -23,7 +27,8 @@ %tr{:class => cycle("odd", "even")} %td= check_box_tag 'request_ids[]', request.id %td= request.name - %td= request.email + - @user = User.find_by_email(request.email) if request.approved + %td= link_to_if @user, request.email, @user %td= request.interest %td= request.more %td= request.created_at From e1f1e4aff4d71aa474b616d7f5e650e17e8979c2 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 15 Feb 2012 00:50:55 +0600 Subject: [PATCH 17/52] remove broken migration --- db/migrate/20120206194328_remove_orphan_platforms.rb | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 db/migrate/20120206194328_remove_orphan_platforms.rb diff --git a/db/migrate/20120206194328_remove_orphan_platforms.rb b/db/migrate/20120206194328_remove_orphan_platforms.rb deleted file mode 100644 index aa922710a..000000000 --- a/db/migrate/20120206194328_remove_orphan_platforms.rb +++ /dev/null @@ -1,8 +0,0 @@ -class RemoveOrphanPlatforms < ActiveRecord::Migration - def self.up - Platform.all.each {|x| x.destroy unless x.owner.present?} - end - - def self.down - end -end From 5986cd6ddef230aab582d57ad1487c86a0fd679f Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 15 Feb 2012 02:13:52 +0400 Subject: [PATCH 18/52] [issue #64] Removed debug methods and unnecessary comments. --- app/controllers/wiki_controller.rb | 17 ++--------------- lib/gollum/wiki.rb | 5 ----- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 51dc73dee..fd398d1aa 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -121,16 +121,11 @@ class WikiController < ApplicationController when 1 then @versions.first when 2 then sprintf('%s...%s', @versions.last, @versions.first) else begin - redirect_to history_project_wiki_index_path(@project) and return + redirect_to history_project_wiki_index_path(@project) + return end end redirect_to compare_versions_project_wiki_index_path(@project, versions_string) -# if @versions.size < 2 -# redirect_to history_project_wiki_index_path(@project) -# else -# redirect_to compare_versions_project_wiki_index_path(@project, -# sprintf('%s...%s', @versions.last, @versions.first)) -# end elsif request.get? @versions = params[:versions].split(/\.{2,3}/) || [] @diffs = case @versions.size @@ -141,13 +136,6 @@ class WikiController < ApplicationController return end end - puts 'DIFFS' - puts @diffs.inspect -# if @versions.size < 2 -# redirect_to history_project_wiki_index_path(@project) -# return -# end -# @diffs = @wiki.repo.diff(@versions.first, @versions.last) render :compare else redirect_to project_wiki_path(@project, CGI.escape(@name)) @@ -189,7 +177,6 @@ class WikiController < ApplicationController sha2, sha1 = sha1, "#{sha1}^" if !sha2 @versions = [sha1, sha2] @diffs = @wiki.repo.diff(@versions.first, @versions.last) -# @diffs = [diffs.first] flash[:error] = t("flash.wiki.patch_does_not_apply") render :compare end diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 1c2b53d27..70ef08e46 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -47,8 +47,6 @@ module Gollum multi_commit = false patch = full_reverse_diff_for(page, sha1, sha2) - puts 'patch' - puts patch committer = if obj = commit[:committer] multi_commit = true obj @@ -85,14 +83,11 @@ module Gollum end end - puts 'IN MY RELOADED FILE' - multi_commit ? committer : committer.commit end alias_method_chain :revert_page, :committer def revert_commit_with_committer(sha1, sha2 = nil, commit = {}) - puts "i'm here" revert_page_with_committer(nil, sha1, sha2, commit) end alias_method_chain :revert_commit, :committer From aedfc0df8c1aa68eb74489b76701099d0b71b5a3 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 15 Feb 2012 14:36:45 +0400 Subject: [PATCH 19/52] Change nginx log rotate period to 1 day --- config/locales/en.yml | 2 +- config/locales/ru.yml | 2 +- config/schedule.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 0664293d0..9e7871c1f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -59,7 +59,7 @@ en: downloads: title: Downloads statistic - message: Automatically updated every 5 minutes + message: Automatically updated every 24 hours refresh_btn: Refresh auto_build_lists: diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 9be3f4015..3a9fcc2d8 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -63,7 +63,7 @@ ru: downloads: title: Статистика закачек пакетов - message: Обновляется автоматически каждые 5 минут + message: Обновляется автоматически каждые 24 часа refresh_btn: Обновить auto_build_lists: diff --git a/config/schedule.rb b/config/schedule.rb index f966ecc1d..f1d6faa22 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -7,7 +7,7 @@ # runner "Download.parse_and_remove_nginx_log" #end -every 5.minutes do +every 1.day, :at => '5:00' do #rake "sudo_test:projects" runner "Download.rotate_nginx_log" runner "Download.parse_and_remove_nginx_log" From 41861185c0874612b0c50dd6d1ee3ceacc06e190 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 15 Feb 2012 17:12:49 +0600 Subject: [PATCH 20/52] [refs #134] fixed git hook --- app/models/project.rb | 2 +- bin/post-receive-hook_dev | 15 ++++++++++++ bin/post-receive-hook_prod | 15 ++++++++++++ ...120131141651_write_git_hook_to_projects.rb | 13 ----------- lib/tasks/hook.rake | 23 +++++++++++++++++++ 5 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 bin/post-receive-hook_dev create mode 100644 bin/post-receive-hook_prod delete mode 100644 db/migrate/20120131141651_write_git_hook_to_projects.rb create mode 100644 lib/tasks/hook.rake diff --git a/app/models/project.rb b/app/models/project.rb index 9238119fa..56105d2e1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -219,7 +219,7 @@ class Project < ActiveRecord::Base def write_hook hook_file = File.join(path, 'hooks', 'post-receive') - FileUtils.cp(File.join(::Rails.root.to_s, 'lib', 'post-receive-hook'), hook_file) + FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}"), hook_file) #File.chmod(0775, hook_file) # need? rescue Exception # FIXME end diff --git a/bin/post-receive-hook_dev b/bin/post-receive-hook_dev new file mode 100644 index 000000000..b577daa5b --- /dev/null +++ b/bin/post-receive-hook_dev @@ -0,0 +1,15 @@ +#!/bin/bash + +# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly. + +pwd=`pwd` +reponame=`basename $pwd .git` +owner=`basename \`dirname $pwd\`` + +while read oldrev newrev ref +do + newrev_type=$(git cat-file -t $newrev 2> /dev/null) + oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) + + /bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" +done \ No newline at end of file diff --git a/bin/post-receive-hook_prod b/bin/post-receive-hook_prod new file mode 100644 index 000000000..6e9fb4bd8 --- /dev/null +++ b/bin/post-receive-hook_prod @@ -0,0 +1,15 @@ +#!/bin/bash + +# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly. + +pwd=`pwd` +reponame=`basename $pwd .git` +owner=`basename \`dirname $pwd\`` + +while read oldrev newrev ref +do + newrev_type=$(git cat-file -t $newrev 2> /dev/null) + oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) + + /bin/bash -l -c "cd /srv/rosa_build/current && RAILS_ENV=production bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" > /dev/null 2>&1 +done \ No newline at end of file diff --git a/db/migrate/20120131141651_write_git_hook_to_projects.rb b/db/migrate/20120131141651_write_git_hook_to_projects.rb deleted file mode 100644 index d8dded706..000000000 --- a/db/migrate/20120131141651_write_git_hook_to_projects.rb +++ /dev/null @@ -1,13 +0,0 @@ -class WriteGitHookToProjects < ActiveRecord::Migration - def self.up - origin_hook = File.join(::Rails.root.to_s, 'lib', 'post-receive-hook') - Project.all.each do |project| - hook_file = File.join(project.path, 'hooks', 'post-receive') - FileUtils.cp(origin_hook, hook_file) - end - end - - def self.down - Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive')} - end -end diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake new file mode 100644 index 000000000..9b4a0212b --- /dev/null +++ b/lib/tasks/hook.rake @@ -0,0 +1,23 @@ +namespace :hook do + desc "Inserting hook to all repos" + task :install => :environment do + origin_hook = File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}") + say "process.. #{origin_hook}" + count = 0 + Project.all.each do |project| + hook_file = File.join(project.path, 'hooks', 'post-receive') + FileUtils.cp(origin_hook, hook_file) + count = count + 1 + end + say "Done! Writing to #{count.to_s} repo(s)" + end + + desc "remove with git hook" + task :remove => :environment do + say "process.." + count = 0 + Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive'); count = count + 1} + say "Done! Removing from #{count.to_s} repo(s)" + end +end + From 4cdabd555c5ccbf70de580619abc7ca263e3cd10 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 15 Feb 2012 17:23:49 +0600 Subject: [PATCH 21/52] [refs #134] clean --- lib/post-receive-hook | 15 --------------- lib/tasks/hook.rake | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100755 lib/post-receive-hook diff --git a/lib/post-receive-hook b/lib/post-receive-hook deleted file mode 100755 index b577daa5b..000000000 --- a/lib/post-receive-hook +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly. - -pwd=`pwd` -reponame=`basename $pwd .git` -owner=`basename \`dirname $pwd\`` - -while read oldrev newrev ref -do - newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) - - /bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" -done \ No newline at end of file diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index 9b4a0212b..1eeae0774 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -12,7 +12,7 @@ namespace :hook do say "Done! Writing to #{count.to_s} repo(s)" end - desc "remove with git hook" + desc "remove git hook from all repos" task :remove => :environment do say "process.." count = 0 From 3b39738316017c7bad4f02142dc3e36f5d6be2f1 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 15 Feb 2012 19:06:25 +0600 Subject: [PATCH 22/52] [refs #134] rails root --- ...ive-hook_dev => post-receive-hook.partial} | 5 +---- bin/post-receive-hook_prod | 15 ------------- lib/tasks/hook.rake | 22 ++++++++++++++----- 3 files changed, 18 insertions(+), 24 deletions(-) rename bin/{post-receive-hook_dev => post-receive-hook.partial} (51%) delete mode 100644 bin/post-receive-hook_prod diff --git a/bin/post-receive-hook_dev b/bin/post-receive-hook.partial similarity index 51% rename from bin/post-receive-hook_dev rename to bin/post-receive-hook.partial index b577daa5b..b1e39a205 100644 --- a/bin/post-receive-hook_dev +++ b/bin/post-receive-hook.partial @@ -9,7 +9,4 @@ owner=`basename \`dirname $pwd\`` while read oldrev newrev ref do newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) - - /bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" -done \ No newline at end of file + oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) \ No newline at end of file diff --git a/bin/post-receive-hook_prod b/bin/post-receive-hook_prod deleted file mode 100644 index 6e9fb4bd8..000000000 --- a/bin/post-receive-hook_prod +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly. - -pwd=`pwd` -reponame=`basename $pwd .git` -owner=`basename \`dirname $pwd\`` - -while read oldrev newrev ref -do - newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) - - /bin/bash -l -c "cd /srv/rosa_build/current && RAILS_ENV=production bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" > /dev/null 2>&1 -done \ No newline at end of file diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index 1eeae0774..baf1e458a 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -1,15 +1,28 @@ namespace :hook do desc "Inserting hook to all repos" task :install => :environment do - origin_hook = File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}") - say "process.. #{origin_hook}" + is_production = ENV['RAILS_ENV'] == 'production' + say "Generate temporary file..." + hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook") + FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook) + File.open(hook, 'a') do |f| + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && \ + bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s << " > /dev/null 2>&1" if is_production + s << "\ndone\n" + f.write(s) + end + + say "Install process.." count = 0 Project.all.each do |project| hook_file = File.join(project.path, 'hooks', 'post-receive') - FileUtils.cp(origin_hook, hook_file) + FileUtils.cp(hook, hook_file) count = count + 1 end - say "Done! Writing to #{count.to_s} repo(s)" + say "Writing to #{count.to_s} repo(s)" + say "Removing temporary file" + FileUtils.rm_rf(hook) end desc "remove git hook from all repos" @@ -20,4 +33,3 @@ namespace :hook do say "Done! Removing from #{count.to_s} repo(s)" end end - From f7b496bb39d4df977b121814bb29d363c9604241 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 15 Feb 2012 20:30:56 +0400 Subject: [PATCH 23/52] Some fixes: * Changed default visibility to personal platforms to 'open' * Changed 'Erase' button to simple link in comments partial * Probably added domain name to links in mail notifications * Fixed protocol in repo links form 'http' to 'https' --- app/helpers/projects_helper.rb | 4 ++-- app/views/comments/_list.html.haml | 3 ++- app/views/user_mailer/issue_assign_notification.en.haml | 2 +- app/views/user_mailer/issue_assign_notification.ru.haml | 2 +- app/views/user_mailer/new_comment_notification.en.haml | 8 ++++---- app/views/user_mailer/new_comment_notification.ru.haml | 6 +++--- .../user_mailer/new_comment_reply_notification.en.haml | 4 ++-- app/views/user_mailer/new_issue_notification.en.haml | 2 +- app/views/user_mailer/new_issue_notification.ru.haml | 2 +- lib/modules/models/personal_repository.rb | 2 +- 10 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 06c4de5b0..827e4cda0 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -2,9 +2,9 @@ module ProjectsHelper def git_repo_url(name) if current_user - "http://#{current_user.uname}@#{request.host_with_port}/#{name}.git" + "https://#{current_user.uname}@#{request.host_with_port}/#{name}.git" else - "http://#{request.host_with_port}/#{name}.git" + "https://#{request.host_with_port}/#{name}.git" end end end diff --git a/app/views/comments/_list.html.haml b/app/views/comments/_list.html.haml index 25e6e13ee..c2aa719bb 100644 --- a/app/views/comments/_list.html.haml +++ b/app/views/comments/_list.html.haml @@ -20,7 +20,8 @@ - edit_path = edit_project_commit_comment_path(project, commentable, comment) - delete_path = project_commit_comment_path(project, commentable, comment) = link_to t("layout.edit"), edit_path if can? :update, comment - = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), delete_path, :method => "delete", :class => "button", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment + =# link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), delete_path, :method => "delete", :class => "button", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment + = link_to t("layout.delete"), delete_path, :method => "delete", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment .block .content diff --git a/app/views/user_mailer/issue_assign_notification.en.haml b/app/views/user_mailer/issue_assign_notification.en.haml index 83c33e8ac..bc52f31d2 100644 --- a/app/views/user_mailer/issue_assign_notification.en.haml +++ b/app/views/user_mailer/issue_assign_notification.en.haml @@ -1,7 +1,7 @@ %p== Hello, #{@user.name}. -%p You have been assigned to issue #{ link_to @issue.title, [@issue.project, @issue] } +%p You have been assigned to issue #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/issue_assign_notification.ru.haml b/app/views/user_mailer/issue_assign_notification.ru.haml index a6615d3eb..db96619f7 100644 --- a/app/views/user_mailer/issue_assign_notification.ru.haml +++ b/app/views/user_mailer/issue_assign_notification.ru.haml @@ -1,7 +1,7 @@ %p== Здравствуйте, #{@user.name}. -%p Вам была назначена задача #{ link_to @issue.title, [@issue.project, @issue] } +%p Вам была назначена задача #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Команда поддержки «ROSA Build System» diff --git a/app/views/user_mailer/new_comment_notification.en.haml b/app/views/user_mailer/new_comment_notification.en.haml index 2c7fb66cb..99c1a4bfe 100644 --- a/app/views/user_mailer/new_comment_notification.en.haml +++ b/app/views/user_mailer/new_comment_notification.en.haml @@ -1,14 +1,14 @@ %p== Hello, #{@user.name}. - if @comment.commentable.class == Issue - - link = link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] + - link = link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) - object = 'issue' - elsif @comment.commentable.class == Grit::Commit - - link = link_to @comment.commentable.message, commit_path(@comment.project, @comment.commentable_id) + - link = link_to @comment.commentable.message, commit_url(@comment.project, @comment.commentable_id) - object = 'commit' -%p #{ link_to @comment.user.uname, user_path(@comment.user)} added new comment to #{object} #{link}. +%p #{ link_to @comment.user.uname, user_url(@comment.user)} added new comment to #{object} #{link}. %p "#{ @comment.body }" -%p== Support team «ROSA Build System» \ No newline at end of file +%p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/new_comment_notification.ru.haml b/app/views/user_mailer/new_comment_notification.ru.haml index d1c0734dd..1dcab28a8 100644 --- a/app/views/user_mailer/new_comment_notification.ru.haml +++ b/app/views/user_mailer/new_comment_notification.ru.haml @@ -1,12 +1,12 @@ %p== Здравствуйте, #{@user.name}. - if @comment.commentable.class == Issue - - link = link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] + - link = link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) - object = 'задаче' - elsif @comment.commentable.class == Grit::Commit - - link = link_to @comment.commentable.message, commit_path(@comment.project, @comment.commentable_id) + - link = link_to @comment.commentable.message, commit_url(@comment.project, @comment.commentable_id) - object = 'коммиту' -%p #{ link_to @comment.user.uname, user_path(@comment.user)} добавил комментарий к #{object} #{link}. +%p #{ link_to @comment.user.uname, user_url(@comment.user)} добавил комментарий к #{object} #{link}. %p "#{ @comment.body }" diff --git a/app/views/user_mailer/new_comment_reply_notification.en.haml b/app/views/user_mailer/new_comment_reply_notification.en.haml index 9324062f2..b2838b2e0 100644 --- a/app/views/user_mailer/new_comment_reply_notification.en.haml +++ b/app/views/user_mailer/new_comment_reply_notification.en.haml @@ -1,7 +1,7 @@ %p== Hello, #{@user.name}. - -%p Your comment into issue #{ link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] } has been answered. +- #TODO hmm... this need to be refactored. +%p Your comment into issue #{ link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) } has been answered. %p "#{ @comment.body }" diff --git a/app/views/user_mailer/new_issue_notification.en.haml b/app/views/user_mailer/new_issue_notification.en.haml index f814fa617..7ddda0017 100644 --- a/app/views/user_mailer/new_issue_notification.en.haml +++ b/app/views/user_mailer/new_issue_notification.en.haml @@ -1,7 +1,7 @@ %p== Hello, #{@user.name}. -%p To project #{ link_to @issue.project.name, project_path(@issue.project) } has been added an issue #{ link_to @issue.title, [@issue.project, @issue] } +%p To project #{ link_to @issue.project.name, project_url(@issue.project) } has been added an issue #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/new_issue_notification.ru.haml b/app/views/user_mailer/new_issue_notification.ru.haml index 3a2604cfb..4255c06c2 100644 --- a/app/views/user_mailer/new_issue_notification.ru.haml +++ b/app/views/user_mailer/new_issue_notification.ru.haml @@ -1,7 +1,7 @@ %p== Здравствуйте, #{@user.name}. -%p К проекту #{ link_to @issue.project.name, project_path(@issue.project) } была добавлена задача #{ link_to @issue.title, [@issue.project, @issue] } +%p К проекту #{ link_to @issue.project.name, project_url(@issue.project) } была добавлена задача #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Команда поддержки «ROSA Build System» diff --git a/lib/modules/models/personal_repository.rb b/lib/modules/models/personal_repository.rb index 8ee4fd3d8..58f8f1805 100644 --- a/lib/modules/models/personal_repository.rb +++ b/lib/modules/models/personal_repository.rb @@ -16,7 +16,7 @@ module Modules pl.description = "#{self.uname}_personal" pl.platform_type = 'personal' pl.distrib_type = APP_CONFIG['distr_types'].first - pl.visibility = 'hidden' + pl.visibility = 'open' pl.save! rep = pl.repositories.build From 50ad3edab489aaaa189152d1ed9e212c25dd5648 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 15 Feb 2012 22:02:47 +0400 Subject: [PATCH 24/52] Fixed default host in mailer --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index fe08b9089..85f7a95ef 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -37,7 +37,7 @@ Rosa::Application.configure do # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - config.action_mailer.default_url_options = { :host => 'rosa-build.rosalab.ru' } + config.action_mailer.default_url_options = { :host => 'abf.rosalinux.ru' } # Enable threaded mode # config.threadsafe! From a809a4c11612bef62a1732488da982094819f6fe Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 16 Feb 2012 21:08:08 +0600 Subject: [PATCH 25/52] [refs #134] fixed bug with new project --- app/models/project.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 56105d2e1..adc851079 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -218,9 +218,20 @@ class Project < ActiveRecord::Base end def write_hook + is_production = ENV['RAILS_ENV'] == 'production' + hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook") + FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook) + File.open(hook, 'a') do |f| + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s << " > /dev/null 2>&1" if is_production + s << "\ndone\n" + f.write(s) + end + hook_file = File.join(path, 'hooks', 'post-receive') - FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}"), hook_file) - #File.chmod(0775, hook_file) # need? + FileUtils.cp(hook, hook_file) + FileUtils.rm_rf(hook) + rescue Exception # FIXME end end From 30f47a1748812823596b23281a6a5736d13ef781 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 16 Feb 2012 22:29:41 +0600 Subject: [PATCH 26/52] [refs #134] lost env! --- app/models/project.rb | 2 +- lib/tasks/hook.rake | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index adc851079..b26f2ee06 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -222,7 +222,7 @@ class Project < ActiveRecord::Base hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook") FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook) File.open(hook, 'a') do |f| - s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" s << " > /dev/null 2>&1" if is_production s << "\ndone\n" f.write(s) diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index baf1e458a..67c5e8140 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -6,8 +6,7 @@ namespace :hook do hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook") FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook) File.open(hook, 'a') do |f| - s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && \ - bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" s << " > /dev/null 2>&1" if is_production s << "\ndone\n" f.write(s) From 4daf50b34ee7eb0cdccdd4426ea2c0896a46726a Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 16 Feb 2012 20:23:33 +0200 Subject: [PATCH 27/52] Change blank repo message. Refs #196 --- config/locales/en.yml | 2 +- config/locales/ru.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 9e7871c1f..626fec74f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -513,7 +513,7 @@ en: list_header: Event log repositories: - empty: Empty repository + empty: "Repository is still empty. You need to wait some time if you have forked or imported" source: Source commits: Commits commit_diff_too_big: Sorry, commit too big! diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 3a9fcc2d8..3f4cb1f08 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -365,7 +365,7 @@ ru: git: repositories: - empty: Пустой репозиторий + empty: "Репозиторий пока пустой. Если форкнули или импортировали, необходимо немного подожать" source: Source commits: Commits commit_diff_too_big: Извините, коммит слишком большой! From f4f542811d70d89b8cc56485dbe38bfa7073d223 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Thu, 16 Feb 2012 23:08:54 +0400 Subject: [PATCH 28/52] [Refs#196] Update text message for empty text[ru] --- config/locales/ru.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 3f4cb1f08..1567e590a 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -365,7 +365,7 @@ ru: git: repositories: - empty: "Репозиторий пока пустой. Если форкнули или импортировали, необходимо немного подожать" + empty: "Репозиторий пуст. Если вы клонировали(Fork) проект или импортировали пакет, данные скоро появятся" source: Source commits: Commits commit_diff_too_big: Извините, коммит слишком большой! From e93d5c08b0304d519d90fd02a35d175bde48d2e1 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Thu, 16 Feb 2012 23:10:58 +0400 Subject: [PATCH 29/52] [Refs#196] Update text message for empty text[en] --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 626fec74f..368e2c04d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -513,7 +513,7 @@ en: list_header: Event log repositories: - empty: "Repository is still empty. You need to wait some time if you have forked or imported" + empty: "Repository is empty. You need to wait some time if you have forked project or imported package" source: Source commits: Commits commit_diff_too_big: Sorry, commit too big! From c972968338b5c9ba0dca4b3749d4a5c9c79b4731 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 17 Feb 2012 15:22:55 +0600 Subject: [PATCH 30/52] [refs #134] some hook task improvements --- lib/tasks/hook.rake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index 67c5e8140..d41bbafdb 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -14,7 +14,8 @@ namespace :hook do say "Install process.." count = 0 - Project.all.each do |project| + projects = ENV['project_id'] ? Project.where(:id => eval(ENV['project_id'])) : Project + projects.where('created_at >= ?', Time.now.ago(ENV['period'] ? eval(ENV['period']) : 100.years)).each do |project| hook_file = File.join(project.path, 'hooks', 'post-receive') FileUtils.cp(hook, hook_file) count = count + 1 @@ -28,7 +29,11 @@ namespace :hook do task :remove => :environment do say "process.." count = 0 - Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive'); count = count + 1} + projects = ENV['project_id'] ? Project.where(:id => eval(ENV['project_id'])) : Project + projects.where('created_at >= ?', Time.now.ago(ENV['period'] ? eval(ENV['period']) : 100.years)).each do |project| + FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive') + count = count + 1 + end say "Done! Removing from #{count.to_s} repo(s)" end end From 432b6ac27604257d2e48eec45e6c6e4b8736a335 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 17 Feb 2012 16:32:03 +0200 Subject: [PATCH 31/52] Refactor bluepill deploy recipies. Restart DJ through bluepill. Refs #196 --- config/deploy.rb | 3 ++- config/production.pill | 1 + lib/recipes/bluepill.rb | 49 +++++++++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index c67c374a3..3dc198504 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -62,8 +62,9 @@ namespace :deploy do end after "deploy:update_code", "deploy:symlink_all", "deploy:migrate" -after "deploy:restart","bluepill:stop", "delayed_job:restart", "deploy:cleanup", "bluepill:start" after "deploy:setup", "deploy:symlink_pids" +after "deploy:restart","bluepill:processes:restart_dj" # "bluepill:restart" +after "deploy:restart", "deploy:cleanup" require 'cape' namespace :rake_tasks do diff --git a/config/production.pill b/config/production.pill index ff49759fc..3199e382a 100644 --- a/config/production.pill +++ b/config/production.pill @@ -11,6 +11,7 @@ Bluepill.application(app_name) do |app| process.start_command = "/usr/bin/env RAILS_ENV=production script/delayed_job start" process.stop_command = "/usr/bin/env RAILS_ENV=production script/delayed_job stop" + process.restart_command = "/usr/bin/env RAILS_ENV=production script/delayed_job restart" process.pid_file = File.join(app.working_dir, 'tmp', 'pids', 'delayed_job.pid') end diff --git a/lib/recipes/bluepill.rb b/lib/recipes/bluepill.rb index a84ff7ecb..969728664 100644 --- a/lib/recipes/bluepill.rb +++ b/lib/recipes/bluepill.rb @@ -3,29 +3,46 @@ Capistrano::Configuration.instance(:must_exist).load do namespace :bluepill do set(:bluepill_binary) {"bundle exec bluepill --no-privileged"} - desc "Load bluepill configuration and start it" + namespace :processes do + desc "Start processes that bluepill is monitoring" + task :start, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} start" + end + + desc "Stop processes that bluepill is monitoring" + task :stop, :roles => [:app], :on_error => :continue do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} stop" + end + + desc "Restart processes that bluepill is monitoring" + task :restart, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart" + end + + desc "Prints bluepills monitored processes statuses" + task :status, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} status" + end + + desc "Restart DJ process" + task :restart_dj, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart delayed_job" + end + end + + desc "Start a bluepill process and load a config" task :start, :roles => [:app] do run "cd #{fetch :current_path} && #{try_sudo} APP_NAME=#{fetch :application} #{bluepill_binary} load config/production.pill" end - desc "Stop processes that bluepill is monitoring" - task :stop, :roles => [:app], :on_error => :continue do - run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} stop" - end - - task :restart, :roles => [:app] do - # run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart" - stop; quit; start - end - - desc "Stop processes that bluepill is monitoring and quit bluepill" - task :quit, :roles => [:app] do + desc "Quit bluepill" + task :stop, :roles => [:app] do run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} quit" end - desc "Prints bluepills monitored processes statuses" - task :status, :roles => [:app] do - run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} status" + desc "Completely restart bluepill and monitored services" + task :restart, :roles => [:app] do + processes.stop; stop; start end end end From 5e58ec9e59430fa0d1479293403867b48ae9e994 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 21 Feb 2012 01:13:05 +0200 Subject: [PATCH 32/52] Delegate all repo abilities to platform. Remove repository owner and relations. Fix templates and specs. Refactor and code cleanup. Refs #205 --- .../personal_repositories_controller.rb | 2 +- app/controllers/repositories_controller.rb | 1 - app/models/ability.rb | 14 +++--- app/models/group.rb | 21 ++++---- app/models/relation.rb | 7 +-- app/models/repository.rb | 50 ++++++------------- app/models/user.rb | 15 +++--- .../projects_list.html.haml | 10 ---- .../personal_repositories/show.html.haml | 6 --- .../repositories/projects_list.html.haml | 5 -- app/views/repositories/show.html.haml | 5 -- ...0120220185458_remove_repositories_owner.rb | 12 +++++ db/schema.rb | 4 +- lib/modules/models/personal_repository.rb | 1 - .../collaborators_controller_spec.rb | 1 + spec/controllers/groups_controller_spec.rb | 1 + spec/controllers/members_controller_spec.rb | 1 + .../personal_repositories_controller_spec.rb | 5 +- .../repositories_controller_spec.rb | 6 +-- spec/factories/repository_factory.rb | 16 ++---- spec/models/cancan_spec.rb | 11 ++-- spec/models/comment_for_commit_spec.rb | 1 + spec/models/comment_spec.rb | 1 + spec/models/repository_spec.rb | 11 ++-- spec/models/subscribe_spec.rb | 1 + 25 files changed, 77 insertions(+), 131 deletions(-) create mode 100644 db/migrate/20120220185458_remove_repositories_owner.rb diff --git a/app/controllers/personal_repositories_controller.rb b/app/controllers/personal_repositories_controller.rb index c76c21623..122ed928a 100644 --- a/app/controllers/personal_repositories_controller.rb +++ b/app/controllers/personal_repositories_controller.rb @@ -12,7 +12,7 @@ class PersonalRepositoriesController < ApplicationController else @projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30 end - @user = @repository.owner + @user = @repository.platform.owner @urpmi_commands = @repository.platform.urpmi_list(request.host) end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 317683699..693be6034 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -42,7 +42,6 @@ class RepositoriesController < ApplicationController def create @repository = Repository.new(params[:repository]) @repository.platform_id = params[:platform_id] - @repository.owner = get_owner if @repository.save flash[:notice] = t('flash.repository.saved') redirect_to @repositories_path diff --git a/app/models/ability.rb b/app/models/ability.rb index 2b58c1329..8a6ac63a4 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -66,18 +66,16 @@ class Ability can :read, Platform, :owner_type => 'User', :owner_id => user.id can :read, Platform, :owner_type => 'Group', :owner_id => user.group_ids can(:read, Platform, read_relations_for('platforms')) {|platform| local_reader? platform} - can(:update, Platform) {|platform| local_admin? platform} + can([:update, :build_all], Platform) {|platform| local_admin? platform} can([:freeze, :unfreeze, :destroy], Platform) {|platform| owner? platform} can :autocomplete_user_uname, Platform - # TODO delegate to platform? can :read, Repository, :platform => {:visibility => 'open'} - can :read, Repository, :owner_type => 'User', :owner_id => user.id - can :read, Repository, :owner_type => 'Group', :owner_id => user.group_ids - can(:read, Repository, read_relations_for('repositories')) {|repository| local_reader? repository} - can(:create, Repository) {|repository| local_admin? repository.platform} - can([:update, :add_project, :remove_project], Repository) {|repository| local_admin? repository} - can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository} + can :read, Repository, :platform => {:owner_type => 'User', :owner_id => user.id} + can :read, Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} + can(:read, Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} + can([:create, :update, :projects_list, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform} + can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id} can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} diff --git a/app/models/group.rb b/app/models/group.rb index c68147305..a7d96dcc7 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -2,16 +2,16 @@ class Group < ActiveRecord::Base belongs_to :owner, :class_name => 'User' - has_many :own_projects, :as => :owner, :class_name => 'Project' - + has_many :relations, :as => :object, :dependent => :destroy has_many :objects, :as => :target, :class_name => 'Relation' has_many :targets, :as => :object, :class_name => 'Relation' has_many :members, :through => :objects, :source => :object, :source_type => 'User', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true - has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true, :dependent => :destroy - has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true - has_many :relations, :as => :object, :dependent => :destroy + has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true + + has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy + has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy validates :name, :owner, :presence => true validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } @@ -26,11 +26,12 @@ class Group < ActiveRecord::Base after_initialize lambda {|r| r.name ||= r.uname } # default include Modules::Models::PersonalRepository -# include Modules::Models::Owner + # include Modules::Models::Owner protected - def add_owner_to_members - Relation.create_with_role(self.owner, self, 'admin') -# members << self.owner if !members.exists?(:id => self.owner.id) - end + + def add_owner_to_members + Relation.create_with_role(self.owner, self, 'admin') + # members << self.owner if !members.exists?(:id => self.owner.id) + end end diff --git a/app/models/relation.rb b/app/models/relation.rb index 59c31d29d..6847b097b 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -22,7 +22,8 @@ class Relation < ActiveRecord::Base end protected - def add_default_role - self.role = ROLES.first if role.nil? || role.empty? - end + + def add_default_role + self.role = ROLES.first if role.nil? || role.empty? + end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 379d3deac..f5c7d4c13 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,27 +1,19 @@ # -*- encoding : utf-8 -*- class Repository < ActiveRecord::Base belongs_to :platform - belongs_to :owner, :polymorphic => true has_many :projects, :through => :project_to_repositories #, :dependent => :destroy has_many :project_to_repositories, :validate => true, :dependent => :destroy - has_many :relations, :as => :target, :dependent => :destroy - has_many :objects, :as => :target, :class_name => 'Relation', :dependent => :destroy - has_many :members, :through => :objects, :source => :object, :source_type => 'User' - has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' - validates :description, :uniqueness => {:scope => :platform_id}, :presence => true validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ } - # validates :platform_id, :presence => true # if you uncomment this platform clone will not work scope :recent, order("name ASC") before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy - after_create :add_admin_relations - attr_accessible :description, :name #, :platform_id + attr_accessible :description, :name def full_clone(attrs) # owner clone.tap do |c| # dup @@ -31,8 +23,6 @@ class Repository < ActiveRecord::Base end end - include Modules::Models::Owner - class << self def build_stub(platform) rep = Repository.new @@ -43,31 +33,21 @@ class Repository < ActiveRecord::Base protected - def xml_rpc_create - result = BuildServer.create_repo name, platform.name - if result == BuildServer::SUCCESS - return true - else - raise "Failed to create repository #{name} inside platform #{platform.name} with code #{result}." - end + def xml_rpc_create + result = BuildServer.create_repo name, platform.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to create repository #{name} inside platform #{platform.name} with code #{result}." end + end - def xml_rpc_destroy - result = BuildServer.delete_repo name, platform.name - if result == BuildServer::SUCCESS - return true - else - raise "Failed to delete repository #{name} inside platform #{platform.name} with code #{result}." - end - end - - def add_admin_relations - platform.relations.where(:role => 'admin').each do |rel| - if !relations.exists?(:role => 'admin', :object_type => rel.object_type, :object_id => rel.object_id) && rel.object != owner - r = relations.build(:role => 'admin', :object_type => rel.object_type) - r.object_id = rel.object_id - r.save - end - end + def xml_rpc_destroy + result = BuildServer.delete_repo name, platform.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to delete repository #{name} inside platform #{platform.name} with code #{result}." end + end end diff --git a/app/models/user.rb b/app/models/user.rb index 25e8dab2f..aeb0729cd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,22 +13,19 @@ class User < ActiveRecord::Base has_many :authentications, :dependent => :destroy has_many :build_lists, :dependent => :destroy + has_many :subscribes, :foreign_key => :user_id, :dependent => :destroy + has_many :comments, :dependent => :destroy has_many :relations, :as => :object, :dependent => :destroy has_many :targets, :as => :object, :class_name => 'Relation' - has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy - has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group' - has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy - has_many :own_repositories, :as => :owner, :class_name => 'Repository', :dependent => :destroy - - has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true + has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true - has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true - has_many :subscribes, :foreign_key => :user_id, :dependent => :destroy - has_many :comments, :dependent => :destroy + has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy + has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group', :dependent => :destroy + has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy include Modules::Models::PersonalRepository diff --git a/app/views/personal_repositories/projects_list.html.haml b/app/views/personal_repositories/projects_list.html.haml index 4766fcb0b..2f3d8c3c0 100644 --- a/app/views/personal_repositories/projects_list.html.haml +++ b/app/views/personal_repositories/projects_list.html.haml @@ -20,21 +20,11 @@ = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.name, url_for(@repository.platform) - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.name, url_for(@repository.owner) %p %b = t("activerecord.attributes.platform.visibility") \: = @repository.platform.visibility - %p - %b - = t("activerecord.attributes.repository.platform") - \: - = link_to @repository.platform.name, platform_path(@platform) .wat-cf = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") diff --git a/app/views/personal_repositories/show.html.haml b/app/views/personal_repositories/show.html.haml index f8f346094..c40d3a1d5 100644 --- a/app/views/personal_repositories/show.html.haml +++ b/app/views/personal_repositories/show.html.haml @@ -6,12 +6,6 @@ %li= link_to t("layout.personal_repositories.private_users"), platform_private_users_path(@repository.platform) if @repository.platform.hidden? .content .inner - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.name, url_for(@repository.owner) - = render 'shared/urpmi_list', :urpmi_commands => @urpmi_commands .wat-cf =# link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") diff --git a/app/views/repositories/projects_list.html.haml b/app/views/repositories/projects_list.html.haml index af5a9a1a9..d9ca336d8 100644 --- a/app/views/repositories/projects_list.html.haml +++ b/app/views/repositories/projects_list.html.haml @@ -21,11 +21,6 @@ = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.description, url_for(@repository.platform) - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.uname, url_for(@repository.owner) .wat-cf = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") diff --git a/app/views/repositories/show.html.haml b/app/views/repositories/show.html.haml index 72ab6577a..7e23d2b0d 100644 --- a/app/views/repositories/show.html.haml +++ b/app/views/repositories/show.html.haml @@ -21,11 +21,6 @@ = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.description, url_for(@repository.platform) - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.try(:name), url_for(@repository.owner) .wat-cf = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") if can? :destroy, @repository diff --git a/db/migrate/20120220185458_remove_repositories_owner.rb b/db/migrate/20120220185458_remove_repositories_owner.rb new file mode 100644 index 000000000..88c85a855 --- /dev/null +++ b/db/migrate/20120220185458_remove_repositories_owner.rb @@ -0,0 +1,12 @@ +class RemoveRepositoriesOwner < ActiveRecord::Migration + def self.up + remove_column :repositories, :owner_id + remove_column :repositories, :owner_type + Relation.delete_all(:target_type => 'Repository') + end + + def self.down + add_column :repositories, :owner_id, :integer + add_column :repositories, :owner_type, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 75b6b173f..e99351bdd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120210141153) do +ActiveRecord::Schema.define(:version => 20120220185458) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -302,8 +302,6 @@ ActiveRecord::Schema.define(:version => 20120210141153) do t.datetime "created_at" t.datetime "updated_at" t.string "name", :null => false - t.integer "owner_id" - t.string "owner_type" end create_table "rpms", :force => true do |t| diff --git a/lib/modules/models/personal_repository.rb b/lib/modules/models/personal_repository.rb index 58f8f1805..5b903ecae 100644 --- a/lib/modules/models/personal_repository.rb +++ b/lib/modules/models/personal_repository.rb @@ -20,7 +20,6 @@ module Modules pl.save! rep = pl.repositories.build - rep.owner = pl.owner rep.name = 'main' rep.description = 'main' rep.save! diff --git a/spec/controllers/collaborators_controller_spec.rb b/spec/controllers/collaborators_controller_spec.rb index c7dcaa4b5..858bd3c05 100644 --- a/spec/controllers/collaborators_controller_spec.rb +++ b/spec/controllers/collaborators_controller_spec.rb @@ -37,6 +37,7 @@ end describe CollaboratorsController do before(:each) do + stub_rsync_methods @project = Factory(:project) @another_user = Factory(:user) @update_params = {:user => {:read => {@another_user.id => '1'}}} diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 2ccf820b3..4238babf8 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe GroupsController do before(:each) do + stub_rsync_methods @group = Factory(:group) @another_user = Factory(:user) @create_params = {:group => {:name => 'grp1', :uname => 'un_grp1'}} diff --git a/spec/controllers/members_controller_spec.rb b/spec/controllers/members_controller_spec.rb index 512bbc73c..ab8ab5fbe 100644 --- a/spec/controllers/members_controller_spec.rb +++ b/spec/controllers/members_controller_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe MembersController do before(:each) do + stub_rsync_methods @group = Factory(:group) @user = @group.owner set_session_for @user diff --git a/spec/controllers/personal_repositories_controller_spec.rb b/spec/controllers/personal_repositories_controller_spec.rb index 50ff6f03f..6e020d61e 100644 --- a/spec/controllers/personal_repositories_controller_spec.rb +++ b/spec/controllers/personal_repositories_controller_spec.rb @@ -92,9 +92,6 @@ describe PersonalRepositoriesController do @project.update_attribute(:owner, @user) - @repository.update_attribute(:owner, @user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') - @repository.platform.update_attribute(:owner, @user) @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') end @@ -108,7 +105,7 @@ describe PersonalRepositoriesController do before(:each) do @user = Factory(:user) set_session_for(@user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') end it_should_behave_like 'personal repository viewer' diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 935de2e40..422fb5128 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -79,8 +79,8 @@ describe RepositoriesController do before(:each) do @user = Factory(:user) set_session_for(@user) - @repository.update_attribute(:owner, @user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @repository.platform.update_attribute(:owner, @user) + @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') end it_should_behave_like 'repository user with owner rights' @@ -90,7 +90,7 @@ describe RepositoriesController do before(:each) do @user = Factory(:user) set_session_for(@user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') end it_should_behave_like 'repository user with reader rights' diff --git a/spec/factories/repository_factory.rb b/spec/factories/repository_factory.rb index 2188bc17e..4af755b28 100644 --- a/spec/factories/repository_factory.rb +++ b/spec/factories/repository_factory.rb @@ -3,18 +3,12 @@ Factory.define(:repository) do |p| p.description { Factory.next(:string) } p.name { Factory.next(:unixname) } p.association :platform, :factory => :platform - p.association :owner, :factory => :user end -Factory.define(:personal_repository, :class => Repository) do |p| - p.description { Factory.next(:string) } - p.name { Factory.next(:unixname) } - p.association :platform, :factory => :platform - p.association :owner, :factory => :user - - p.after_create { |rep| - rep.platform.platform_type = 'personal' - rep.platform.visibility = 'hidden' - rep.platform.save! +Factory.define(:personal_repository, :parent => :repository) do |p| + p.after_create {|r| + r.platform.platform_type = 'personal' + r.platform.visibility = 'hidden' + r.platform.save! } end diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index 597d5dd38..248a502d6 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -278,24 +278,19 @@ describe CanCan do context 'with owner rights' do before(:each) do - @repository.update_attribute(:owner, @user) + @repository.platform.update_attribute(:owner, @user) end - [:read, :update, :destroy, :add_project, :remove_project, :change_visibility, :settings].each do |action| + [:read, :create, :update, :destroy, :add_project, :remove_project, :change_visibility, :settings].each do |action| it "should be able to #{action} repository" do @ability.should be_able_to(action, @repository) end end - - it do - @repository.platform.update_attribute(:owner, @user) - @ability.should be_able_to(:create, @repository) - end end context 'with read rights' do before(:each) do - @repository.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader') + @repository.platform.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader') end it "should be able to read repository" do diff --git a/spec/models/comment_for_commit_spec.rb b/spec/models/comment_for_commit_spec.rb index 6f693d03e..446131e5e 100644 --- a/spec/models/comment_for_commit_spec.rb +++ b/spec/models/comment_for_commit_spec.rb @@ -21,6 +21,7 @@ def set_comments_data_for_commit end describe Comment do + before { stub_rsync_methods } context 'for global admin user' do before(:each) do @user = Factory(:admin) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index b44f85684..d692beb19 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -15,6 +15,7 @@ def set_commentable_data end describe Comment do + before { stub_rsync_methods } context 'for global admin user' do before(:each) do @user = Factory(:admin) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 9056e45c7..c742a5671 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -10,14 +10,9 @@ describe Repository do @params = {:name => 'tst_platform', :description => 'test platform'} end - it 'it should increase Relations.count by 1' do - rep = Repository.new(@params) - rep.platform = @platform - rep.owner = @platform.owner - rep.save! - Relation.by_object(rep.owner).by_target(rep).count.should eql(1) -# (@platform.owner.repositories.where(:platform_id => @platform.id).count == 1).should be_true + it 'it should increase Repository.count by 1' do + rep = Repository.create(@params) {|r| r.platform = @platform} + @platform.repositories.count.should eql(1) end end - #pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/subscribe_spec.rb b/spec/models/subscribe_spec.rb index eff91b9a8..40ccddd3c 100644 --- a/spec/models/subscribe_spec.rb +++ b/spec/models/subscribe_spec.rb @@ -12,6 +12,7 @@ def set_testable_data end describe Subscribe do + before { stub_rsync_methods } context 'for global admin user' do before(:each) do @user = Factory(:admin) From 600df031f5c53428528bffdb97d3304a7199ddc1 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 21 Feb 2012 23:27:11 +0200 Subject: [PATCH 33/52] Refactor platform clone controller and routes. Refactor and fix clone process for platform, repository, product. Place XML RPC clone request to DJ. Refs #207 --- app/controllers/platforms_controller.rb | 26 +++++++++++++------------ app/models/platform.rb | 12 +++++------- app/models/product.rb | 6 +++--- app/models/repository.rb | 6 +++--- app/views/platforms/clone.html.haml | 2 +- config/routes.rb | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 060fe99e0..06eb87c45 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -109,19 +109,21 @@ class PlatformsController < ApplicationController end def clone - if request.post? - @cloned = @platform.make_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], - :owner_id => current_user.id, :owner_type => current_user.class.to_s) - if @cloned.persisted? - flash[:notice] = I18n.t("flash.platform.clone_success") - redirect_to @cloned - else - flash[:error] = @cloned.errors.full_messages.join('. ') - end + @cloned = Platform.new + @cloned.name = @platform.name + "_clone" + @cloned.description = @platform.description + "_clone" + end + + def make_clone + @cloned = @platform.make_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], + :owner_id => current_user.id, :owner_type => current_user.class.to_s) + if @cloned.persisted? # valid? + flash[:notice] = I18n.t("flash.platform.clone_success") + redirect_to @cloned else - @cloned = Platform.new - @cloned.name = @platform.name + "_clone" - @cloned.description = @platform.description + "_clone" + raise @cloned.repositories.first.inspect + flash[:error] = @cloned.errors.full_messages.join('. ') + render 'clone' end end diff --git a/app/models/platform.rb b/app/models/platform.rb index e7b552ba2..773aa3111 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -98,23 +98,21 @@ class Platform < ActiveRecord::Base platform_type == 'personal' end - def full_clone(attrs) # :description, :name, :owner + def full_clone(attrs = {}) # :description, :name, :owner clone.tap do |c| - c.attributes = attrs + c.attributes = attrs # do not set protected c.updated_at = nil; c.created_at = nil # :id = nil c.parent = self - new_attrs = {:platform_id => nil} - c.repositories = repositories.map{|r| r.full_clone(new_attrs.merge(:owner_id => attrs[:owner_id], :owner_type => attrs[:owner_type]))} - c.products = products.map{|p| p.full_clone(new_attrs)} + c.repositories = repositories.map(&:full_clone) + c.products = products.map(&:full_clone) end end - # TODO * make it Delayed Job * def make_clone(attrs) p = full_clone(attrs) begin Thread.current[:skip] = true - p.save and xml_rpc_clone(attrs[:name]) + p.save and self.delay.xml_rpc_clone(attrs[:name]) ensure Thread.current[:skip] = false end diff --git a/app/models/product.rb b/app/models/product.rb index 94e355d20..14cd10549 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -59,10 +59,10 @@ class Product < ActiveRecord::Base EOF end - def full_clone(attrs) # owner + def full_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs - c.updated_at = nil; c.created_at = nil # :id = nil + c.attributes = attrs # do not set protected + c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil end end diff --git a/app/models/repository.rb b/app/models/repository.rb index f5c7d4c13..79e49a345 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -15,10 +15,10 @@ class Repository < ActiveRecord::Base attr_accessible :description, :name - def full_clone(attrs) # owner + def full_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs - c.updated_at = nil; c.created_at = nil # :id = nil + c.attributes = attrs # do not set protected + c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil c.projects = projects end end diff --git a/app/views/platforms/clone.html.haml b/app/views/platforms/clone.html.haml index 045e2956a..01eb9b7be 100644 --- a/app/views/platforms/clone.html.haml +++ b/app/views/platforms/clone.html.haml @@ -8,7 +8,7 @@ %h2.title = t("layout.platforms.clone_header") .inner - = form_for @cloned, :url => clone_platform_path(@platform), :html => { :class => :form } do |f| + = form_for @cloned, :url => make_clone_platform_path(@platform), :html => { :class => :form } do |f| .group = f.label :name, :class => :label = f.text_field :name, :class => 'text_field' diff --git a/config/routes.rb b/config/routes.rb index e8c872689..b3ef45c46 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,7 +71,7 @@ Rosa::Application.routes.draw do post 'freeze' post 'unfreeze' get 'clone' - post 'clone' + post 'make_clone' post 'build_all' end From 7c273c022b82133e49c535fbd490a3f2aecdd088 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 21 Feb 2012 23:43:06 +0200 Subject: [PATCH 34/52] Remove raise. Refs #207 --- app/controllers/platforms_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 06eb87c45..5e6a467f3 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -121,7 +121,6 @@ class PlatformsController < ApplicationController flash[:notice] = I18n.t("flash.platform.clone_success") redirect_to @cloned else - raise @cloned.repositories.first.inspect flash[:error] = @cloned.errors.full_messages.join('. ') render 'clone' end From 069c226110a102f0185b9d4a8e3299ed2b0e0ae2 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 22 Feb 2012 14:35:40 +0200 Subject: [PATCH 35/52] Place platform destroy to background. Redo clone process to 2 phases - base_clone and relations_clone. Place relations clone and XML RPC to background. Remove unneeded validations. Refactor xml_rpc_clone. Refs #207 --- app/controllers/platforms_controller.rb | 7 +++-- app/models/platform.rb | 38 +++++++++++++++---------- app/models/project.rb | 2 +- app/models/repository.rb | 8 +++--- lib/ext/core/object.rb | 10 +++++++ 5 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 lib/ext/core/object.rb diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 5e6a467f3..c357b526a 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -115,9 +115,10 @@ class PlatformsController < ApplicationController end def make_clone - @cloned = @platform.make_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], + @cloned = @platform.base_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], :owner_id => current_user.id, :owner_type => current_user.class.to_s) - if @cloned.persisted? # valid? + if with_skip{@cloned.save} + @cloned.delay.clone_complete flash[:notice] = I18n.t("flash.platform.clone_success") redirect_to @cloned else @@ -127,7 +128,7 @@ class PlatformsController < ApplicationController end def destroy - @platform.destroy if @platform + @platform.delay.destroy if @platform flash[:notice] = t("flash.platform.destroyed") redirect_to root_path diff --git a/app/models/platform.rb b/app/models/platform.rb index 773aa3111..305addb84 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -14,7 +14,7 @@ class Platform < ActiveRecord::Base has_many :members, :through => :objects, :source => :object, :source_type => 'User' has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' - validates :description, :presence => true, :uniqueness => true + validates :description, :presence => true validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ } validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']} @@ -98,25 +98,33 @@ class Platform < ActiveRecord::Base platform_type == 'personal' end - def full_clone(attrs = {}) # :description, :name, :owner + def base_clone(attrs = {}) # :description, :name, :owner clone.tap do |c| c.attributes = attrs # do not set protected c.updated_at = nil; c.created_at = nil # :id = nil c.parent = self - c.repositories = repositories.map(&:full_clone) - c.products = products.map(&:full_clone) end end - def make_clone(attrs) - p = full_clone(attrs) - begin - Thread.current[:skip] = true - p.save and self.delay.xml_rpc_clone(attrs[:name]) - ensure - Thread.current[:skip] = false + # def full_clone(attrs = {}) # :description, :name, :owner + # clone.tap do |c| + # c.attributes = attrs # do not set protected + # c.updated_at = nil; c.created_at = nil # :id = nil + # c.parent = self + # c.repositories = repositories.map(&:full_clone) + # c.products = products.map(&:full_clone) + # end + # end + + def clone_relations(from = parent) + self.repositories = from.repositories.map(&:full_clone) + self.products = from.products.map(&:full_clone) + end + + def clone_complete + with_skip do + clone_relations and xml_rpc_clone end - p end def name @@ -179,12 +187,12 @@ class Platform < ActiveRecord::Base end end - def xml_rpc_clone(new_name) - result = BuildServer.clone_platform new_name, self.name, APP_CONFIG['root_path'] + '/platforms' + def xml_rpc_clone(old_name = parent.name, new_name = name) + result = BuildServer.clone_platform new_name, old_name, APP_CONFIG['root_path'] + '/platforms' if result == BuildServer::SUCCESS return true else - raise "Failed to clone platform #{name} with code #{result}. Path: #{build_path(name)} to platform #{new_name}" + raise "Failed to clone platform #{old_name} with code #{result}. Path: #{build_path(old_name)} to platform #{new_name}" end end diff --git a/app/models/project.rb b/app/models/project.rb index b26f2ee06..d7e20f02d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -18,7 +18,7 @@ class Project < ActiveRecord::Base has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User' has_many :groups, :through => :relations, :source => :object, :source_type => 'Group' - validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ } + validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^[a-zA-Z0-9_\-\+\.]+$/} validates :owner, :presence => true validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS } # validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?} diff --git a/app/models/repository.rb b/app/models/repository.rb index 79e49a345..45b1e116d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -2,11 +2,11 @@ class Repository < ActiveRecord::Base belongs_to :platform - has_many :projects, :through => :project_to_repositories #, :dependent => :destroy - has_many :project_to_repositories, :validate => true, :dependent => :destroy + has_many :project_to_repositories, :dependent => :destroy, :validate => true + has_many :projects, :through => :project_to_repositories - validates :description, :uniqueness => {:scope => :platform_id}, :presence => true - validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ } + validates :description, :presence => true + validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => {:with => /^[a-z0-9_\-]+$/} scope :recent, order("name ASC") diff --git a/lib/ext/core/object.rb b/lib/ext/core/object.rb new file mode 100644 index 000000000..d2856a51c --- /dev/null +++ b/lib/ext/core/object.rb @@ -0,0 +1,10 @@ +class Object + def with_skip + begin + Thread.current[:skip] = true + yield + ensure + Thread.current[:skip] = false + end + end +end From 9015b971aa765a3bf32d3f0c1f6b8256f28da80d Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 22 Feb 2012 22:24:29 +0200 Subject: [PATCH 36/52] Redo clone logic. Split clone process for repositories. Optimize and refactor. Refs #207 --- app/controllers/platforms_controller.rb | 6 ++---- app/models/platform.rb | 20 +++++--------------- app/models/product.rb | 5 +++-- app/models/repository.rb | 20 ++++++++++++++++---- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index c357b526a..3b0151bd6 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -115,10 +115,8 @@ class PlatformsController < ApplicationController end def make_clone - @cloned = @platform.base_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], - :owner_id => current_user.id, :owner_type => current_user.class.to_s) - if with_skip{@cloned.save} - @cloned.delay.clone_complete + @cloned = @platform.full_clone params[:platform].merge(:owner => current_user) + if @cloned.persisted? flash[:notice] = I18n.t("flash.platform.clone_success") redirect_to @cloned else diff --git a/app/models/platform.rb b/app/models/platform.rb index 305addb84..3b7551703 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -100,30 +100,20 @@ class Platform < ActiveRecord::Base def base_clone(attrs = {}) # :description, :name, :owner clone.tap do |c| - c.attributes = attrs # do not set protected + c.attributes = attrs # attrs.each {|k,v| c.send("#{k}=", v)} c.updated_at = nil; c.created_at = nil # :id = nil c.parent = self end end - # def full_clone(attrs = {}) # :description, :name, :owner - # clone.tap do |c| - # c.attributes = attrs # do not set protected - # c.updated_at = nil; c.created_at = nil # :id = nil - # c.parent = self - # c.repositories = repositories.map(&:full_clone) - # c.products = products.map(&:full_clone) - # end - # end - def clone_relations(from = parent) - self.repositories = from.repositories.map(&:full_clone) + self.repositories = from.repositories.map{|r| r.full_clone(:platform_id => id)} self.products = from.products.map(&:full_clone) end - def clone_complete - with_skip do - clone_relations and xml_rpc_clone + def full_clone(attrs = {}) + base_clone(attrs).tap do |c| + with_skip {c.save} and c.clone_relations(self) and c.delay.xml_rpc_clone end end diff --git a/app/models/product.rb b/app/models/product.rb index 14cd10549..536b3dbbf 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -61,8 +61,9 @@ class Product < ActiveRecord::Base def full_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs # do not set protected - c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil + c.platform_id = nil + attrs.each {|k,v| c.send("#{k}=", v)} + c.updated_at = nil; c.created_at = nil # :id = nil end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 45b1e116d..50b57cb4a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -15,11 +15,23 @@ class Repository < ActiveRecord::Base attr_accessible :description, :name - def full_clone(attrs = {}) + def base_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs # do not set protected - c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil - c.projects = projects + c.platform_id = nil + attrs.each {|k,v| c.send("#{k}=", v)} + c.updated_at = nil; c.created_at = nil # :id = nil + end + end + + def clone_relations(from) + with_skip do + from.projects.find_each {|p| self.projects << p} + end + end + + def full_clone(attrs = {}) + base_clone(attrs).tap do |c| + with_skip {c.save} and c.delay.clone_relations(self) end end From 07093c0d1d8ee02a9c3d582f85e357d110306aeb Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 00:57:43 +0200 Subject: [PATCH 37/52] Create directory for platform before clone. Fix created directory permissions. Increase timeout during XML RPC clone. Switch off cascade XML RPC requests during platform destroy. Refs #207 --- app/models/platform.rb | 11 ++++++++++- app/models/project_to_repository.rb | 2 +- app/models/repository.rb | 2 +- lib/build_server.rb | 4 +++- lib/modules/models/rsync_stub.rb | 4 ++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index 3b7551703..713283b5c 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -18,6 +18,7 @@ class Platform < ActiveRecord::Base validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ } validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']} + before_create :create_directory, :if => lambda {Thread.current[:skip]} # TODO remove this when core will be ready before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy # before_update :check_freezing @@ -131,9 +132,13 @@ class Platform < ActiveRecord::Base end end + def create_directory + system("sudo mkdir -p -m 0777 #{path}") + end + def mount_directory_for_rsync # umount_directory_for_rsync # TODO ignore errors - system("sudo mkdir -p #{mount_path}") + system("sudo mkdir -p -m 0777 #{mount_path}") system("sudo mount --bind #{path} #{mount_path}") Arch.all.each do |arch| str = "country=Russian Federation,city=Moscow,latitude=52.18,longitude=48.88,bw=1GB,version=2011,arch=#{arch.name},type=distrib,url=#{public_downloads_url}\n" @@ -153,6 +158,10 @@ class Platform < ActiveRecord::Base end end + def destroy + with_skip {super} # avoid cascade XML RPC requests + end + protected def build_path(dir) diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index 7bf5adba5..611bb0bbe 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -6,7 +6,7 @@ class ProjectToRepository < ActiveRecord::Base delegate :path, :to => :project after_create lambda { project.xml_rpc_create(repository) }, :unless => lambda {Thread.current[:skip]} - after_destroy lambda { project.xml_rpc_destroy(repository) } + after_destroy lambda { project.xml_rpc_destroy(repository) }, :unless => lambda {Thread.current[:skip]} # after_rollback lambda { project.xml_rpc_destroy(repository) rescue true if new_record? } validate :one_project_in_platform_repositories diff --git a/app/models/repository.rb b/app/models/repository.rb index 50b57cb4a..7684ee005 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -11,7 +11,7 @@ class Repository < ActiveRecord::Base scope :recent, order("name ASC") before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} - before_destroy :xml_rpc_destroy + before_destroy :xml_rpc_destroy, :unless => lambda {Thread.current[:skip]} attr_accessible :description, :name diff --git a/lib/build_server.rb b/lib/build_server.rb index feb066b19..2bf6cfc9a 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -49,10 +49,12 @@ class BuildServer end def self.clone_repo new_name, old_name, new_platform_name + tmp = self.client.timeout # TODO remove this when core will be ready + self.client.timeout = 30.minutes self.client.call('clone_repo', new_name, old_name, new_platform_name) + self.client.timeout = tmp end - def self.publish_container container_id self.client.call('publish_container', container_id) end diff --git a/lib/modules/models/rsync_stub.rb b/lib/modules/models/rsync_stub.rb index bbf101d76..7865c232f 100644 --- a/lib/modules/models/rsync_stub.rb +++ b/lib/modules/models/rsync_stub.rb @@ -5,6 +5,10 @@ module Modules extend ActiveSupport::Concern included do + def create_directory + true + end + def mount_directory_for_rsync true end From c3d5ea790f0377e68897ffb3a09452db8fe0188e Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 17:17:02 +0200 Subject: [PATCH 38/52] Rescue and ignore timeout error during long XML RPC. Apply add_branch script. Refs #207 --- lib/build_server.rb | 16 +++++++++------- lib/tasks/add_branch.rake | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 lib/tasks/add_branch.rake diff --git a/lib/build_server.rb b/lib/build_server.rb index 2bf6cfc9a..9aa2be76e 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -28,33 +28,35 @@ class BuildServer self.client.call('add_platform', name, platforms_root_folder, repos, distrib_type) end - def self.delete_platform name self.client.call('delete_platform', name) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end - def self.clone_platform new_name, old_name, new_root_folder self.client.call('clone_platform', new_name, old_name, new_root_folder) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end - def self.create_repo name, platform_name self.client.call('create_repository', name, platform_name) end - def self.delete_repo name, platform_name self.client.call('delete_repository', name, platform_name) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end def self.clone_repo new_name, old_name, new_platform_name - tmp = self.client.timeout # TODO remove this when core will be ready - self.client.timeout = 30.minutes self.client.call('clone_repo', new_name, old_name, new_platform_name) - self.client.timeout = tmp + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end + def self.publish_container container_id self.client.call('publish_container', container_id) end diff --git a/lib/tasks/add_branch.rake b/lib/tasks/add_branch.rake new file mode 100644 index 000000000..1a7b96bd5 --- /dev/null +++ b/lib/tasks/add_branch.rake @@ -0,0 +1,22 @@ +require 'highline/import' + +desc "Add branch for platform projects" +task :add_branch => :environment do + src_branch = ENV['SRC_BRANCH'] || 'import_mandriva2011' + dst_branch = ENV['DST_BRANCH'] || 'rosa2012lts' + + say "START add branch #{dst_branch} from #{src_branch}" + Platform.find_by_name(dst_branch).repositories.each do |r| + say "=== Process #{r.name} repo" + r.projects.find_each do |p| + say "===== Process #{p.name} project" + tmp_path = Rails.root.join('tmp', p.name) + system("git clone #{p.path} #{tmp_path}") + system("cd #{tmp_path} && git checkout remotes/origin/#{src_branch}") or system("cd #{tmp_path} && git checkout master") + system("cd #{tmp_path} && git checkout -b #{dst_branch}") + system("cd #{tmp_path} && git push origin HEAD") + FileUtils.rm_rf tmp_path + end + end + say 'DONE' +end From 15f78e30a0d09cfb6d0dbb1fde86bdcc18dfc544 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 20:32:56 +0200 Subject: [PATCH 39/52] Redo platform build_all with sleep and errors rescue. Refs #207 --- app/controllers/platforms_controller.rb | 6 +----- app/models/platform.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 3b0151bd6..01cbc0eec 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -8,11 +8,7 @@ class PlatformsController < ApplicationController autocomplete :user, :uname def build_all - @platform.repositories.each do |repository| - repository.projects.each do |project| - project.delay.build_for(@platform, current_user) - end - end + @platform.delay.build_all(current_user) redirect_to(platform_path(@platform), :notice => t("flash.platform.build_all_success")) end diff --git a/app/models/platform.rb b/app/models/platform.rb index 713283b5c..76756ee3e 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -158,6 +158,21 @@ class Platform < ActiveRecord::Base end end + def build_all(user) + repositories.each do |r| + r.projects.find_in_batches(:batch_size => 5) do |group| + sleep 1 + group.each do |p| + begin + p.build_for(self, user) + rescue RuntimeError, Exception + p.delay.build_for(self, user) + end + end + end + end + end + def destroy with_skip {super} # avoid cascade XML RPC requests end From 165a8dd6f4694131e41a687369ea6c00653ff903 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 21:06:28 +0200 Subject: [PATCH 40/52] Build only main repo. Refs #207 --- app/models/platform.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index 76756ee3e..6a109fa2d 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -159,15 +159,13 @@ class Platform < ActiveRecord::Base end def build_all(user) - repositories.each do |r| - r.projects.find_in_batches(:batch_size => 5) do |group| - sleep 1 - group.each do |p| - begin - p.build_for(self, user) - rescue RuntimeError, Exception - p.delay.build_for(self, user) - end + repositories.find_by_name('main').projects.find_in_batches(:batch_size => 5) do |group| + sleep 1 + group.each do |p| + begin + p.build_for(self, user) + rescue RuntimeError, Exception + p.delay.build_for(self, user) end end end From 51e2c85b0a475625d37bde529c2534c505acc9a1 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 22:20:44 +0200 Subject: [PATCH 41/52] Fix build_for settings. Refs #207 --- app/models/project.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index d7e20f02d..08e487864 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -61,14 +61,13 @@ class Project < ActiveRecord::Base end end - def build_for(platform, user) + def build_for(platform, user) build_lists.create do |bl| bl.pl = platform bl.bpl = platform - bl.update_type = 'recommended' + bl.update_type = 'newpackage' bl.arch = Arch.find_by_name('x86_64') # Return i586 after mass rebuild - # FIXME: Need to set "latest_#{platform.name}" - bl.project_version = "latest_import_mandriva2011" + bl.project_version = "latest_#{platform.name}" # "latest_import_mandriva2011" bl.build_requires = false # already set as db default bl.user = user bl.auto_publish = true # already set as db default From 63c89edfda7379f3330b5419c09cc45830e47a0e Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Fri, 24 Feb 2012 17:49:47 +0400 Subject: [PATCH 42/52] Isolated localization for activity feed --- config/locales/activity_feed.en.yml | 31 ++++++++++++++++++++++++++ config/locales/activity_feed.ru.yml | 34 +++++++++++++++++++++++++++++ config/locales/en.yml | 4 ---- config/locales/notifications.en.yml | 34 ----------------------------- config/locales/notifications.ru.yml | 29 ------------------------ config/locales/ru.yml | 3 --- 6 files changed, 65 insertions(+), 70 deletions(-) create mode 100644 config/locales/activity_feed.en.yml create mode 100644 config/locales/activity_feed.ru.yml delete mode 100644 config/locales/notifications.en.yml delete mode 100644 config/locales/notifications.ru.yml diff --git a/config/locales/activity_feed.en.yml b/config/locales/activity_feed.en.yml new file mode 100644 index 000000000..cc3307d17 --- /dev/null +++ b/config/locales/activity_feed.en.yml @@ -0,0 +1,31 @@ +en: + + layout: + activity_feed: + header: Activity Feed + + notifications: + subjects: + new_comment_notification: New comment to your task + new_issue_notification: New task added to project + new_user_notification: Registered on project «%{ project_name }» + issue_assign_notification: New task assigned + + bodies: + new_comment_notification: + title: Hello, %{user_name}. + content: To the issue %{issue_link} added a comment. + new_comment_reply_notification: + title: Hello, %{user_name}. + content: Your comment into issue %{issue_link} has been answered. + new_issue_notification: + title: Hello, %{user_name}. + content: To project %{project_link} has been added an issue %{issue_link} + new_user_notification: + title: Hello, %{user_name}. + content: You have been sign up to project «ROSA Build System» and now can sign in. + email: ==Your email %{user_email} + password: ==Your password %{user_password} + issue_assign_notification: + title: Hello, %{user_name}. + content: You have been assigned to issue %{issue_link} diff --git a/config/locales/activity_feed.ru.yml b/config/locales/activity_feed.ru.yml new file mode 100644 index 000000000..2ac9486cc --- /dev/null +++ b/config/locales/activity_feed.ru.yml @@ -0,0 +1,34 @@ +ru: + + layout: + activity_feed: + header: Лента активности + + notifications: + subjects: + new_comment_notification: Новый комментарий к Вашей задаче + new_comment_reply_notification: Новый комментарий к Вашей задаче + new_issue_notification: Новая задача добавлена к проекту + new_user_notification: Регистрация на проекте «%{ project_name }» + issue_assign_notification: Вам назначили задачу + + bodies: + new_comment_notification: + title: Здравствуйте, %{user_name}. + content: К задаче %{issue_link} был добавлен новый комментарий. + new_comment_reply_notification: + title: Здравствуйте, %{user_name}. + content: На Ваш комментарий в задаче %{issue_link} был дан ответ. + new_issue_notification: + title: Здравствуйте, %{user_name}. + content: К проекту %{project_link} была добавлена задача %{issue_link} + new_user_notification: + title: Здравствуйте, %{user_name}. + content: Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему. + email: ==Ваш email %{user_email} + password: ==Ваш пароль %{user_password} + issue_assign_notification: + title: Здравствуйте, %{user_name}. + content: Вам была назначена задача %{issue_link} + new_commit_comment_notification: Новый комментарий к коммиту + invite_approve_notification: Приглашение в ABF \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 368e2c04d..fda62af7e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -381,9 +381,6 @@ en: unlock: Do not receive unlock instructions? sign_in_through: Sign in by %{provider} - activity_feed: - header: Activity Feed - downloads: title: Downloads statistic message: Automatically updated every 5 minutes @@ -1134,4 +1131,3 @@ en: distro: Source platform: Platform counter: Downloads - diff --git a/config/locales/notifications.en.yml b/config/locales/notifications.en.yml deleted file mode 100644 index 93d15993b..000000000 --- a/config/locales/notifications.en.yml +++ /dev/null @@ -1,34 +0,0 @@ -notifications: - subjects: - new_comment_notification: New comment to your task - new_issue_notification: New task added to project - new_user_notification: Registered on project «%{ project_name }» - issue_assign_notification: New task assigned - - bodies: - new_comment_notification: - title: Hello, %{user_name}. - content: To the issue %{issue_link} added a comment. - new_comment_reply_notification: - title: Hello, %{user_name}. - content: Your comment into issue %{issue_link} has been answered. - new_issue_notification: - title: Hello, %{user_name}. - content: To project %{project_link} has been added an issue %{issue_link} - new_user_notification: - title: Hello, %{user_name}. - content: You have been sign up to project «ROSA Build System» and now can sign in. - email: ==Your email %{user_email} - password: ==Your password %{user_password} - issue_assign_notification: - title: Hello, %{user_name}. - content: You have been assigned to issue %{issue_link} - - download: - name: Name - version: Version - distro: Source - platform: Platform - counter: Downloads - - diff --git a/config/locales/notifications.ru.yml b/config/locales/notifications.ru.yml deleted file mode 100644 index f4ddbe462..000000000 --- a/config/locales/notifications.ru.yml +++ /dev/null @@ -1,29 +0,0 @@ -notifications: - subjects: - new_comment_notification: Новый комментарий к Вашей задаче - new_comment_reply_notification: Новый комментарий к Вашей задаче - new_issue_notification: Новая задача добавлена к проекту - new_user_notification: Регистрация на проекте «%{ project_name }» - issue_assign_notification: Вам назначили задачу - - bodies: - new_comment_notification: - title: Здравствуйте, %{user_name}. - content: К задаче %{issue_link} был добавлен новый комментарий. - new_comment_reply_notification: - title: Здравствуйте, %{user_name}. - content: На Ваш комментарий в задаче %{issue_link} был дан ответ. - new_issue_notification: - title: Здравствуйте, %{user_name}. - content: К проекту %{project_link} была добавлена задача %{issue_link} - new_user_notification: - title: Здравствуйте, %{user_name}. - content: Вы зарегистрированы на проекте «ROSA Build System» и теперь можете войти в систему. - email: ==Ваш email %{user_email} - password: ==Ваш пароль %{user_password} - issue_assign_notification: - title: Здравствуйте, %{user_name}. - content: Вам была назначена задача %{issue_link} - new_commit_comment_notification: Новый комментарий к коммиту - invite_approve_notification: Приглашение в ABF - diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 1567e590a..6a73ff386 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -58,9 +58,6 @@ ru: unlock: Не получили инструкции по разблокировке? sign_in_through: Войти через %{provider} - activity_feed: - header: Лента активности - downloads: title: Статистика закачек пакетов message: Обновляется автоматически каждые 24 часа From 3685eafe575e2f0d5752c422cb4323b2925e1a75 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Fri, 24 Feb 2012 17:50:35 +0400 Subject: [PATCH 43/52] Remove unused code [Refs #207] --- app/models/comment.rb | 15 --------------- config/routes.rb | 1 - 2 files changed, 16 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index bd84e8f68..e6a72f83e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -8,7 +8,6 @@ class Comment < ActiveRecord::Base # FIXME after_create :subscribe_on_reply, :unless => "commentable_type == 'Grit::Commit'" - #after_create :deliver_new_comment_notification, :unless => "commentable_type == 'Grit::Commit'" after_create :invoke_helper, :if => "commentable_type == 'Grit::Commit'" after_create :subscribe_users after_create {|comment| Subscribe.new_comment_notification(comment)} @@ -35,20 +34,6 @@ class Comment < ActiveRecord::Base protected - #def deliver_new_comment_notification - # subscribes = self.commentable.subscribes - # subscribes.each do |subscribe| - # # TODO: new_comment and new_comment_reply - you need to check each variant, not only new_comment_reply... - # if self.user_id != subscribe.user_id && User.find(subscribe.user).notifier.new_comment_reply && User.find(subscribe.user).notifier.can_notify - # if self.reply? subscribe - # UserMailer.delay.new_comment_reply_notification(self, subscribe.user) - # else - # UserMailer.delay.new_comment_notification(self, subscribe.user) - # end - # end - # end - #end - def subscribe_on_reply self.commentable.subscribes.create(:user_id => self.user_id) if !self.commentable.subscribes.exists?(:user_id => self.user_id) end diff --git a/config/routes.rb b/config/routes.rb index b3ef45c46..1daa1fe29 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -211,7 +211,6 @@ Rosa::Application.routes.draw do match '/projects/:project_id/git/raw/:treeish/*path', :controller => "git/blobs", :action => :raw, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :raw match '/projects/:project_id/git/commit/raw/:commit_hash/*path', :controller => "git/blobs", :action => :raw, :as => :raw_commit - #root :to => "platforms#index" root :to => "activity_feeds#index" match '/forbidden', :to => 'platforms#forbidden', :as => 'forbidden' end From 3c8f1c062bdcb71a74ec02e4fd4e938fe2912659 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Fri, 24 Feb 2012 20:33:00 +0400 Subject: [PATCH 44/52] Fix ActivityFeed for user, remove info about password [Refs #207] --- app/models/activity_feed_observer.rb | 4 +++- .../activity_feeds/partials/_new_user_notification.haml | 7 +------ app/views/user_mailer/new_user_notification.en.haml | 2 -- app/views/user_mailer/new_user_notification.ru.haml | 2 -- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index 5c4b2a875..b4e5fb348 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -7,7 +7,7 @@ class ActivityFeedObserver < ActiveRecord::Observer ActivityFeed.create( :user => record, :kind => 'new_user_notification', - :date => {:user_name => record.name, :user_email => record.email, :password => user.password} + :data => {:user_name => record.name, :user_email => record.email} ) when 'Issue' @@ -52,6 +52,7 @@ class ActivityFeedObserver < ActiveRecord::Observer end end end + when 'GitHook' change_type = record.change_type branch_name = record.refname.match(/\/([\w\d]+)$/)[1] @@ -79,6 +80,7 @@ class ActivityFeedObserver < ActiveRecord::Observer :data => options ) end + when 'Gollum::Committer' actor = User.find_by_uname(record.actor.name) project_name = record.wiki.path.match(/\/(\w+)\.wiki\.git$/)[1] diff --git a/app/views/activity_feeds/partials/_new_user_notification.haml b/app/views/activity_feeds/partials/_new_user_notification.haml index b1ae04bd6..98d4796e9 100644 --- a/app/views/activity_feeds/partials/_new_user_notification.haml +++ b/app/views/activity_feeds/partials/_new_user_notification.haml @@ -1,10 +1,5 @@ %p== #{ t("notifications.bodies.new_user_notification.title", :user_name => user_name) } - %p #{ t("notifications.bodies.new_user_notification.content") } - -%p - #{ t("notifications.bodies.new_user_notification.email", :user_email => user_email) } - %br/ - #{ t("notifications.bodies.new_user_notification.password", :user_password => user_email) } +%p #{ t("notifications.bodies.new_user_notification.email", :user_email => user_email) } \ No newline at end of file diff --git a/app/views/user_mailer/new_user_notification.en.haml b/app/views/user_mailer/new_user_notification.en.haml index d1a0722bf..c0f05d467 100644 --- a/app/views/user_mailer/new_user_notification.en.haml +++ b/app/views/user_mailer/new_user_notification.en.haml @@ -6,7 +6,5 @@ %p ==Your email : #{@user.email} - %br/ - ==Your password: #{@user.password} %p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/new_user_notification.ru.haml b/app/views/user_mailer/new_user_notification.ru.haml index f3c6d1ec7..acae98cba 100644 --- a/app/views/user_mailer/new_user_notification.ru.haml +++ b/app/views/user_mailer/new_user_notification.ru.haml @@ -6,7 +6,5 @@ %p ==Ваш email : #{@user.email} - %br/ - ==Ваш пароль: #{@user.password} %p== Команда поддержки «ROSA Build System» From dde81b55544c40a31af6f6be448b748abae8f118 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Sat, 25 Feb 2012 00:25:35 +0600 Subject: [PATCH 45/52] [refs #123] fix activity feed for commit comments; remove reply notification --- app/models/activity_feed_observer.rb | 30 +++++++++++-------- app/models/comment.rb | 5 ---- app/models/subscribe.rb | 23 -------------- .../_new_comment_reply_notification.haml | 5 ---- .../_new_commit_comment_notification.haml | 5 ++++ .../new_comment_reply_notification.en.haml | 9 ------ config/locales/activity_feed.en.yml | 7 ++--- config/locales/activity_feed.ru.yml | 9 ++---- config/locales/en.yml | 1 - 9 files changed, 29 insertions(+), 65 deletions(-) delete mode 100644 app/views/activity_feeds/partials/_new_comment_reply_notification.haml create mode 100644 app/views/activity_feeds/partials/_new_commit_comment_notification.haml delete mode 100644 app/views/user_mailer/new_comment_reply_notification.en.haml diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index b4e5fb348..6092ddea3 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -32,25 +32,31 @@ class ActivityFeedObserver < ActiveRecord::Observer end when 'Comment' - subscribes = record.commentable.subscribes - subscribes.each do |subscribe| - if record.user_id != subscribe.user_id - if record.reply? subscribe - UserMailer.delay.new_comment_reply_notification(record, subscribe.user) if record.can_notify_on_reply?(subscribe) - ActivityFeed.create( - :user => subscribe.user, - :kind => 'new_comment_reply_notification', - :data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id} - ) - else + if record.commentable.class == Issue + subscribes = record.commentable.subscribes.finder_hack + subscribes.each do |subscribe| + if record.user_id != subscribe.user_id UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe) ActivityFeed.create( :user => subscribe.user, :kind => 'new_comment_notification', - :data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id} + :data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, + :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id} ) end end + elsif record.commentable.class == Grit::Commit + subscribes = Subscribe.comment_subscribes(record).where(:status => true) + subscribes.each do |subscribe| + next if record.own_comment?(subscribe.user) + UserMailer.delay.new_comment_notification(record, subscribe.user) if subscribe.user.notifier.can_notify + ActivityFeed.create( + :user => subscribe.user, + :kind => 'new_comment_commit_notification', + :data => {:user_name => subscribe.user.name, :comment_body => record.body, :commit_message => record.commentable.message.encode_to_default, + :commit_id => record.commentable.id, :project_id => record.project.id} + ) + end end when 'GitHook' diff --git a/app/models/comment.rb b/app/models/comment.rb index e6a72f83e..0cde4b217 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -10,7 +10,6 @@ class Comment < ActiveRecord::Base after_create :subscribe_on_reply, :unless => "commentable_type == 'Grit::Commit'" after_create :invoke_helper, :if => "commentable_type == 'Grit::Commit'" after_create :subscribe_users - after_create {|comment| Subscribe.new_comment_notification(comment)} def helper class_eval "def commentable; project.git_repository.commit('#{commentable_id}'); end" if commentable_type == 'Grit::Commit' @@ -20,10 +19,6 @@ class Comment < ActiveRecord::Base user_id == user.id end - def reply?(subscribe) - self.commentable.comments.exists?(:user_id => subscribe.user.id) - end - def can_notify_on_reply?(subscribe) User.find(subscribe.user).notifier.new_comment_reply && User.find(subscribe.user).notifier.can_notify end diff --git a/app/models/subscribe.rb b/app/models/subscribe.rb index a8fd5cc31..9779af5a3 100644 --- a/app/models/subscribe.rb +++ b/app/models/subscribe.rb @@ -14,27 +14,6 @@ class Subscribe < ActiveRecord::Base Subscribe.where(:subscribeable_id => comment.commentable.id, :subscribeable_type => comment.commentable.class.name, :project_id => comment.project) end - def self.new_comment_notification(comment) - commentable_class = comment.commentable.class - Subscribe.new_comment_issue_notification(comment) if commentable_class == Issue - Subscribe.new_comment_commit_notification(comment) if commentable_class == Grit::Commit - end - - def self.new_comment_issue_notification(comment) - comment.commentable.subscribes.finder_hack.each do |subscribe| - next if comment.own_comment?(subscribe.user) || !subscribe.user.notifier.can_notify - UserMailer.delay.new_comment_notification(comment, subscribe.user) if subscribe.user.notifier.new_comment_reply - end - end - - def self.new_comment_commit_notification(comment) - subscribes = Subscribe.comment_subscribes(comment).where(:status => true) - subscribes.each do |subscribe| - next if comment.own_comment?(subscribe.user) || !subscribe.user.notifier.can_notify - UserMailer.delay.new_comment_notification(comment, subscribe.user) - end - end - def self.subscribed_to_commit?(project, user, commit) subscribe = user.subscribes.where(:subscribeable_id => commit.id, :subscribeable_type => commit.class.name, :project_id => project.id).first return subscribe.subscribed? if subscribe # return status if already subscribe present @@ -44,12 +23,10 @@ class Subscribe < ActiveRecord::Base (user.committer?(commit) && user.notifier.new_comment_commit_owner) end - def self.subscribe_to_commit(options) Subscribe.set_subscribe_to_commit(options, true) end - def self.unsubscribe_from_commit(options) Subscribe.set_subscribe_to_commit(options, false) end diff --git a/app/views/activity_feeds/partials/_new_comment_reply_notification.haml b/app/views/activity_feeds/partials/_new_comment_reply_notification.haml deleted file mode 100644 index a9f040c38..000000000 --- a/app/views/activity_feeds/partials/_new_comment_reply_notification.haml +++ /dev/null @@ -1,5 +0,0 @@ -%p== #{ t("notifications.bodies.new_comment_reply_notification.title", :user_name => user_name) } - -%p= raw t("notifications.bodies.new_comment_reply_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))}) - -%p "#{ comment_body }" diff --git a/app/views/activity_feeds/partials/_new_commit_comment_notification.haml b/app/views/activity_feeds/partials/_new_commit_comment_notification.haml new file mode 100644 index 000000000..32826e333 --- /dev/null +++ b/app/views/activity_feeds/partials/_new_commit_comment_notification.haml @@ -0,0 +1,5 @@ +%p== #{ t("notifications.bodies.new_commit_comment_notification.title", :user_name => user_name) } + +%p= raw t("notifications.bodies.new_comment_notification.commit_content", {:commit_link => link_to(commit_message, commit_path(project_id, commit_id))}) + +%p "#{ comment_body }" diff --git a/app/views/user_mailer/new_comment_reply_notification.en.haml b/app/views/user_mailer/new_comment_reply_notification.en.haml deleted file mode 100644 index b2838b2e0..000000000 --- a/app/views/user_mailer/new_comment_reply_notification.en.haml +++ /dev/null @@ -1,9 +0,0 @@ -%p== Hello, #{@user.name}. - -- #TODO hmm... this need to be refactored. -%p Your comment into issue #{ link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) } has been answered. - -%p "#{ @comment.body }" - - -%p== Support team «ROSA Build System» diff --git a/config/locales/activity_feed.en.yml b/config/locales/activity_feed.en.yml index cc3307d17..0794427a7 100644 --- a/config/locales/activity_feed.en.yml +++ b/config/locales/activity_feed.en.yml @@ -6,7 +6,8 @@ en: notifications: subjects: - new_comment_notification: New comment to your task + new_comment_notification: New comment to task + new_commit_comment_notification: New comment to commit new_issue_notification: New task added to project new_user_notification: Registered on project «%{ project_name }» issue_assign_notification: New task assigned @@ -15,9 +16,7 @@ en: new_comment_notification: title: Hello, %{user_name}. content: To the issue %{issue_link} added a comment. - new_comment_reply_notification: - title: Hello, %{user_name}. - content: Your comment into issue %{issue_link} has been answered. + commit_content: To the commit %{commit_link} added a comment. new_issue_notification: title: Hello, %{user_name}. content: To project %{project_link} has been added an issue %{issue_link} diff --git a/config/locales/activity_feed.ru.yml b/config/locales/activity_feed.ru.yml index 2ac9486cc..256a8d7bb 100644 --- a/config/locales/activity_feed.ru.yml +++ b/config/locales/activity_feed.ru.yml @@ -6,8 +6,8 @@ ru: notifications: subjects: - new_comment_notification: Новый комментарий к Вашей задаче - new_comment_reply_notification: Новый комментарий к Вашей задаче + new_comment_notification: Новый комментарий к задаче + new_commit_comment_notification: Новый комментарий к коммиту new_issue_notification: Новая задача добавлена к проекту new_user_notification: Регистрация на проекте «%{ project_name }» issue_assign_notification: Вам назначили задачу @@ -16,9 +16,7 @@ ru: new_comment_notification: title: Здравствуйте, %{user_name}. content: К задаче %{issue_link} был добавлен новый комментарий. - new_comment_reply_notification: - title: Здравствуйте, %{user_name}. - content: На Ваш комментарий в задаче %{issue_link} был дан ответ. + commit_content: К коммиту %{commit_link} был добавлен новый комментарий. new_issue_notification: title: Здравствуйте, %{user_name}. content: К проекту %{project_link} была добавлена задача %{issue_link} @@ -30,5 +28,4 @@ ru: issue_assign_notification: title: Здравствуйте, %{user_name}. content: Вам была назначена задача %{issue_link} - new_commit_comment_notification: Новый комментарий к коммиту invite_approve_notification: Приглашение в ABF \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index fda62af7e..d4c08478c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -949,7 +949,6 @@ en: new_issue_notification: New task added to project new_user_notification: Registered on project «%{ project_name }» issue_assign_notification: New task assigned - new_commit_comment_notification: New comment to commit invite_approve_notification: Invitation to ABF project: From 952082f7a00868d090340721cde0c563c4c2941c Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 29 Feb 2012 13:15:12 +0400 Subject: [PATCH 46/52] [Fix #235] Remove wrong clone_platform_product_path url --- app/views/platforms/show.html.haml | 2 +- app/views/products/show.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/platforms/show.html.haml b/app/views/platforms/show.html.haml index baf917e62..8f8755070 100644 --- a/app/views/platforms/show.html.haml +++ b/app/views/platforms/show.html.haml @@ -113,7 +113,7 @@ = link_to t("layout.edit"), edit_platform_product_path(@platform, product) if can? :update, product | = link_to t("layout.delete"), platform_product_path(@platform, product), :method => :delete, :confirm => t("layout.products.confirm_delete") if can? :destroy, product - = (product.can_clone? ? "| #{link_to t("layout.products.clone"), clone_platform_product_path(@platform, product)}" : "").html_safe + =# (product.can_clone? ? "| #{link_to t("layout.products.clone"), clone_platform_product_path(@platform, product)}" : "").html_safe .actions-bar.wat-cf .actions - content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/products/show.html.haml b/app/views/products/show.html.haml index f9c3f5bea..0dc7ae13c 100644 --- a/app/views/products/show.html.haml +++ b/app/views/products/show.html.haml @@ -31,7 +31,7 @@ - if can? :destroy, @product = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete") - if @product.can_clone? - = link_to t("layout.products.clone"), clone_platform_product_path(@platform, @product), :class => "button" + =# link_to t("layout.products.clone"), clone_platform_product_path(@platform, @product), :class => "button" - if can?(:create, @product => ProductBuildList) = link_to t("layout.products.build"), platform_product_product_build_lists_path(@platform, @product), :class => "button", :method => 'post', :confirm => t("layout.confirm") From 97c9eab3beca09085353090db307f19838c9f9ce Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 29 Feb 2012 13:41:42 +0400 Subject: [PATCH 47/52] [Fix #236] Add application/octet-stream content type for tar.bz2 product attachment --- app/models/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/product.rb b/app/models/product.rb index 536b3dbbf..e52a700f0 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -10,7 +10,7 @@ class Product < ActiveRecord::Base has_attached_file :tar - validates_attachment_content_type :tar, :content_type => ["application/gnutar", "application/x-compressed", "application/x-gzip", "application/x-bzip", "application/x-bzip2", "application/x-tar"], :message => I18n.t('layout.invalid_content_type') + validates_attachment_content_type :tar, :content_type => ["application/gnutar", "application/x-compressed", "application/x-gzip", "application/x-bzip", "application/x-bzip2", "application/x-tar", "application/octet-stream"], :message => I18n.t('layout.invalid_content_type') validates :name, :presence => true, :uniqueness => {:scope => :platform_id} scope :recent, order("name ASC") From 062b5c71b119a90799383f932c1bc81d3ef8e46a Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 29 Feb 2012 15:13:56 +0400 Subject: [PATCH 48/52] [Refs #221] Fix right for platform local admin --- app/views/product_build_lists/_product_build_list.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/product_build_lists/_product_build_list.html.haml b/app/views/product_build_lists/_product_build_list.html.haml index 38a70580e..91fb1c373 100644 --- a/app/views/product_build_lists/_product_build_list.html.haml +++ b/app/views/product_build_lists/_product_build_list.html.haml @@ -3,5 +3,5 @@ %td= link_to product_build_list.product.name, [product_build_list.product.platform, product_build_list.product] %td= link_to nil, product_build_list.container_path %td= product_build_list.human_status - %td= link_to t("layout.product_build_lists.delete"), platform_product_product_build_list_path(product_build_list.product.platform, product_build_list.product, product_build_list), :method => "delete", :confirm => t("layout.confirm") if can? :delete, product_build_list + %td= link_to t("layout.product_build_lists.delete"), platform_product_product_build_list_path(product_build_list.product.platform, product_build_list.product, product_build_list), :method => "delete", :confirm => t("layout.confirm") if can? :destroy, product_build_list %td= product_build_list.notified_at \ No newline at end of file From 02cbec8d86b07857fcf1ebbfbda29f9e5ec2c4bb Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 29 Feb 2012 15:15:49 +0400 Subject: [PATCH 49/52] [Refs #221] Add xml-rpc call for iso container destroy --- app/models/product_build_list.rb | 14 ++++++++++++-- lib/product_builder.rb | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index f9078f19d..cae1b3bba 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -14,6 +14,7 @@ class ProductBuildList < ActiveRecord::Base attr_accessor :base_url after_create :xml_rpc_create + after_destroy :xml_delete_iso_container def container_path "/downloads/#{product.platform.name}/product/#{id}/" @@ -34,8 +35,17 @@ class ProductBuildList < ActiveRecord::Base if result == ProductBuilder::SUCCESS return true else - # return false - raise "Failed to create product_build_list #{id} inside platform #{product.platform.name} tar url #{tar_url} with code #{result}." + raise "Failed to create product_build_list #{id} inside platform #{platform.name} tar url #{tar_url} with code #{result}." + end + end + + def xml_delete_iso_container + result = ProductBuilder.delete_iso_container platform.name, id + if result == ProductBuilder::SUCCESS + return true + else + raise "Failed to destroy product_build_list #{id} inside platform #{platform.name} with code #{result}." end end + end diff --git a/lib/product_builder.rb b/lib/product_builder.rb index dfcac41df..65d2b5530 100644 --- a/lib/product_builder.rb +++ b/lib/product_builder.rb @@ -14,4 +14,8 @@ class ProductBuilder call('create_product', pbl.id.to_s, pbl.product.platform.name, pbl.product.ks, pbl.product.menu, pbl.product.build_script, pbl.product.counter, [], pbl.product.tar.exists? ? "#{pbl.base_url}#{pbl.product.tar.url}" : '') end + + def self.delete_iso_container(plname, id): + self.client(pbl.product.platform.distrib_type).call('delete_iso_container', plname, id) + end end From 6e15ee3e96a5f59be3adf57d6bd2ca4281813318 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 29 Feb 2012 15:47:05 +0400 Subject: [PATCH 50/52] [Refs #221] Fix syntax error --- lib/product_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/product_builder.rb b/lib/product_builder.rb index 65d2b5530..c774de089 100644 --- a/lib/product_builder.rb +++ b/lib/product_builder.rb @@ -15,7 +15,7 @@ class ProductBuilder pbl.product.counter, [], pbl.product.tar.exists? ? "#{pbl.base_url}#{pbl.product.tar.url}" : '') end - def self.delete_iso_container(plname, id): + def self.delete_iso_container(plname, id) self.client(pbl.product.platform.distrib_type).call('delete_iso_container', plname, id) end end From b20c533e6b7ae4ae71238004a7d20a424d769f82 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 29 Feb 2012 16:00:02 +0400 Subject: [PATCH 51/52] [Refs #221] Fix xml-rpc call --- app/models/product_build_list.rb | 2 +- lib/product_builder.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index cae1b3bba..24ee0afab 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -40,7 +40,7 @@ class ProductBuildList < ActiveRecord::Base end def xml_delete_iso_container - result = ProductBuilder.delete_iso_container platform.name, id + result = ProductBuilder.delete_iso_container self if result == ProductBuilder::SUCCESS return true else diff --git a/lib/product_builder.rb b/lib/product_builder.rb index c774de089..a845f2dda 100644 --- a/lib/product_builder.rb +++ b/lib/product_builder.rb @@ -15,7 +15,7 @@ class ProductBuilder pbl.product.counter, [], pbl.product.tar.exists? ? "#{pbl.base_url}#{pbl.product.tar.url}" : '') end - def self.delete_iso_container(plname, id) - self.client(pbl.product.platform.distrib_type).call('delete_iso_container', plname, id) + def self.delete_iso_container pbl # product_build_list + self.client(pbl.product.platform.distrib_type).call('delete_iso_container', pbl.product.platform.name, pbl.id.to_s) end end From 05eac4918ffd8f7fc2613ad4ed18d26c773b0e8c Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Wed, 29 Feb 2012 19:10:01 +0400 Subject: [PATCH 52/52] Fix NoMethodError: undefined method `default_order' for ActiveRecord::Relation --- app/controllers/categories_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 3dae0ee00..f7ed16b9d 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -19,10 +19,10 @@ class CategoriesController < ApplicationController if @platform @categories = Category.select('categories.id, categories.name, categories.ancestry, count(projects.id) projects_count'). joins(:projects => :repositories).where('repositories.platform_id = ?', @platform.id). - having('count(projects.id) > 0').group('categories.id, categories.name, categories.ancestry, projects_count').default_order + having('count(projects.id) > 0').group('categories.id, categories.name, categories.ancestry, projects_count') render 'index2' else - @categories = Category.default_order.paginate(:page => params[:page]) + @categories = Category.paginate(:page => params[:page]) end end