Course role code

Community Contributor

Does anyone have any code they can share to create a course role with the following permissions.

  • can view content
  • can view gradebook
  • cannot edit grade
  • can view quizzes questions, but cannot view exam questions (midterm and final exams)

Basically, the user cannot grade, but can view the grades and comments from a teacher, and they can view quiz questions, but they cannot view exam questions.

The Javascript I have isn't quite working the way I need it to, and it's not possible to do this when I enable or disable some of the permissions.  Here's the code (i removed the link to our server and noted it):


var url = window.location.pathname;

url = url.split("/");

if((url[1]=="courses")&&(url[3]=="quizzes")){//check if on a quiz page

    //alert("we are on a quiz page");

    var courseID = url[2];

    var quizID = url[4];

    var quizReadOnlyPage = url[5];




    //find out if quiz has access code

    $.getJSON("/api/v1/courses/" + courseID + "/quizzes/" + quizID, function(dataQuiz){



            alert("This quiz has an access code");


            //var quizAccessCode = true;



            //get self ID

            $.getJSON("/api/v1/users/self", function(dataID){

                selfID =;

                alert("My id is: " + selfID);

                alert("here we have a link to our server" + courseID + "/enrollments?include[]=role&user_id="+selfID);

            });//end json get self ID   




                //course and id are hard coded; change to variable once it is owrking.

            $.getJSON("ourtestinstance/api/v1/courses/870/enrollments?include[]=role&user_id=" + selfID, function(enrollData) {


                            alert("Enroll Data: " + enrollData.role);

                            alert("getting users....");

                            var blockExams = false;

                            //loop through enrollments, find if "self" is in here.

                            $.each(data,function(i, value){


                            });//end for each enrollment

                                /*alert("checking role...");


                                    //alert(selfID + " " + value.role + ". You are a br teacher or coord");


                                    blockExams = true;

                                    alert("i am blocking you..." + blockExams);

                                    $("").hide();//block exams


                                    if(quizReadOnlyPage == "read_only"){

                                        alert("you cannot be here!");



                                        alert("you are fine to view the page.");

                                    }//end if quiz read_only page

                                }else{//if not a BR Corrd and Teacher

                                    alert("You are allowed to view this page.");


                                }//end if self is enrolled AND  a BR teach or coord



                        }); //end get jSON enrollments

          }else{//if this is not an exam -- does not have an access code


            //alert("this is not an exam");

        }//end if has access code

    });//end json get access code information


}//end IF on a quiz page


            /***********END BLOCK EXAM*************/

Any help is greatly appreciated!