def move_membership(lti=None):
    # Get the attributes
    assignment_id = request.values.get('assignment_id', None)
    old_group_id = request.values.get('old_group_id', None)
    new_group_id = request.values.get('new_group_id', None)
    if None in (assignment_id, new_group_id, old_group_id):
        return jsonify(success=False, message="Need assignment_id, old_group_id, and new_group_id.")
    
    # Ensure that the assignment exists and that the user can modify it
    assignment = Assignment.by_id(int(assignment_id))
    if not g.user.is_instructor(assignment.course_id):
        return jsonify(success=False, message="You are not an instructor in this assignment's course.")
        
    # Verify permissions
    if int(new_group_id) != -1:
        new_assignment_group = AssignmentGroup.by_id(int(new_group_id))
        if not g.user.is_instructor(new_assignment_group.course_id):
            return jsonify(success=False, message="You are not an instructor in this assignment's course.")
    if int(old_group_id) != -1:
        old_assignment_group = AssignmentGroup.by_id(int(old_group_id))
        if not g.user.is_instructor(old_assignment_group.course_id):
            return jsonify(success=False, message="You are not an instructor in this assignment's course.")
    # Perform action
    AssignmentGroupMembership.move_assignment(int(assignment_id), int(new_group_id))
    # Result
    return jsonify(success=True)
Beispiel #2
0
def move_group(lti=lti):
    assignment_id = request.values.get('assignment_id', None)
    new_group_id = request.values.get('new_group_id', None)
    if None in (assignment_id, new_group_id):
        return jsonify(success=False, message="Need assignment_id and new_group_id.")
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return jsonify(success=False, message="You are not an instructor in this course.")
    AssignmentGroupMembership.move_assignment(assignment_id, new_group_id)
    return jsonify(success=True)
Beispiel #3
0
def move_group(lti=lti):
    assignment_id = request.values.get('assignment_id', None)
    new_group_id = request.values.get('new_group_id', None)
    if None in (assignment_id, new_group_id):
        return jsonify(success=False,
                       message="Need assignment_id and new_group_id.")
    user, roles, course = ensure_canvas_arguments()
    if not User.is_lti_instructor(roles):
        return jsonify(success=False,
                       message="You are not an instructor in this course.")
    AssignmentGroupMembership.move_assignment(assignment_id, new_group_id)
    return jsonify(success=True)
Beispiel #4
0
def move_membership(lti=None):
    # Get the attributes
    assignment_id = request.values.get('assignment_id', None)
    old_group_id = request.values.get('old_group_id', None)
    new_group_id = request.values.get('new_group_id', None)
    if None in (assignment_id, new_group_id, old_group_id):
        return jsonify(
            success=False,
            message="Need assignment_id, old_group_id, and new_group_id.")

    # Ensure that the assignment exists and that the user can modify it
    assignment = Assignment.by_id(int(assignment_id))
    if not g.user.is_instructor(assignment.course_id):
        return jsonify(
            success=False,
            message="You are not an instructor in this assignment's course.")

    # Verify permissions
    if int(new_group_id) != -1:
        new_assignment_group = AssignmentGroup.by_id(int(new_group_id))
        if not g.user.is_instructor(new_assignment_group.course_id):
            return jsonify(
                success=False,
                message="You are not an instructor in this assignment's course."
            )
    if int(old_group_id) != -1:
        old_assignment_group = AssignmentGroup.by_id(int(old_group_id))
        if not g.user.is_instructor(old_assignment_group.course_id):
            return jsonify(
                success=False,
                message="You are not an instructor in this assignment's course."
            )
    # Perform action
    AssignmentGroupMembership.move_assignment(int(assignment_id),
                                              int(new_group_id))
    # Result
    return jsonify(success=True)
Beispiel #5
0
    def run(self, user_data_file, **kwargs):
        from models.models import Role, User, Course, Assignment, CourseAssignment, AssignmentGroup, AssignmentGroupMembership

        print("Adding Admin")
        admin = User(first_name='Cory',
                     last_name='Bart',
                     password=encrypt_password('password'),
                     confirmed_at=datetime.datetime.now(),
                     active=True,
                     email='*****@*****.**',
                     gender='Male')
        db.session.add(admin)
        db.session.flush()
        db.session.add(Role(name='instructor', user_id=admin.id))
        db.session.add(Role(name='admin', user_id=admin.id))

        print("Adding some students for color")
        for student in ('Dan Tilden', 'Anamary Leal', 'Ellie Cayford'):
            first, last = student.split()
            email = '{}{}@vt.edu'.format(first[0].lower(), last.lower())
            user = User(first_name=first, last_name=last, email=email)
            db.session.add(user)

        print("Adding default course")
        default_course = Course(name="Computational Thinking",
                                owner_id=admin.id,
                                service="native")
        db.session.add(default_course)
        db.session.flush()

        print("Adding public course")
        public_course = Course(name="Public Course",
                               owner_id=admin.id,
                               service="native",
                               visibility='public')
        db.session.add(public_course)
        db.session.flush()
        db.session.add(
            Role(name='instructor',
                 course_id=public_course.id,
                 user_id=admin.id))

        print("Adding local Canvas course")
        canvas_course = Course(
            name="Computational Thinking - Dev",
            owner_id=admin.id,
            service='canvas',
            visibility='private',
            external_id='cbdd860576c6c08ccb998b93009305c318bd269b')
        db.session.add(canvas_course)
        db.session.flush()

        print("Adding CS1 course")
        cs1_course = Course(name="CS 1",
                            owner_id=user.id,
                            service='canvas',
                            visibility='private')
        db.session.add(cs1_course)
        db.session.flush()

        print("Adding some assignments")
        assignment1 = Assignment(name="Assignment #1",
                                 body="a=b+c",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment1)
        assignment2 = Assignment(name="Assignment #2",
                                 body="Figure it out!",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment2)
        assignment3 = Assignment(name="Assignment #3",
                                 body="Clue",
                                 course_id=default_course.id,
                                 owner_id=admin.id)
        db.session.add(assignment3)

        ca1 = CourseAssignment(course_id=public_course.id,
                               assignment_id=assignment1.id)
        db.session.add(ca1)
        ca2 = CourseAssignment(course_id=public_course.id,
                               assignment_id=assignment2.id)
        db.session.add(ca2)

        ag1 = AssignmentGroup(name="Day 1 - Decision",
                              course_id=default_course.id)
        db.session.add(ag1)
        ag2 = AssignmentGroup(name="Day 2 - Iteration",
                              course_id=default_course.id)
        db.session.add(ag2)
        db.session.commit()

        db.session.add(
            AssignmentGroupMembership(assignment_group_id=ag1.id,
                                      assignment_id=assignment1.id))
        db.session.add(
            AssignmentGroupMembership(assignment_group_id=ag1.id,
                                      assignment_id=assignment2.id))
        db.session.add(
            AssignmentGroupMembership(assignment_group_id=ag2.id,
                                      assignment_id=assignment3.id))

        db.session.commit()
        print("Complete")