2011-12-28 02:57:42 +00:00
|
|
|
# If rules goes one by one CanCan joins them by 'OR' sql operator
|
|
|
|
# If rule has multiple conditions CanCan joins them by 'AND' sql operator
|
2012-01-12 11:22:12 +00:00
|
|
|
# WARNING:
|
2011-12-28 02:57:42 +00:00
|
|
|
# - put cannot rules _after_ can rules and not before!
|
2012-01-12 11:22:12 +00:00
|
|
|
# - beware inner joins. Use sub queries against them!
|
2011-12-28 02:57:42 +00:00
|
|
|
|
2011-11-15 20:05:08 +00:00
|
|
|
class Ability
|
|
|
|
include CanCan::Ability
|
|
|
|
|
|
|
|
def initialize(user)
|
|
|
|
user ||= User.new # guest user (not logged in)
|
2011-12-28 02:57:42 +00:00
|
|
|
@user = user
|
2011-12-21 14:48:16 +00:00
|
|
|
|
2012-03-01 17:33:46 +00:00
|
|
|
# Shared rights between guests and registered users
|
2014-01-21 04:51:49 +00:00
|
|
|
can [:show, :archive], Project, visibility: 'open'
|
|
|
|
can :get_id, Project, visibility: 'open' # api
|
2013-07-15 12:02:06 +01:00
|
|
|
can(:refs_list, Project) {|project| can? :show, project}
|
2014-03-11 11:47:03 +00:00
|
|
|
can :read, Issue, project: { visibility: 'open' }
|
2014-01-21 04:51:49 +00:00
|
|
|
can [:read, :commits, :files], PullRequest, to_project: {visibility: 'open'}
|
|
|
|
can [:read, :log, :everything], BuildList, project: {visibility: 'open'}
|
|
|
|
can [:read, :log], ProductBuildList#, product: {platform: {visibility: 'open'}} # double nested hash don't work
|
2013-05-21 17:55:29 +01:00
|
|
|
can [:read, :search], Advisory
|
2012-09-25 10:46:19 +01:00
|
|
|
|
2012-09-06 18:09:10 +01:00
|
|
|
# Platforms block
|
2014-01-21 04:51:49 +00:00
|
|
|
can [:show, :members, :advisories], Platform, visibility: 'open'
|
|
|
|
can :platforms_for_build, Platform, visibility: 'open', platform_type: 'main'
|
2013-06-05 14:48:11 +01:00
|
|
|
can([:read, :get_list], MassBuild) {|mass_build| can?(:show, mass_build.save_to_platform) }
|
2014-01-21 04:51:49 +00:00
|
|
|
can [:read, :projects_list, :projects], Repository, platform: {visibility: 'open'}
|
|
|
|
can :read, Product, platform: {visibility: 'open'}
|
2012-09-06 18:09:10 +01:00
|
|
|
|
2012-10-02 16:14:08 +01:00
|
|
|
can :show, Group
|
|
|
|
can :show, User
|
2013-11-20 11:33:48 +00:00
|
|
|
can :possible_forks, Project
|
2012-10-02 16:14:08 +01:00
|
|
|
|
2012-03-01 17:33:46 +00:00
|
|
|
if user.guest? # Guest rights
|
2012-05-02 10:18:07 +01:00
|
|
|
# can [:new, :create], RegisterRequest
|
2012-03-01 17:33:46 +00:00
|
|
|
else # Registered user rights
|
|
|
|
if user.admin?
|
|
|
|
can :manage, :all
|
2012-03-27 22:28:50 +01:00
|
|
|
# Protection
|
2014-01-21 04:51:49 +00:00
|
|
|
cannot :approve, RegisterRequest, approved: true
|
|
|
|
cannot :reject, RegisterRequest, rejected: true
|
2012-03-27 22:28:50 +01:00
|
|
|
cannot [:destroy, :create], Subscribe
|
|
|
|
# Act admin as simple user
|
2014-01-21 04:51:49 +00:00
|
|
|
cannot :read, Product, platform: {platform_type: 'personal'}
|
2012-03-23 20:37:17 +00:00
|
|
|
cannot [:owned, :related], [BuildList, Platform]
|
2012-03-27 22:28:50 +01:00
|
|
|
cannot :membered, Project # list products which user members
|
2012-03-01 17:33:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if user.user?
|
2014-01-21 04:51:49 +00:00
|
|
|
can :edit, User, id: user.id
|
2012-10-02 17:54:55 +01:00
|
|
|
can [:read, :create], Group
|
2012-10-16 15:44:21 +01:00
|
|
|
can [:update, :manage_members, :members, :add_member, :remove_member, :update_member], Group do |group|
|
2014-01-21 04:51:49 +00:00
|
|
|
group.actors.exists?(actor_type: 'User', actor_id: user.id, role: 'admin') # or group.owner_id = user.id
|
2011-12-05 12:32:18 +00:00
|
|
|
end
|
2013-05-07 15:56:13 +01:00
|
|
|
can :write, Group do |group|
|
2014-01-21 04:51:49 +00:00
|
|
|
group.actors.exists?(actor_type: 'User', actor_id: user.id, role: ['writer', 'admin'])
|
2013-05-07 15:56:13 +01:00
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
can :destroy, Group, owner_id: user.id
|
2012-05-02 10:18:07 +01:00
|
|
|
can :remove_user, Group
|
2011-12-05 12:32:18 +00:00
|
|
|
|
2011-11-19 11:41:11 +00:00
|
|
|
can :create, Project
|
2013-11-15 19:36:37 +00:00
|
|
|
can([:mass_import, :run_mass_import], Project) if user.platforms.main.find{ |p| local_admin?(p) }.present?
|
2014-01-21 04:51:49 +00:00
|
|
|
can :read, Project, visibility: 'open'
|
|
|
|
can [:read, :archive, :membered, :get_id], Project, owner_type: 'User', owner_id: user.id
|
|
|
|
can [:read, :archive, :membered, :get_id], Project, owner_type: 'Group', owner_id: user_group_ids
|
2014-04-10 17:59:15 +01:00
|
|
|
# can([:read, :archive, :membered, :get_id], Project, read_relations_for('projects')) {|project| local_reader? project}
|
|
|
|
can([:read, :archive, :membered, :get_id], Project, read_relations_with_projects) {|project| local_reader? project}
|
2011-12-28 02:57:42 +00:00
|
|
|
can(:write, Project) {|project| local_writer? project} # for grack
|
2014-02-18 19:16:23 +00:00
|
|
|
can [:update, :sections, :manage_collaborators, :autocomplete_maintainers, :add_member, :remove_member, :update_member, :members, :schedule], Project do |project|
|
2013-04-15 11:30:48 +01:00
|
|
|
local_admin? project
|
|
|
|
end
|
2011-12-28 02:57:42 +00:00
|
|
|
can(:fork, Project) {|project| can? :read, project}
|
2012-04-19 20:45:50 +01:00
|
|
|
can(:fork, Project) {|project| project.owner_type == 'Group' and can? :update, project.owner}
|
2011-12-28 02:57:42 +00:00
|
|
|
can(:destroy, Project) {|project| owner? project}
|
2014-01-21 04:51:49 +00:00
|
|
|
can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.actors.exists?(actor_type: 'User', actor_id: user.id, role: 'admin')}
|
2012-03-07 21:34:49 +00:00
|
|
|
can :remove_user, Project
|
2012-10-02 14:24:53 +01:00
|
|
|
can :preview, Project
|
2011-11-19 11:41:11 +00:00
|
|
|
|
2013-05-16 10:52:55 +01:00
|
|
|
can([:read, :create, :edit, :destroy, :update], Hook) {|hook| can?(:edit, hook.project)}
|
2013-04-15 11:30:48 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
can [:read, :log, :owned, :everything], BuildList, user_id: user.id
|
|
|
|
can [:read, :log, :related, :everything], BuildList, project: {owner_type: 'User', owner_id: user.id}
|
|
|
|
can [:read, :log, :related, :everything], BuildList, project: {owner_type: 'Group', owner_id: user_group_ids}
|
2014-04-02 18:16:51 +01:00
|
|
|
# can([:read, :log, :everything, :list], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
|
2014-04-10 17:59:15 +01:00
|
|
|
# can([:read, :log, :everything, :list], BuildList, read_relations_for_build_lists_and_projects) {|build_list| can? :read, build_list.project}
|
|
|
|
can([:read, :log, :everything, :list], BuildList, read_relations_with_projects('build_lists')) {|build_list| can? :read, build_list.project}
|
2013-07-16 18:23:38 +01:00
|
|
|
|
2013-11-07 15:49:43 +00:00
|
|
|
can(:publish_into_testing, BuildList) { |build_list| can?(:create, build_list) && build_list.save_to_platform.main? }
|
2014-05-21 23:58:13 +01:00
|
|
|
can([:create, :rerun_tests], BuildList) {|build_list|
|
2013-07-04 20:39:02 +01:00
|
|
|
build_list.project.is_package &&
|
|
|
|
can?(:write, build_list.project) &&
|
2013-07-04 20:55:56 +01:00
|
|
|
(build_list.build_for_platform.blank? || can?(:show, build_list.build_for_platform))
|
2013-07-04 20:39:02 +01:00
|
|
|
}
|
2012-05-14 11:51:08 +01:00
|
|
|
|
2012-04-17 19:18:39 +01:00
|
|
|
can(:publish, BuildList) do |build_list|
|
2013-02-26 17:06:18 +00:00
|
|
|
if build_list.build_published?
|
2014-01-21 04:51:49 +00:00
|
|
|
local_admin?(build_list.save_to_platform) || build_list.save_to_repository.members.exists?(id: user.id)
|
2013-02-26 17:06:18 +00:00
|
|
|
else
|
|
|
|
build_list.save_to_repository.publish_without_qa ?
|
|
|
|
can?(:write, build_list.project) : local_admin?(build_list.save_to_platform)
|
2013-02-26 17:18:24 +00:00
|
|
|
end
|
2012-04-17 19:18:39 +01:00
|
|
|
end
|
2013-05-30 10:44:58 +01:00
|
|
|
can(:create_container, BuildList) do |build_list|
|
2012-09-21 20:48:30 +01:00
|
|
|
local_admin?(build_list.save_to_platform)
|
2012-04-17 19:18:39 +01:00
|
|
|
end
|
2013-05-30 10:44:58 +01:00
|
|
|
can(:reject_publish, BuildList) do |build_list|
|
|
|
|
build_list.save_to_repository.publish_without_qa ?
|
|
|
|
can?(:write, build_list.project) : local_admin?(build_list.save_to_platform)
|
|
|
|
end
|
2013-01-25 17:42:33 +00:00
|
|
|
can([:cancel, :create_container], BuildList) {|build_list| can?(:write, build_list.project)}
|
2011-12-28 02:57:42 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
can [:read, :owned, :related, :members], Platform, owner_type: 'User', owner_id: user.id
|
|
|
|
can [:read, :related, :members], Platform, owner_type: 'Group', owner_id: user_group_ids
|
2012-03-20 16:24:18 +00:00
|
|
|
can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform}
|
2014-01-21 04:51:49 +00:00
|
|
|
can [:read, :related], Platform, id: user.repositories.pluck(:platform_id)
|
2014-05-20 22:15:06 +01:00
|
|
|
can([:update, :destroy, :change_visibility, :remove_file], Platform) {|platform| owner?(platform) }
|
2013-03-07 10:05:53 +00:00
|
|
|
can([:local_admin_manage, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) }
|
2011-12-28 02:57:42 +00:00
|
|
|
|
2013-06-03 16:20:23 +01:00
|
|
|
can([:create, :publish], MassBuild) {|mass_build| owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)}
|
|
|
|
can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)) && !mass_build.stop_build}
|
2012-07-06 17:36:44 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
can [:read, :projects_list, :projects], Repository, platform: {owner_type: 'User', owner_id: user.id}
|
|
|
|
can [:read, :projects_list, :projects], Repository, platform: {owner_type: 'Group', owner_id: user_group_ids}
|
2013-07-17 14:20:48 +01:00
|
|
|
can([:read, :projects_list, :projects], Repository, read_relations_for('repositories')) {|repository| can? :show, repository.platform}
|
2012-10-19 15:49:01 +01:00
|
|
|
can([:read, :projects_list, :projects], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform}
|
2013-07-29 13:24:41 +01:00
|
|
|
can([:create, :edit, :update, :destroy, :projects_list, :projects, :add_project, :remove_project, :regenerate_metadata, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository) {|repository| local_admin? repository.platform}
|
2014-01-20 21:24:22 +00:00
|
|
|
can([:remove_members, :remove_member, :add_member, :signatures, :packages], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)}
|
2014-01-21 04:51:49 +00:00
|
|
|
can([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(id: user.id)}
|
2013-03-05 22:04:31 +00:00
|
|
|
can(:clear, Platform) {|platform| owner?(platform) && platform.personal?}
|
2013-08-23 19:58:29 +01:00
|
|
|
can(:regenerate_metadata, Platform) {|platform| owner?(platform) || local_admin?(platform)}
|
2013-06-26 10:00:51 +01:00
|
|
|
can([:settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform}
|
2011-12-28 02:57:42 +00:00
|
|
|
|
2012-07-13 12:18:12 +01:00
|
|
|
can([:create, :destroy], KeyPair) {|key_pair| owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)}
|
|
|
|
|
2013-06-25 14:56:39 +01:00
|
|
|
can([:read, :create, :withdraw], Token) {|token| local_admin?(token.subject)}
|
2013-06-25 08:00:20 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
can :read, Product, platform: {owner_type: 'User', owner_id: user.id, platform_type: 'main'}
|
|
|
|
can :read, Product, platform: {owner_type: 'Group', owner_id: user_group_ids, platform_type: 'main'}
|
2012-07-10 08:06:08 +01:00
|
|
|
can(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.main?}
|
|
|
|
can([:create, :update, :destroy, :clone], Product) {|product| local_admin? product.platform and product.platform.main?}
|
2012-03-15 00:07:53 +00:00
|
|
|
|
2013-03-22 16:04:29 +00:00
|
|
|
can([:create, :cancel, :update], ProductBuildList) {|pbl| can?(:update, pbl.product)}
|
2012-02-27 20:00:33 +00:00
|
|
|
can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)}
|
2012-03-15 00:07:53 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
can :read, Issue, project: {owner_type: 'User', owner_id: user.id}
|
|
|
|
can :read, Issue, project: {owner_type: 'Group', owner_id: user_group_ids}
|
2012-09-26 18:09:29 +01:00
|
|
|
can(:read, Issue, read_relations_for('issues', 'projects')) {|issue| can? :read, issue.project rescue nil}
|
2012-08-20 18:54:55 +01:00
|
|
|
can(:create, Issue) {|issue| can? :read, issue.project}
|
2012-10-02 17:46:51 +01:00
|
|
|
can(:update, Issue) {|issue| issue.user_id == user.id or local_admin?(issue.project)}
|
2014-01-21 04:51:49 +00:00
|
|
|
cannot :manage, Issue, project: {has_issues: false} # switch off issues
|
2012-09-26 18:09:29 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
can [:read, :commits, :files], PullRequest, to_project: {owner_type: 'User', owner_id: user.id}
|
|
|
|
can [:read, :commits, :files], PullRequest, to_project: {owner_type: 'Group', owner_id: user_group_ids}
|
2013-06-21 14:45:28 +01:00
|
|
|
can([:read, :commits, :files], PullRequest, read_relations_for('pull_requests', 'to_projects')) {|pull| can? :read, pull.to_project}
|
2012-09-26 18:09:29 +01:00
|
|
|
can :create, PullRequest
|
2013-06-18 21:00:01 +01:00
|
|
|
can(:update, PullRequest) {|pull| pull.user_id == user.id or local_admin?(pull.to_project)}
|
|
|
|
can(:merge, PullRequest) {|pull| local_admin?(pull.to_project)}
|
2011-12-28 02:57:42 +00:00
|
|
|
|
2012-10-04 19:40:12 +01:00
|
|
|
can([:create, :new_line], Comment) {|comment| can? :read, comment.project}
|
2012-10-05 07:13:14 +01:00
|
|
|
can([:update, :destroy], Comment) {|comment| comment.user == user or comment.project.owner == user or local_admin?(comment.project)}
|
2012-09-26 10:24:46 +01:00
|
|
|
cannot :manage, Comment do |c|
|
|
|
|
c.commentable_type == 'Issue' && !c.project.has_issues && !c.commentable.pull_request # when switch off issues
|
|
|
|
end
|
2011-11-15 20:05:08 +00:00
|
|
|
end
|
2011-12-21 14:48:16 +00:00
|
|
|
|
2012-03-01 17:33:46 +00:00
|
|
|
# Shared cannot rights for all users (registered, admin)
|
2014-01-21 04:51:49 +00:00
|
|
|
cannot [:regenerate_metadata, :destroy], Platform, platform_type: 'personal'
|
|
|
|
cannot [:create, :destroy], Repository, platform: {platform_type: 'personal'}, name: 'main'
|
|
|
|
cannot [:packages], Repository, platform: {platform_type: 'personal'}
|
|
|
|
cannot [:remove_members, :remove_member, :add_member, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository, platform: {platform_type: 'personal'}
|
2013-07-26 15:41:39 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
cannot :clear, Platform, platform_type: 'main'
|
2012-03-01 17:33:46 +00:00
|
|
|
cannot :destroy, Issue
|
2011-12-29 11:16:54 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
cannot [:members, :add_member, :remove_member, :remove_members], Platform, platform_type: 'personal'
|
2012-03-20 18:41:14 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
cannot [:create, :update, :destroy, :clone], Product, platform: {platform_type: 'personal'}
|
|
|
|
cannot [:clone], Platform, platform_type: 'personal'
|
2012-07-06 17:36:44 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
cannot [:publish, :publish_into_testing], BuildList, new_core: false
|
|
|
|
cannot :create_container, BuildList, new_core: false
|
2013-02-26 17:18:24 +00:00
|
|
|
cannot(:publish, BuildList) {|build_list| !build_list.can_publish? }
|
2013-11-05 18:41:46 +00:00
|
|
|
cannot(:publish_into_testing, BuildList) {|build_list| !build_list.can_publish_into_testing? }
|
2014-01-21 04:51:49 +00:00
|
|
|
cannot :publish_into_testing, BuildList, save_to_platform: {platform_type: 'personal'}
|
2013-02-05 13:08:40 +00:00
|
|
|
|
2013-06-03 16:20:23 +01:00
|
|
|
cannot(:cancel, MassBuild) {|mass_build| mass_build.stop_build}
|
2013-02-11 15:12:58 +00:00
|
|
|
|
2013-01-16 15:16:42 +00:00
|
|
|
if @user.system?
|
2012-12-20 19:46:16 +00:00
|
|
|
can :key_pair, Repository
|
|
|
|
else
|
|
|
|
cannot :key_pair, Repository
|
|
|
|
end
|
|
|
|
|
2012-03-01 17:33:46 +00:00
|
|
|
can :create, Subscribe do |subscribe|
|
2014-01-21 04:51:49 +00:00
|
|
|
!subscribe.subscribeable.subscribes.exists?(user_id: user.id)
|
2012-03-01 17:33:46 +00:00
|
|
|
end
|
|
|
|
can :destroy, Subscribe do |subscribe|
|
2014-01-21 04:51:49 +00:00
|
|
|
subscribe.subscribeable.subscribes.exists?(user_id: user.id) && user.id == subscribe.user_id
|
2012-03-01 17:33:46 +00:00
|
|
|
end
|
2011-12-29 11:16:54 +00:00
|
|
|
end
|
2011-11-15 20:05:08 +00:00
|
|
|
end
|
2011-11-17 19:34:02 +00:00
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
def read_relations_for(table, parent = nil)
|
|
|
|
key = parent ? "#{parent.singularize}_id" : 'id'
|
|
|
|
parent ||= table
|
2013-07-16 18:23:38 +01:00
|
|
|
|
2014-04-02 18:16:51 +01:00
|
|
|
["#{table}.#{key} = ANY (
|
|
|
|
ARRAY (
|
|
|
|
SELECT target_id
|
|
|
|
FROM relations
|
|
|
|
WHERE relations.target_type = ? AND
|
2013-07-18 17:30:49 +01:00
|
|
|
(relations.actor_type = 'User' AND relations.actor_id = ? OR
|
2014-04-02 18:16:51 +01:00
|
|
|
relations.actor_type = 'Group' AND relations.actor_id IN (?))
|
|
|
|
)
|
|
|
|
)", parent.classify, @user, user_group_ids
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2014-04-10 21:09:02 +01:00
|
|
|
def read_relations_with_projects(table = 'projects')
|
|
|
|
key = table == 'projects' ? 'id' : 'project_id'
|
2014-04-10 17:59:15 +01:00
|
|
|
["#{table}.#{key} = ANY (
|
2014-04-02 18:16:51 +01:00
|
|
|
ARRAY (
|
|
|
|
SELECT target_id
|
|
|
|
FROM relations
|
|
|
|
INNER JOIN projects ON projects.id = relations.target_id
|
|
|
|
WHERE relations.target_type = 'Project' AND
|
|
|
|
(
|
|
|
|
projects.owner_type = 'User' AND projects.owner_id != :user OR
|
|
|
|
projects.owner_type = 'Group' AND projects.owner_id NOT IN (:groups)
|
|
|
|
) AND (
|
|
|
|
relations.actor_type = 'User' AND relations.actor_id = :user OR
|
|
|
|
relations.actor_type = 'Group' AND relations.actor_id IN (:groups)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)", { user: @user, groups: user_group_ids }
|
|
|
|
]
|
2011-11-17 19:34:02 +00:00
|
|
|
end
|
|
|
|
|
2012-04-26 02:38:33 +01:00
|
|
|
def local_reader?(target)
|
2012-06-21 10:49:39 +01:00
|
|
|
%w{reader writer admin}.include? @user.best_role(target)
|
2011-12-21 14:48:16 +00:00
|
|
|
end
|
|
|
|
|
2012-04-26 02:38:33 +01:00
|
|
|
def local_writer?(target)
|
2012-06-21 10:49:39 +01:00
|
|
|
%w{writer admin}.include? @user.best_role(target)
|
2011-12-28 02:57:42 +00:00
|
|
|
end
|
2011-12-15 21:58:20 +00:00
|
|
|
|
2012-04-26 02:38:33 +01:00
|
|
|
def local_admin?(target)
|
2012-06-21 10:49:39 +01:00
|
|
|
@user.best_role(target) == 'admin'
|
2011-12-15 21:58:20 +00:00
|
|
|
end
|
|
|
|
|
2012-04-26 02:38:33 +01:00
|
|
|
def owner?(target)
|
2014-01-14 18:42:35 +00:00
|
|
|
target.owner == @user or user_own_groups.include?(target.owner)
|
2011-12-28 02:57:42 +00:00
|
|
|
end
|
2014-01-14 18:42:35 +00:00
|
|
|
|
|
|
|
def user_own_groups
|
|
|
|
@user_own_groups ||= @user.own_groups
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_group_ids
|
2014-01-15 11:14:42 +00:00
|
|
|
@user_group_ids ||= @user.group_ids
|
2014-01-14 18:42:35 +00:00
|
|
|
end
|
2011-12-01 14:20:24 +00:00
|
|
|
end
|