[issue #425] Changed object to actor in Relation and to eventable in

EventLog
This commit is contained in:
George Vinogradov 2012-04-26 05:38:33 +04:00
parent 2a24997eb4
commit de093d7065
40 changed files with 175 additions and 143 deletions

View File

@ -33,10 +33,10 @@ class MembersController < ApplicationController
params['user'].keys.each { |user_id|
role = params['user'][user_id]
if relation = parent.objects.find_by_object_id_and_object_type(user_id, 'User')
if relation = parent.actors.where(:actor_id => user_id, :actor_type => 'User') #find_by_actor_id_and_actor_type(user_id, 'User')
relation.update_attribute(:role, role)
else
relation = parent.objects.build(:object_id => user_id, :object_type => 'User', :role => role)
relation = parent.actors.build(:actor_id => user_id, :actor_type => 'User', :role => role)
relation.save!
end
} if params['user']
@ -53,7 +53,7 @@ class MembersController < ApplicationController
def remove
if params[:id]
u = User.find(params[:id])
Relation.by_object(u).by_target(parent)[0].destroy
Relation.by_actor(u).by_target(parent)[0].destroy
redirect_to groups_path
else
@ -65,7 +65,7 @@ class MembersController < ApplicationController
all_user_ids.each do |user_id|
u = User.find(user_id)
Relation.by_object(u).by_target(parent).each {|r| r.destroy}
Relation.by_actor(u).by_target(parent).each {|r| r.destroy}
end
redirect_to edit_group_members_path(parent)
@ -75,8 +75,8 @@ class MembersController < ApplicationController
def add
if params['user_id'] and !params['user_id'].empty?
@user = User.find_by_uname(params['user_id'])
unless parent.objects.exists? :object_id => @user.id, :object_type => 'User'
relation = parent.objects.build(:object_id => @user.id, :object_type => 'User', :role => params[:role])
unless parent.actors.exists? :actor_id => @user.id, :actor_type => 'User'
relation = parent.actors.build(:actor_id => @user.id, :actor_type => 'User', :role => params[:role])
if relation.save
flash[:notice] = t("flash.members.successfully_added")
else

View File

@ -95,14 +95,14 @@ class PlatformsController < ApplicationController
def remove_members
all_user_ids = params['user_remove'].inject([]) {|a, (k, v)| a << k if v.first == '1'; a}
all_user_ids.each do |uid|
Relation.by_target(@platform).where(:object_id => uid, :object_type => 'User').each{|r| r.destroy}
Relation.by_target(@platform).where(:actor_id => uid, :actor_type => 'User').each{|r| r.destroy}
end
redirect_to members_platform_path(@platform)
end
def remove_member
u = User.find(params[:member_id])
Relation.by_object(u).by_target(@platform).each{|r| r.destroy}
Relation.by_actor(u).by_target(@platform).each{|r| r.destroy}
redirect_to members_platform_path(@platform)
end
@ -110,11 +110,11 @@ class PlatformsController < ApplicationController
def add_member
if params[:member_id].present?
member = User.find(params[:member_id])
if @platform.relations.exists?(:object_id => member.id, :object_type => member.class.to_s) or @platform.owner == member
if @platform.relations.exists?(:actor_id => member.id, :actor_type => member.class.to_s) or @platform.owner == member
flash[:warning] = t('flash.platform.members.already_added', :name => member.uname)
else
rel = @platform.relations.build(:role => 'admin')
rel.object = member
rel.actor = member
if rel.save
flash[:notice] = t('flash.platform.members.successfully_added', :name => member.uname)
else

View File

@ -28,7 +28,7 @@ module ProjectsHelper
end
def alone_member?(project)
Relation.by_target(project).by_object(current_user).size > 0
Relation.by_target(project).by_actor(current_user).size > 0
end
def participant_path(participant)

View File

@ -46,7 +46,7 @@ class Ability
can [:read, :create, :autocomplete_group_uname], Group
can [:update, :manage_members], Group do |group|
group.objects.exists?(:object_type => 'User', :object_id => user.id, :role => 'admin') # or group.owner_id = user.id
group.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin') # or group.owner_id = user.id
end
can :destroy, Group, :owner_id => user.id
@ -60,7 +60,7 @@ class Ability
can(:fork, Project) {|project| can? :read, project}
can(:fork_to_group, Project) {|project| project.owner_type == 'Group' and can? :update, project.owner}
can(:destroy, Project) {|project| owner? project}
can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.objects.exists?(:object_type => 'User', :object_id => user.id, :role => 'admin')}
can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin')}
can :remove_user, Project
can [:read, :owned], BuildList, :user_id => user.id
@ -143,28 +143,28 @@ class Ability
parent ||= table
["#{table}.#{key} IN (
SELECT target_id FROM relations WHERE relations.target_type = ? AND
(relations.object_type = 'User' AND relations.object_id = ? OR
relations.object_type = 'Group' AND relations.object_id IN (?)))", parent.classify, @user, @user.group_ids]
(relations.actor_type = 'User' AND relations.actor_id = ? OR
relations.actor_type = 'Group' AND relations.actor_id IN (?)))", parent.classify, @user, @user.group_ids]
end
def relation_exists_for(object, roles)
object.relations.exists?(:object_id => @user.id, :object_type => 'User', :role => roles) or
object.relations.exists?(:object_id => @user.group_ids, :object_type => 'Group', :role => roles)
def relation_exists_for(target, roles)
target.relations.exists?(:actor_id => @user.id, :actor_type => 'User', :role => roles) or
target.relations.exists?(:actor_id => @user.group_ids, :actor_type => 'Group', :role => roles)
end
def local_reader?(object)
relation_exists_for(object, %w{reader writer admin}) or owner?(object)
def local_reader?(target)
relation_exists_for(target, %w{reader writer admin}) or owner?(target)
end
def local_writer?(object)
relation_exists_for(object, %w{writer admin}) or owner?(object)
def local_writer?(target)
relation_exists_for(target, %w{writer admin}) or owner?(target)
end
def local_admin?(object)
relation_exists_for(object, 'admin') or owner?(object)
def local_admin?(target)
relation_exists_for(target, 'admin') or owner?(target)
end
def owner?(object)
object.owner == @user or @user.own_groups.include?(object.owner)
def owner?(target)
target.owner == @user or @user.own_groups.include?(target.owner)
end
end

View File

@ -17,7 +17,7 @@ class Collaborator
def find_by_project(project)
res = []
project.relations.each do |r|
res << from_relation(r) unless project.owner_id == r.object_id and project.owner_type == r.object_type
res << from_relation(r) unless project.owner_id == r.actor_id and project.owner_type == r.actor_type
end
return res
end
@ -64,7 +64,7 @@ class Collaborator
def relation=(model)
@relation = model
@actor = @relation.object
@actor = @relation.actor
@project = @relation.target
end
@ -134,15 +134,15 @@ class Collaborator
end
def relation
return @relation if @relation.present? and @relation.object == @actor and @relation.target == @project
return @relation if @relation.present? and @relation.actor == @actor and @relation.target == @project
if @actor.present? and @project.present?
@relation = Relation.by_object(@actor).by_target(@project).limit(1).first
@relation ||= Relation.new(:object_id => @actor.id, :object_type => @actor.class.to_s,
@relation = Relation.by_actor(@actor).by_target(@project).limit(1).first
@relation ||= Relation.new(:actor_id => @actor.id, :actor_type => @actor.class.to_s,
:target_id => @project.id, :target_type => 'Project')
else
@relation = Relation.new
@relation.object = @actor
@relation.actor = @actor
@relation.target = @project
end
@relation

View File

@ -61,7 +61,7 @@ class Comment < ActiveRecord::Base
if issue_comment?
commentable.subscribes.create(:user => user) if !commentable.subscribes.exists?(:user_id => user.id)
elsif commit_comment?
recipients = project.relations.by_role('admin').where(:object_type => 'User').map &:object # admins
recipients = project.relations.by_role('admin').where(:actor_type => 'User').map &:actor # admins
recipients << user << User.where(:email => commentable.committer.email).first # commentor and committer
recipients << project.owner if project.owner_type == 'User' # project owner
recipients.compact.uniq.each do |user|

View File

@ -1,7 +1,7 @@
# -*- encoding : utf-8 -*-
class EventLog < ActiveRecord::Base
belongs_to :user
belongs_to :object, :polymorphic => true
belongs_to :eventable, :polymorphic => true
# self.per_page = 1
@ -10,7 +10,7 @@ class EventLog < ActiveRecord::Base
before_create do
self.user_name = user.try(:uname) || 'guest'
self.object_name ||= object.name if object.respond_to?(:name)
self.eventable_name ||= eventable.name if eventable.respond_to?(:name)
end
# after_create { self.class.current_controller = nil }

View File

@ -3,24 +3,24 @@ class EventLogObserver < ActiveRecord::Observer
observe :user, :private_user, :platform, :repository, :project, :product, :build_list, :product_build_list
def after_create(record)
ActiveSupport::Notifications.instrument("event_log.observer", :object => record)
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record)
end
def before_update(record)
case record.class.to_s
when 'BuildList'
if record.status_changed? and [BuildList::BUILD_CANCELED, BuildList::BUILD_PUBLISHED].include?(record.status)
ActiveSupport::Notifications.instrument("event_log.observer", :object => record)
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record)
end
when 'Platform'
if record.visibility_changed?
ActiveSupport::Notifications.instrument "event_log.observer", :object => record,
ActiveSupport::Notifications.instrument "event_log.observer", :eventable => record,
:message => I18n.t("activerecord.attributes.platform.visibility_types.#{record.visibility}")
end
end
end
def after_destroy(record)
ActiveSupport::Notifications.instrument("event_log.observer", :object => record)
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record)
end
end

View File

@ -2,12 +2,12 @@
class Group < ActiveRecord::Base
belongs_to :owner, :class_name => 'User'
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 :relations, :as => :actor, :dependent => :destroy
has_many :actors, :as => :target, :class_name => 'Relation'
has_many :targets, :as => :actor, :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 :members, :through => :actors, :source => :actor, :source_type => 'User', :autosave => true
has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy
has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy
@ -18,7 +18,7 @@ class Group < ActiveRecord::Base
scope :opened, where('1=1')
scope :by_owner, lambda {|owner| where(:owner_id => owner.id)}
scope :by_admin, lambda {|admin| joins(:objects).where(:'relations.role' => 'admin', :'relations.object_id' => admin.id, :'relations.object_type' => 'User')}
scope :by_admin, lambda {|admin| joins(:actors).where(:'relations.role' => 'admin', :'relations.actor_id' => admin.id, :'relations.actor_type' => 'User')}
include Modules::Models::ActsLikeMember

View File

@ -54,7 +54,7 @@ class Issue < ActiveRecord::Base
end
def collect_recipient_ids
recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) }
recipients = self.project.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) }
recipients = recipients | [self.assignee_id] if self.assignee_id
recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User'

View File

@ -10,8 +10,8 @@ class Platform < ActiveRecord::Base
has_many :products, :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 :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy
has_many :members, :through => :actors, :source => :actor, :source_type => 'User'
validates :description, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
@ -148,8 +148,8 @@ class Platform < ActiveRecord::Base
def update_owner_relation
if owner_id_was != owner_id
r = relations.where(:object_id => owner_id_was, :object_type => owner_type_was)[0]
r.update_attributes(:object_id => owner_id, :object_type => owner_type)
r = relations.where(:actor_id => owner_id_was, :actor_type => owner_type_was)[0]
r.update_attributes(:actor_id => owner_id, :actor_type => owner_type)
end
end

View File

@ -13,8 +13,8 @@ class Project < ActiveRecord::Base
has_many :repositories, :through => :project_to_repositories
has_many :relations, :as => :target, :dependent => :destroy
has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User'
has_many :groups, :through => :relations, :source => :object, :source_type => 'Group'
has_many :collaborators, :through => :relations, :source => :actor, :source_type => 'User'
has_many :groups, :through => :relations, :source => :actor, :source_type => 'Group'
has_many :labels
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^[a-zA-Z0-9_\-\+\.]+$/}
@ -206,7 +206,7 @@ class Project < ActiveRecord::Base
end
def owner_and_admin_ids
recipients = self.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) }
recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) }
recipients = recipients | [self.owner_id] if self.owner_type == 'User'
recipients
end

View File

@ -1,22 +1,22 @@
# -*- encoding : utf-8 -*-
class Relation < ActiveRecord::Base
belongs_to :target, :polymorphic => true
belongs_to :object, :polymorphic => true
belongs_to :actor, :polymorphic => true
ROLES = %w[reader writer admin]
validates :role, :inclusion => {:in => ROLES}
# validate { errors.add(:object, :taken) if Relation.where(:object_type => self.object_type, :object_id => self.object_id).present? }
# validate { errors.add(:actor, :taken) if Relation.where(:actor_type => self.actor_type, :actor_id => self.actor_id).present? }
before_validation :add_default_role
scope :by_user_through_groups, lambda {|u| where("object_type = 'User' AND object_id = ? OR object_type = 'Group' AND object_id IN (?)", u.id, u.group_ids)}
scope :by_object, lambda {|obj| {:conditions => ['object_id = ? AND object_type = ?', obj.id, obj.class.to_s]}}
scope :by_user_through_groups, lambda {|u| where("actor_type = 'User' AND actor_id = ? OR actor_type = 'Group' AND actor_id IN (?)", u.id, u.group_ids)}
scope :by_actor, lambda {|obj| {:conditions => ['actor_id = ? AND actor_type = ?', obj.id, obj.class.to_s]}}
scope :by_target, lambda {|tar| {:conditions => ['target_id = ? AND target_type = ?', tar.id, tar.class.to_s]}}
scope :by_role, lambda {|role| {:conditions => ['role = ?', role]}}
def self.create_with_role(object, target, role)
r = new
r.object = object
def self.create_with_role(actor, target, role)
r = self.new
r.actor = actor
r.target = target
r.role = role
r.save

View File

@ -24,8 +24,8 @@ class User < ActiveRecord::Base
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', :dependent => :destroy
has_many :relations, :as => :actor, :dependent => :destroy
has_many :targets, :as => :actor, :class_name => 'Relation', :dependent => :destroy
has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true

View File

@ -39,7 +39,7 @@
- Relation::ROLES.each_with_index do |role, i|
%td
.radio
= radio_button_tag "user[#{user.id}]", role, ((@project.relations.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), :class => 'niceRadio'
= radio_button_tag "user[#{user.id}]", role, ((@project.relations.exists? :actor_id => user.id, :actor_type => 'User', :role => role) ? :checked : nil), :class => 'niceRadio'
.forradio= t("layout.collaborators.role_names.#{ role }")
= link_to_function t("layout.delete_selected"), "deleteAdminMember();", :class => 'button'
= link_to_function t("layout.save"), "saveAdminMember();", :class => 'button right_floated'
@ -84,7 +84,7 @@
- Relation::ROLES.each_with_index do |role, i|
%td
.radio
= radio_button_tag "group[#{group.id}]", role, ((@project.relations.exists? :object_id => group.id, :object_type => 'Group', :role => role) ? :checked : nil), :class => 'niceRadio'
= radio_button_tag "group[#{group.id}]", role, ((@project.relations.exists? :actor_id => group.id, :actor_type => 'Group', :role => role) ? :checked : nil), :class => 'niceRadio'
.forradio= t("layout.collaborators.role_names.#{ role }")
= link_to_function t("layout.delete_selected"), "deleteAdminGroup();", :class => 'button'
= link_to_function t("layout.save"), "saveAdminGroup();", :class => 'button right_floated'

View File

@ -1,8 +1,8 @@
= surround '[', ']' do
= I18n.t "event_log.controllers.#{el.controller.underscore}", :default => el.controller
= I18n.t "event_log.actions.#{el.controller.underscore}.#{el.action}", :default => :"event_log.actions.#{el.action}"
- if el.object_id.present? and el.object_type.present?
= I18n.t "activerecord.models.#{el.object_type.underscore}"
= el.object_name
= "(id##{el.object_id})" # link_to "id##{el.object_id}", el.object
- if el.eventable_id.present? and el.eventable_type.present?
= I18n.t "activerecord.models.#{el.eventable_type.underscore}"
= el.eventable_name
= "(id##{el.eventable_id})" # link_to "id##{el.eventable_id}", el.eventable
= el.message

View File

@ -23,7 +23,7 @@
- Relation::ROLES.each_with_index do |role, i|
%td
.radio
= radio_button_tag "user[#{user.id}]", role, ((parent.objects.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), :class => 'niceRadio'
= radio_button_tag "user[#{user.id}]", role, ((parent.actors.exists? :actor_id => user.id, :actor_type => 'User', :role => role) ? :checked : nil), :class => 'niceRadio'
.forradio= t("layout.collaborators.role_names.#{ role }")
= link_to_function t("layout.delete"), "deleteAdminMember();", :class => 'button'
.both

View File

@ -1,6 +1,6 @@
# -*- encoding : utf-8 -*-
Warden::Manager.after_authentication do |user,auth,opts| # after_set_user, :except => fetch
ActiveSupport::Notifications.instrument("event_log.observer", :object => user)
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => user)
end
Warden::Manager.before_failure do |env, opts|
@ -10,14 +10,14 @@ Warden::Manager.before_failure do |env, opts|
end
Warden::Manager.before_logout do |user,auth,opts|
ActiveSupport::Notifications.instrument("event_log.observer", :object => user)
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => user)
end
ActiveSupport::Notifications.subscribe "event_log.observer" do |name, start, finish, id, payload|
if c = EventLog.current_controller
object = payload[:object]
message = payload[:message].presence; message ||= object.event_log_message if object.respond_to?(:event_log_message)
eventable = payload[:eventable]
message = payload[:message].presence; message ||= eventable.event_log_message if eventable.respond_to?(:event_log_message)
EventLog.create_with_current_controller :kind => (payload[:kind].presence || 'info'), :message => message,
:object => object, :object_name => payload[:object_name].presence
:eventable => eventable, :eventable_name => payload[:eventable_name].presence
end
end

View File

@ -0,0 +1,15 @@
class ChangeObjectToActorInRelation < ActiveRecord::Migration
def up
change_table :relations do |t|
t.rename :object_id, :actor_id
t.rename :object_type, :actor_type
end
end
def down
change_table :relations do |t|
t.rename :actor_id, :object_id
t.rename :actor_type, :object_type
end
end
end

View File

@ -0,0 +1,17 @@
class ChangeObjectToEventableInEventLog < ActiveRecord::Migration
def up
change_table :event_logs do |t|
t.rename :object_id, :eventable_id
t.rename :object_type, :eventable_type
t.rename :object_name, :eventable_name
end
end
def down
change_table :event_logs do |t|
t.rename :eventable_id, :object_id
t.rename :eventable_type, :object_type
t.rename :eventable_name, :object_name
end
end
end

View File

@ -11,14 +11,14 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120418100619) do
ActiveRecord::Schema.define(:version => 20120425190938) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
t.string "kind"
t.text "data"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "arches", :force => true do |t|
@ -112,9 +112,9 @@ ActiveRecord::Schema.define(:version => 20120418100619) do
create_table "event_logs", :force => true do |t|
t.integer "user_id"
t.string "user_name"
t.integer "object_id"
t.string "object_type"
t.string "object_name"
t.integer "eventable_id"
t.string "eventable_type"
t.string "eventable_name"
t.string "ip"
t.string "kind"
t.string "protocol"
@ -262,24 +262,25 @@ ActiveRecord::Schema.define(:version => 20120418100619) do
t.integer "build_count", :default => 0, :null => false
end
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
create_table "register_requests", :force => true do |t|
t.string "name"
t.string "email"
t.string "token"
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "interest"
t.text "more"
end
add_index "register_requests", ["email"], :name => "index_register_requests_on_email", :unique => true, :case_sensitive => false
add_index "register_requests", ["token"], :name => "index_register_requests_on_token", :unique => true, :case_sensitive => false
create_table "relations", :force => true do |t|
t.integer "object_id"
t.string "object_type"
t.integer "actor_id"
t.string "actor_type"
t.integer "target_id"
t.string "target_type"
t.datetime "created_at"
@ -323,19 +324,15 @@ ActiveRecord::Schema.define(:version => 20120418100619) do
t.string "name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :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"
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.datetime "reset_password_sent_at"
t.text "professional_experience"
t.string "site"
t.string "company"
@ -347,6 +344,9 @@ ActiveRecord::Schema.define(:version => 20120418100619) do
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "authentication_token"
end

View File

@ -8,10 +8,10 @@ module Modules
scope :not_member_of, lambda { |item|
where("
#{klass.table_name}.id NOT IN (
SELECT relations.object_id
SELECT relations.actor_id
FROM relations
WHERE (
relations.object_type = '#{klass.to_s}'
relations.actor_type = '#{klass.to_s}'
AND relations.target_type = '#{item.class.to_s}'
AND relations.target_id = #{item.id}
)

View File

@ -5,7 +5,7 @@ module Modules
extend ActiveSupport::Concern
included do
after_create lambda { relations.create :object_id => owner.id, :object_type => owner.class.to_s, :role => 'admin' }
after_create lambda { relations.create :actor_id => owner.id, :actor_type => owner.class.to_s, :role => 'admin' }
end
module ClassMethods

View File

@ -103,7 +103,7 @@ describe BuildListsController do
@owner_user = @project.owner
@member_user = FactoryGirl.create(:user)
rel = @project.relations.build(:role => 'reader')
rel.object = @member_user
rel.actor = @member_user
rel.save
@user = FactoryGirl.create(:user)
set_session_for(@user)
@ -116,7 +116,7 @@ describe BuildListsController do
@build_list2 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden'))
@build_list3 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :owner => @user, :visibility => 'hidden'))
@build_list4 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden'))
@build_list4.project.relations.create :role => 'reader', :object_id => @user.id, :object_type => 'User'
@build_list4.project.relations.create :role => 'reader', :actor_id => @user.id, :actor_type => 'User'
end
it 'should be able to perform index action' do
@ -177,17 +177,17 @@ describe BuildListsController do
before(:each) do
@owner_group = FactoryGirl.create(:group)
@owner_user = FactoryGirl.create(:user)
@owner_group.objects.create :role => 'reader', :object_id => @owner_user.id, :object_type => 'User'
@owner_group.actors.create :role => 'reader', :actor_id => @owner_user.id, :actor_type => 'User'
@member_group = FactoryGirl.create(:group)
@member_user = FactoryGirl.create(:user)
@member_group.objects.create :role => 'reader', :object_id => @member_user.id, :object_type => 'User'
@member_group.actors.create :role => 'reader', :actor_id => @member_user.id, :actor_type => 'User'
@group = FactoryGirl.create(:group)
@user = FactoryGirl.create(:user)
@group.objects.create :role => 'reader', :object_id => @user.id, :object_type => 'User'
@group.actors.create :role => 'reader', :actor_id => @user.id, :actor_type => 'User'
@project = FactoryGirl.create(:project, :owner => @owner_group)
@project.relations.create :role => 'reader', :object_id => @member_group.id, :object_type => 'Group'
@project.relations.create :role => 'reader', :actor_id => @member_group.id, :actor_type => 'Group'
@build_list = FactoryGirl.create(:build_list_core, :project => @project)
@ -201,7 +201,7 @@ describe BuildListsController do
@build_list2 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden'))
@build_list3 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :owner => @group, :visibility => 'hidden'))
@build_list4 = FactoryGirl.create(:build_list_core, :project => FactoryGirl.create(:project, :visibility => 'hidden'))
@build_list4.project.relations.create :role => 'reader', :object_id => @group.id, :object_type => 'Group'
@build_list4.project.relations.create :role => 'reader', :actor_id => @group.id, :actor_type => 'Group'
end
it 'should be able to perform index action' do

View File

@ -31,12 +31,12 @@ shared_examples_for 'project admin user' do
it 'should add new collaborator with reader role' do
post :create, @create_params.merge(:collaborator => @user_params)
@project.relations.exists?(:object_type => 'User', :object_id => @another_user.id, :role => 'reader').should be_true
@project.relations.exists?(:actor_type => 'User', :actor_id => @another_user.id, :role => 'reader').should be_true
end
it 'should add new group with reader role' do
post :create, @create_params.merge(:collaborator => @group_params)
@project.relations.exists?(:object_type => 'Group', :object_id => @group.id, :role => 'reader').should be_true
@project.relations.exists?(:actor_type => 'Group', :actor_id => @group.id, :role => 'reader').should be_true
end
it 'should be able to set reader role for any user' do
@ -102,7 +102,7 @@ describe CollaboratorsController do
# @user.relations
set_session_for(@user)
@group = FactoryGirl.create(:group)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
create_params
end
@ -117,7 +117,7 @@ describe CollaboratorsController do
@group = FactoryGirl.create(:group)
@project.update_attribute(:owner, @user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
create_params
end
@ -129,7 +129,7 @@ describe CollaboratorsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'user with no rights for this project'
@ -139,7 +139,7 @@ describe CollaboratorsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
end
it_should_behave_like 'user with no rights for this project'

View File

@ -93,7 +93,7 @@ describe CommentsController do
context 'for project admin user' do
before(:each) do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'user with create comment rights for commits'
@ -119,7 +119,7 @@ describe CommentsController do
context 'for project reader user' do
before(:each) do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'user with create comment rights for commits'
@ -130,7 +130,7 @@ describe CommentsController do
context 'for project writer user' do
before(:each) do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
end
it_should_behave_like 'user with create comment rights for commits'

View File

@ -90,7 +90,7 @@ describe CommentsController do
context 'for project admin user' do
before(:each) do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'user with create comment rights'
@ -112,7 +112,7 @@ describe CommentsController do
context 'for project reader user' do
before(:each) do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'user with create comment rights'
@ -123,7 +123,7 @@ describe CommentsController do
context 'for project writer user' do
before(:each) do
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
end
it_should_behave_like 'user with create comment rights'

View File

@ -117,7 +117,7 @@ describe GroupsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'update_member_relation'
@ -130,7 +130,7 @@ describe GroupsController do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@group.update_attribute(:owner, @user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'update_member_relation'
@ -141,7 +141,7 @@ describe GroupsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'reader')
@group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'no group user'

View File

@ -115,7 +115,7 @@ describe IssuesController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'issue user with project reader rights'
@ -130,7 +130,7 @@ describe IssuesController do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'issue user with project reader rights'
@ -144,7 +144,7 @@ describe IssuesController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'issue user with project reader rights'
@ -166,7 +166,7 @@ describe IssuesController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
end
it_should_behave_like 'issue user with project reader rights'

View File

@ -15,12 +15,12 @@ describe MembersController do
it 'should add member to group' do
post :add, @add_params
response.should redirect_to(edit_group_members_path(@group))
Relation.by_target(@group).by_object(@another_user).count.should eql(1)
Relation.by_target(@group).by_actor(@another_user).count.should eql(1)
end
it 'should add reader member to group' do
post :add, @add_params
Relation.by_target(@group).by_object(@another_user).first.role.should eql('reader')
Relation.by_target(@group).by_actor(@another_user).first.role.should eql('reader')
end
end
end

View File

@ -105,7 +105,7 @@ describe PlatformsController do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.update_attribute(:owner, @user)
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'user without create rights'
@ -127,7 +127,7 @@ describe PlatformsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'platform index viewer'

View File

@ -92,7 +92,7 @@ describe ProductBuildListsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@pbl.product.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@pbl.product.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'admin'

View File

@ -64,7 +64,7 @@ describe ProductsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'admin user'

View File

@ -48,7 +48,7 @@ describe ProjectsController do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'projects user with admin rights'
@ -74,7 +74,7 @@ describe ProjectsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'projects user with reader rights'
@ -84,7 +84,7 @@ describe ProjectsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
end
it_should_behave_like 'projects user with reader rights'
@ -103,7 +103,7 @@ describe ProjectsController do
it 'should be able to fork project to group' do
group = FactoryGirl.create(:group)
group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
post :fork, :id => @project.id, :group => group.id
response.should redirect_to(project_path(group.projects.first.id))
end

View File

@ -108,7 +108,7 @@ describe RepositoriesController do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@repository.platform.update_attribute(:owner, @user)
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@repository.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'platform admin user'

View File

@ -66,7 +66,7 @@ describe SubscribesController do
before(:each) do
@user = FactoryGirl.create(:admin)
set_session_for(@user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
@destroy_params = @destroy_params.merge({:id => @user.id})
end

View File

@ -147,7 +147,7 @@ describe CanCan do
context 'with read rights' do
before(:each) do
@project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader')
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader')
end
it 'should be able to read project' do
@ -165,7 +165,7 @@ describe CanCan do
context 'with writer rights' do
before(:each) do
@project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'writer')
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'writer')
end
[:read, :create, :new].each do |action|
@ -184,7 +184,7 @@ describe CanCan do
context 'with admin rights' do
before(:each) do
@project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'admin')
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'admin')
end
[:read, :update].each do |action|
@ -258,7 +258,7 @@ describe CanCan do
context 'with read rights' do
before(:each) do
@platform.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader')
@platform.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader')
end
it "should be able to read platform" do
@ -286,7 +286,7 @@ describe CanCan do
context 'with read rights' do
before(:each) do
@repository.platform.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader')
@repository.platform.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'reader')
end
it "should be able to read repository" do
@ -298,7 +298,7 @@ describe CanCan do
context 'build list relations' do
before(:each) do
@project = FactoryGirl.create(:project)
@project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'writer')
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'writer')
@build_list = FactoryGirl.create(:build_list, :project => @project)
end

View File

@ -61,7 +61,7 @@ describe Comment do
set_comments_data_for_commit
@admin = FactoryGirl.create(:user)
@ability = Ability.new(@admin)
@project.relations.create!(:object_type => 'User', :object_id => @admin.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @admin.id, :role => 'admin')
ActionMailer::Base.deliveries = []
end

View File

@ -56,7 +56,7 @@ describe Comment do
set_commentable_data
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it 'should create comment' do
@ -85,7 +85,7 @@ describe Comment do
set_commentable_data
@project.update_attribute(:owner, @user)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it 'should create comment' do

View File

@ -34,7 +34,7 @@ describe Group do
before(:each) do
@user = FactoryGirl.create(:user)
@another_user = FactoryGirl.create(:user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
@ability = Ability.new(@user)
end
@ -63,7 +63,7 @@ describe Group do
before(:each) do
@user = FactoryGirl.create(:user)
@group.update_attribute(:owner, @user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
@ability = Ability.new(@user)
end
@ -77,7 +77,7 @@ describe Group do
context 'for group reader and writer user' do
before(:each) do
@user = FactoryGirl.create(:user)
@group.objects.create(:object_type => 'User', :object_id => @user.id, :role => 'reader')
@group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
@ability = Ability.new(@user)
end