app/models/contract.rb
# Return a hash describing privileges of the specified user
# on this contract
Return a hash describing privileges of the specified user
on this contract
Return a hash describing privileges of the specified user on this contract
def privileges(user)
		return Contract.privileges(user) if @new_record
		p = TinyPrivileges.new
		return p if user.nil?
		return p.grant_all if user.admin?
		return p.grant_all if facilitator == user
		user_role = role_of(user)
		if user_role.nil?
			case user.privilege
			when User::PRIVILEGE_STAFF
				p[:view] = 
				p[:browse] = 
				p[:create_note] = 
				p[:view_students] = 
				p[:view_note] = true
				p[:edit] = unsupervised
			when User::PRIVILEGE_STUDENT
				if unsupervised and (user.id == creator.id)
					p[:browse] = 
					p[:view] = 
					p[:edit] = 
					p[:create_note] = 
					p[:view_note] = true
				else
					p[:browse] = (category.public)
				end
			end
			return p
		end
		return p.grant_all if user_role >= Enrollment::ROLE_INSTRUCTOR || (unsupervised && user.id == self.creator_id)
		p[:view] = 
		p[:browse] = 
		p[:create_note] = 
		p[:view_note] = true
		p[:view_students] =  
		p[:edit_note] =  (user_role >= Enrollment::ROLE_INSTRUCTOR)
		return p
	end
def privileges ( user ) return Contract . privileges ( user ) if @new_record p = TinyPrivileges . new return p if user . nil? return p . grant_all if user . admin? return p . grant_all if facilitator == user user_role = role_of ( user ) if user_role . nil? case user . privilege when User :: PRIVILEGE_STAFF p [ :view ] = p [ :browse ] = p [ :create_note ] = p [ :view_students ] = p [ :view_note ] = true p [ :edit ] = unsupervised when User :: PRIVILEGE_STUDENT if unsupervised and ( user . id == creator . id ) p [ :browse ] = p [ :view ] = p [ :edit ] = p [ :create_note ] = p [ :view_note ] = true else p [ :browse ] = ( category . public ) end end return p end return p . grant_all if user_role >= Enrollment :: ROLE_INSTRUCTOR || ( unsupervised && user . id == self . creator_id ) p [ :view ] = p [ :browse ] = p [ :create_note ] = p [ :view_note ] = true p [ :view_students ] = p [ :edit_note ] = ( user_role >= Enrollment :: ROLE_INSTRUCTOR ) return p end
Return a hash describing privileges of the specified user
on this contract
Return a hash describing privileges of the specified user on this contract
# if this is being called on an unsaved record, call back # to the class privileges. # create a new privileges object with no rights # user must be specified otherwise no privileges # an admin or facilitator has full privileges ########################################## # see if the user has an enrollment role here ########################################## # USER IS NOT ENROLLED # if no role, then check for staff privileges # staff members can view and do notes # any staff member can edit an unsupervised contract # if the user is the creator of the contract and no facilitator has # been assigned, he gets various privileges # browse is the weakest privilege --- you can view minimal contract # details if the contract is public ########################################## # USER IS ENROLLED # FOR EDIT PRIVILEGES, # user must be the facilitator, or the creator of an unassigned # contract # FOR VIEW/BROWSE/NOTE PRIVILEGES, # user must be enrolled. we have already ascertained that. # an instructor or supervisor can edit a note / view student info
user
<not_specific>