Esempio n. 1
0
		def f(*args, **kwargs):	
			if json:
				jsonret = {}
			try:
				c = course.getCourseByID(kwargs['coursesid'])
			except KeyError:
				if json:
					jsonret['status'] = 'error'
					jsonret['message'] = 'Course not found'
					return jsonify(**jsonret)	
				flash('warning|The requested course was not found.')	
				return redirect(url_for('routes_user.dashboard'))	
			if c:
				role = c.getRole(g.current_user.usersid)
				if g.current_user.is_admin:
					role = 'own'
				if role is None or role not in roles:
					if json:
						jsonret['status'] = 'error'
						jsonret['message'] = 'You do not have permission to make this change'
						return jsonify(**jsonret)
					flash('warning|You do not have permission to access that course.  You have role "{0}", but require "{1}".'.format((role,'" or "'.join(roles))))
					return redirect(url_for('routes_user.dashboard'))	
			else:
				if json:
					jsonret['status'] = 'error'
					jsonret['message'] = 'Course not found'
					return jsonify(**jsonret)
				flash('warning|The requested course was not found.')	
				return redirect(url_for('routes_user.dashboard'))	
			g.current_course = c
			return method(*args, **kwargs)
Esempio n. 2
0
u4.save() # Yes, twice: should run an update the second time.
assert hashlib.md5(('1234' + bckconfig.password_salt).encode('utf-8')).hexdigest() == u1.password
assert user.getUserByID(u1.usersid).teachername == 'Mr. First1'

# Create some courses
c1 = course.Course(name='Math 1')
c2 = course.Course(name='Math 2')
c3 = course.Course(name='Math 3')
c4 = course.Course(name='Math 4')
c1.save()
c2.save()
c3.save()
c4.save()
c4.save() # Yes, twice; should run an update the second time.
assert c1.coursesid
assert course.getCourseByID(c1.coursesid).name == 'Math 1'

# Tie users to courses:
c1.addOrUpdateRole(u1.usersid, 'own')
c1.addOrUpdateRole(u2.usersid, 'view')
c1.addOrUpdateRole(u3.usersid, 'edit')
c2.addOrUpdateRole(u1.usersid, 'own')
c2.addOrUpdateRole(u3.usersid, 'edit')
c3.addOrUpdateRole(u1.usersid, 'own')
c3.addOrUpdateRole(u1.usersid, 'edit')
c3.addOrUpdateRole(u1.usersid, 'own')
c4.addOrUpdateRole(u2.usersid, 'own')
assert c4.getRole(u2.usersid) == 'own'

# Add in some exams
e1 = exam.Exam(name='Exam 1', coursesid=c1.coursesid, layout='DDDD', show_coursename=True, show_directions=True, show_points=False, show_teachername=True)