canvas-lms/app/models/account_user.rb

187 lines
5.4 KiB
Ruby
Raw Normal View History

2011-02-01 09:57:29 +08:00
#
# Copyright (C) 2011 - present Instructure, Inc.
2011-02-01 09:57:29 +08:00
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
class AccountUser < ActiveRecord::Base
belongs_to :account
belongs_to :user
belongs_to :role
include Role::AssociationHelper
has_many :role_overrides, :as => :context, :inverse_of => :context
2011-02-01 09:57:29 +08:00
has_a_broadcast_policy
before_validation :infer_defaults
2011-02-01 09:57:29 +08:00
after_save :touch_user
after_destroy :touch_user
after_save :update_account_associations_if_changed
after_destroy :update_account_associations_later
validate :valid_role?
validates_presence_of :account_id, :user_id, :role_id
alias_method :context, :account
scope :active, -> { where.not(workflow_state: 'deleted') }
include Workflow
workflow do
state :active
state :deleted do
event :reactivate, transitions_to: :active
end
end
alias_method :destroy_permanently!, :destroy
def destroy
return if self.new_record?
self.workflow_state = 'deleted'
self.save!
end
def update_account_associations_if_changed
being_deleted = self.workflow_state == 'deleted' && self.workflow_state_before_last_save != 'deleted'
if (self.saved_change_to_account_id? || self.saved_change_to_user_id?) || being_deleted
if self.new_record?
return if %w{creation_pending deleted}.include?(self.user.workflow_state)
account_chain = self.account.account_chain
associations = {}
account_chain.each_with_index { |account, idx| associations[account.id] = idx }
self.user.update_account_associations(:incremental => true, :precalculated_associations => associations)
else
self.user.update_account_associations_later
end
end
end
def update_account_associations_later
self.user.update_account_associations_later
end
2011-02-01 09:57:29 +08:00
def infer_defaults
self.role ||= Role.get_built_in_role('AccountAdmin')
2011-02-01 09:57:29 +08:00
end
def valid_role?
return true if role.built_in?
unless role.account_role?
self.errors.add(:role_id, "is not a valid account role")
end
unless self.account.valid_role?(role)
self.errors.add(:role_id, "is not an available role for this account")
end
end
2011-02-01 09:57:29 +08:00
set_broadcast_policy do |p|
p.dispatch :new_account_user
p.to {|record| record.account.users}
p.whenever {|record| record.just_created }
refactor grading standards controller 'index' action refactor the grading standards controller and put permissions in place. closes CNVS-18223 test plan: 1. While logged in as an admin, go to the grading standards account page (/accounts/:account_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Admin" in the title of each grading standard you create). 2. Log in as a teacher in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Teacher" in the title of each grading standard you create) 3. Log in as a TA in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "TA" in the title of each grading standard you create) 4. Now that you've created all the grading standards, ensure that the following permissions are in place when logged in at different access levels: Logged in as admin: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Admin -Teacher -TA - At the ACCOUNT url (/accounts/:account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin - Can edit/delete Grading Standards created at the following levels -Admin Logged in as teacher: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as TA: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) 5. Now, create a sub-account under the account you used in steps 1-4. Create an admin for the new sub-account, and create a new Course under the sub-account. Publish the course, and create a Teacher and a TA for the new course. 6. Just as you did in steps 1-3, create grading standards using the new sub-account admin, teacher, and TA. 7. Ensure that the following permissions are in place when logged in at different access levels: Logged in as sub-account admin: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view the Grading Standards created at the following levels -Admin -Sub-Account Admin -New teacher -New TA - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin -New Teacher -New TA - At the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new teacher: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new TA: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Change-Id: I483f5b516f5786a669e7316af80ae382873cf9d1 Reviewed-on: https://gerrit.instructure.com/48109 Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-01-30 11:32:00 +08:00
2011-02-01 09:57:29 +08:00
p.dispatch :account_user_registration
p.to {|record| record.user }
p.whenever {|record| @account_user_registration }
refactor grading standards controller 'index' action refactor the grading standards controller and put permissions in place. closes CNVS-18223 test plan: 1. While logged in as an admin, go to the grading standards account page (/accounts/:account_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Admin" in the title of each grading standard you create). 2. Log in as a teacher in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Teacher" in the title of each grading standard you create) 3. Log in as a TA in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "TA" in the title of each grading standard you create) 4. Now that you've created all the grading standards, ensure that the following permissions are in place when logged in at different access levels: Logged in as admin: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Admin -Teacher -TA - At the ACCOUNT url (/accounts/:account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin - Can edit/delete Grading Standards created at the following levels -Admin Logged in as teacher: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as TA: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) 5. Now, create a sub-account under the account you used in steps 1-4. Create an admin for the new sub-account, and create a new Course under the sub-account. Publish the course, and create a Teacher and a TA for the new course. 6. Just as you did in steps 1-3, create grading standards using the new sub-account admin, teacher, and TA. 7. Ensure that the following permissions are in place when logged in at different access levels: Logged in as sub-account admin: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view the Grading Standards created at the following levels -Admin -Sub-Account Admin -New teacher -New TA - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin -New Teacher -New TA - At the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new teacher: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new TA: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Change-Id: I483f5b516f5786a669e7316af80ae382873cf9d1 Reviewed-on: https://gerrit.instructure.com/48109 Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-01-30 11:32:00 +08:00
2011-02-01 09:57:29 +08:00
p.dispatch :account_user_notification
p.to {|record| record.user }
p.whenever {|record| @account_user_notification }
end
set_policy do
given { |user| self.account.grants_right?(user, :manage_account_memberships) && is_subset_of?(user) }
can :create and can :destroy
end
2011-02-01 09:57:29 +08:00
def readable_type
AccountUser.readable_type(self.role.name)
2011-02-01 09:57:29 +08:00
end
refactor grading standards controller 'index' action refactor the grading standards controller and put permissions in place. closes CNVS-18223 test plan: 1. While logged in as an admin, go to the grading standards account page (/accounts/:account_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Admin" in the title of each grading standard you create). 2. Log in as a teacher in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Teacher" in the title of each grading standard you create) 3. Log in as a TA in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "TA" in the title of each grading standard you create) 4. Now that you've created all the grading standards, ensure that the following permissions are in place when logged in at different access levels: Logged in as admin: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Admin -Teacher -TA - At the ACCOUNT url (/accounts/:account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin - Can edit/delete Grading Standards created at the following levels -Admin Logged in as teacher: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as TA: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) 5. Now, create a sub-account under the account you used in steps 1-4. Create an admin for the new sub-account, and create a new Course under the sub-account. Publish the course, and create a Teacher and a TA for the new course. 6. Just as you did in steps 1-3, create grading standards using the new sub-account admin, teacher, and TA. 7. Ensure that the following permissions are in place when logged in at different access levels: Logged in as sub-account admin: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view the Grading Standards created at the following levels -Admin -Sub-Account Admin -New teacher -New TA - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin -New Teacher -New TA - At the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new teacher: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new TA: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Change-Id: I483f5b516f5786a669e7316af80ae382873cf9d1 Reviewed-on: https://gerrit.instructure.com/48109 Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-01-30 11:32:00 +08:00
2011-02-01 09:57:29 +08:00
def account_user_registration!
@account_user_registration = true
self.save!
@account_user_registration = false
end
refactor grading standards controller 'index' action refactor the grading standards controller and put permissions in place. closes CNVS-18223 test plan: 1. While logged in as an admin, go to the grading standards account page (/accounts/:account_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Admin" in the title of each grading standard you create). 2. Log in as a teacher in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Teacher" in the title of each grading standard you create) 3. Log in as a TA in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "TA" in the title of each grading standard you create) 4. Now that you've created all the grading standards, ensure that the following permissions are in place when logged in at different access levels: Logged in as admin: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Admin -Teacher -TA - At the ACCOUNT url (/accounts/:account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin - Can edit/delete Grading Standards created at the following levels -Admin Logged in as teacher: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as TA: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) 5. Now, create a sub-account under the account you used in steps 1-4. Create an admin for the new sub-account, and create a new Course under the sub-account. Publish the course, and create a Teacher and a TA for the new course. 6. Just as you did in steps 1-3, create grading standards using the new sub-account admin, teacher, and TA. 7. Ensure that the following permissions are in place when logged in at different access levels: Logged in as sub-account admin: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view the Grading Standards created at the following levels -Admin -Sub-Account Admin -New teacher -New TA - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin -New Teacher -New TA - At the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new teacher: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new TA: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Change-Id: I483f5b516f5786a669e7316af80ae382873cf9d1 Reviewed-on: https://gerrit.instructure.com/48109 Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-01-30 11:32:00 +08:00
2011-02-01 09:57:29 +08:00
def account_user_notification!
@account_user_notification = true
self.save!
@account_user_notification = false
end
add support for applying role overrides to just self or just descendants * wrap RoleOverride#permission_for with enabled_for? that also takes a context of where the permission is being applied, and recalculates its enabled-ness relative to that context; use that for checking account admin and enrollment permissions * refactor User#can_masquerade to properly check for descendant permissions test plan: * create a custom role in site admin. give it permission to manage permissions * in script/console, find that override and set apply_to_self=false * add a user to that role, and login as that user * the user should not be able to change permissions in site admin * the user should be able to change permissions in the default account * add another role in site admin. give it permission to manage permissions * in script/console, find the override and set apply_to_self=true, apply_to_descendants=false * add another user to that role, and login as that user * the user should be able to change permissions in site admin * the user should not be able to change permissions in the default account * the first user should not be able to masquerade as the second user and vice versa * an Account Admin should be able to masquerade as either user * create a custom role in the default account, give it permission to manage permissions, and add a user to that role * the first user should be able to masquerade as the new user; the second user should not be able to masquerade as the new user * general regression tests on permissions and masquerading Change-Id: I20a1183b7dfec419634a92cda498f245187060ef Reviewed-on: https://gerrit.instructure.com/15896 Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Tested-by: Cody Cutrer <cody@instructure.com>
2012-12-07 07:15:53 +08:00
def enabled_for?(context, action)
2011-02-01 09:57:29 +08:00
@permission_lookup ||= {}
@permission_lookup[[context.class, context.global_id, action]] ||= RoleOverride.enabled_for?(context, action, self.role, self.account)
add support for applying role overrides to just self or just descendants * wrap RoleOverride#permission_for with enabled_for? that also takes a context of where the permission is being applied, and recalculates its enabled-ness relative to that context; use that for checking account admin and enrollment permissions * refactor User#can_masquerade to properly check for descendant permissions test plan: * create a custom role in site admin. give it permission to manage permissions * in script/console, find that override and set apply_to_self=false * add a user to that role, and login as that user * the user should not be able to change permissions in site admin * the user should be able to change permissions in the default account * add another role in site admin. give it permission to manage permissions * in script/console, find the override and set apply_to_self=true, apply_to_descendants=false * add another user to that role, and login as that user * the user should be able to change permissions in site admin * the user should not be able to change permissions in the default account * the first user should not be able to masquerade as the second user and vice versa * an Account Admin should be able to masquerade as either user * create a custom role in the default account, give it permission to manage permissions, and add a user to that role * the first user should be able to masquerade as the new user; the second user should not be able to masquerade as the new user * general regression tests on permissions and masquerading Change-Id: I20a1183b7dfec419634a92cda498f245187060ef Reviewed-on: https://gerrit.instructure.com/15896 Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Tested-by: Cody Cutrer <cody@instructure.com>
2012-12-07 07:15:53 +08:00
end
def has_permission_to?(context, action)
enabled_for?(context, action).include?(:self)
end
def self.all_permissions_for(user, account)
account_users = account.account_users_for(user)
result = {}
account_users.each do |account_user|
RoleOverride.permissions.keys.each do |permission|
result[permission] ||= []
result[permission] |= account_user.enabled_for?(account, permission)
end
end
result
end
def is_subset_of?(user)
needed_permissions = RoleOverride.manageable_permissions(account).keys.inject({}) do |result, permission|
add support for applying role overrides to just self or just descendants * wrap RoleOverride#permission_for with enabled_for? that also takes a context of where the permission is being applied, and recalculates its enabled-ness relative to that context; use that for checking account admin and enrollment permissions * refactor User#can_masquerade to properly check for descendant permissions test plan: * create a custom role in site admin. give it permission to manage permissions * in script/console, find that override and set apply_to_self=false * add a user to that role, and login as that user * the user should not be able to change permissions in site admin * the user should be able to change permissions in the default account * add another role in site admin. give it permission to manage permissions * in script/console, find the override and set apply_to_self=true, apply_to_descendants=false * add another user to that role, and login as that user * the user should be able to change permissions in site admin * the user should not be able to change permissions in the default account * the first user should not be able to masquerade as the second user and vice versa * an Account Admin should be able to masquerade as either user * create a custom role in the default account, give it permission to manage permissions, and add a user to that role * the first user should be able to masquerade as the new user; the second user should not be able to masquerade as the new user * general regression tests on permissions and masquerading Change-Id: I20a1183b7dfec419634a92cda498f245187060ef Reviewed-on: https://gerrit.instructure.com/15896 Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Tested-by: Cody Cutrer <cody@instructure.com>
2012-12-07 07:15:53 +08:00
result[permission] = enabled_for?(account, permission)
result
end
target_permissions = AccountUser.all_permissions_for(user, account)
needed_permissions.all? do |(permission, needed_permission)|
next true unless needed_permission.present?
target_permission = target_permissions[permission]
next false unless target_permission.present?
(needed_permission - target_permission).empty?
end
end
2011-02-01 09:57:29 +08:00
def self.readable_type(type)
if type == 'AccountAdmin' || !type || type.empty?
t('types.account_admin', "Account Admin")
2011-02-01 09:57:29 +08:00
else
type
end
end
refactor grading standards controller 'index' action refactor the grading standards controller and put permissions in place. closes CNVS-18223 test plan: 1. While logged in as an admin, go to the grading standards account page (/accounts/:account_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Admin" in the title of each grading standard you create). 2. Log in as a teacher in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Teacher" in the title of each grading standard you create) 3. Log in as a TA in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "TA" in the title of each grading standard you create) 4. Now that you've created all the grading standards, ensure that the following permissions are in place when logged in at different access levels: Logged in as admin: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Admin -Teacher -TA - At the ACCOUNT url (/accounts/:account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin - Can edit/delete Grading Standards created at the following levels -Admin Logged in as teacher: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as TA: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) 5. Now, create a sub-account under the account you used in steps 1-4. Create an admin for the new sub-account, and create a new Course under the sub-account. Publish the course, and create a Teacher and a TA for the new course. 6. Just as you did in steps 1-3, create grading standards using the new sub-account admin, teacher, and TA. 7. Ensure that the following permissions are in place when logged in at different access levels: Logged in as sub-account admin: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view the Grading Standards created at the following levels -Admin -Sub-Account Admin -New teacher -New TA - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin -New Teacher -New TA - At the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new teacher: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new TA: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Change-Id: I483f5b516f5786a669e7316af80ae382873cf9d1 Reviewed-on: https://gerrit.instructure.com/48109 Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-01-30 11:32:00 +08:00
2011-02-01 09:57:29 +08:00
def self.any_for?(user)
!account_ids_for_user(user).empty?
end
refactor grading standards controller 'index' action refactor the grading standards controller and put permissions in place. closes CNVS-18223 test plan: 1. While logged in as an admin, go to the grading standards account page (/accounts/:account_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Admin" in the title of each grading standard you create). 2. Log in as a teacher in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Teacher" in the title of each grading standard you create) 3. Log in as a TA in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "TA" in the title of each grading standard you create) 4. Now that you've created all the grading standards, ensure that the following permissions are in place when logged in at different access levels: Logged in as admin: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Admin -Teacher -TA - At the ACCOUNT url (/accounts/:account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin - Can edit/delete Grading Standards created at the following levels -Admin Logged in as teacher: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as TA: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) 5. Now, create a sub-account under the account you used in steps 1-4. Create an admin for the new sub-account, and create a new Course under the sub-account. Publish the course, and create a Teacher and a TA for the new course. 6. Just as you did in steps 1-3, create grading standards using the new sub-account admin, teacher, and TA. 7. Ensure that the following permissions are in place when logged in at different access levels: Logged in as sub-account admin: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view the Grading Standards created at the following levels -Admin -Sub-Account Admin -New teacher -New TA - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin -New Teacher -New TA - At the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new teacher: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new TA: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Change-Id: I483f5b516f5786a669e7316af80ae382873cf9d1 Reviewed-on: https://gerrit.instructure.com/48109 Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-01-30 11:32:00 +08:00
2011-02-01 09:57:29 +08:00
def self.account_ids_for_user(user)
@account_ids_for ||= {}
@account_ids_for[user.id] ||= Rails.cache.fetch(['account_ids_for_user', user].cache_key) do
AccountUser.active.for_user(user).map(&:account_id)
2011-02-01 09:57:29 +08:00
end
end
refactor grading standards controller 'index' action refactor the grading standards controller and put permissions in place. closes CNVS-18223 test plan: 1. While logged in as an admin, go to the grading standards account page (/accounts/:account_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Admin" in the title of each grading standard you create). 2. Log in as a teacher in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Teacher" in the title of each grading standard you create) 3. Log in as a TA in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "TA" in the title of each grading standard you create) 4. Now that you've created all the grading standards, ensure that the following permissions are in place when logged in at different access levels: Logged in as admin: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Admin -Teacher -TA - At the ACCOUNT url (/accounts/:account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin - Can edit/delete Grading Standards created at the following levels -Admin Logged in as teacher: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as TA: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) 5. Now, create a sub-account under the account you used in steps 1-4. Create an admin for the new sub-account, and create a new Course under the sub-account. Publish the course, and create a Teacher and a TA for the new course. 6. Just as you did in steps 1-3, create grading standards using the new sub-account admin, teacher, and TA. 7. Ensure that the following permissions are in place when logged in at different access levels: Logged in as sub-account admin: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view the Grading Standards created at the following levels -Admin -Sub-Account Admin -New teacher -New TA - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin -New Teacher -New TA - At the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new teacher: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new TA: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Change-Id: I483f5b516f5786a669e7316af80ae382873cf9d1 Reviewed-on: https://gerrit.instructure.com/48109 Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-01-30 11:32:00 +08:00
2011-02-01 09:57:29 +08:00
def self.for_user_and_account?(user, account_id)
account_ids_for_user(user).include?(account_id)
end
refactor grading standards controller 'index' action refactor the grading standards controller and put permissions in place. closes CNVS-18223 test plan: 1. While logged in as an admin, go to the grading standards account page (/accounts/:account_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Admin" in the title of each grading standard you create). 2. Log in as a teacher in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "Teacher" in the title of each grading standard you create) 3. Log in as a TA in a course that belongs to the account used in step 1. go to the grading standards page (/courses/:course_id/grading_standards) and create a couple grading standards (it will probably make your life easier to put the word "TA" in the title of each grading standard you create) 4. Now that you've created all the grading standards, ensure that the following permissions are in place when logged in at different access levels: Logged in as admin: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Admin -Teacher -TA - At the ACCOUNT url (/accounts/:account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin - Can edit/delete Grading Standards created at the following levels -Admin Logged in as teacher: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as TA: - At the COURSE url (/courses/:course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Teacher -TA - Can edit/delete Grading Standards created at the following levels -Teacher -TA - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) 5. Now, create a sub-account under the account you used in steps 1-4. Create an admin for the new sub-account, and create a new Course under the sub-account. Publish the course, and create a Teacher and a TA for the new course. 6. Just as you did in steps 1-3, create grading standards using the new sub-account admin, teacher, and TA. 7. Ensure that the following permissions are in place when logged in at different access levels: Logged in as sub-account admin: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view the Grading Standards created at the following levels -Admin -Sub-Account Admin -New teacher -New TA - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin -New Teacher -New TA - At the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin - Can edit/delete Grading Standards created at the following levels -Sub-Account Admin - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new teacher: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Logged in as new TA: - At the NEW COURSE url (/courses/:new_course_id/grading_standards) - Can view Grading Standards created at the following levels -Admin -Sub-Account Admin -New Teacher -New TA - Can edit/delete Grading Standards created at the following levels -New Teacher -New TA - Permission should be denied at the SUB-ACCOUNT url (/accounts/:sub_account_id/grading_standards) - Permission should be denied at the ACCOUNT url (/accounts/:account_id/grading_standards) Change-Id: I483f5b516f5786a669e7316af80ae382873cf9d1 Reviewed-on: https://gerrit.instructure.com/48109 Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins Product-Review: Spencer Olson <solson@instructure.com>
2015-01-30 11:32:00 +08:00
scope :for_user, lambda { |user| where(:user_id => user) }
2011-02-01 09:57:29 +08:00
end