creativeprogrammingatelier / atelier

Online platform for programming tutorials
MIT License
0 stars 1 forks source link

Change permissions of a role per course #108

Open afehnker opened 4 years ago

afehnker commented 4 years ago

In a course, give them the right to see zita comments (for peer reviews)

afehnker commented 3 years ago

Copy the student to the sports day course. Change the permissions.

arthurrump commented 3 years ago

For the sports day, I made this work using this script:

#r "nuget:FSharp.Data"
open FSharp.Data

let courseId = ""
let sportsdayCourseId = ""

let token = ""

let atelierUrl = "https://linux571.ewi.utwente.nl/api/"

type CourseUsers = JsonProvider<"""[{"userID":"A","courseID":"A","userName":"A","email":"A","permission":{"globalRole":"A","courseRole":"A","permissions":64898873567}}]""">

let users = 
    Http.RequestString(atelierUrl + "user/course/" + courseId, headers = [ "Authorization", token ])
    |> CourseUsers.Parse

[ for user in users -> async {
    let! addRes = 
        Http.AsyncRequest(
            atelierUrl + "course/" + sportsdayCourseId + "/user/" + user.UserId + "/role/" + user.Permission.CourseRole, 
            httpMethod = "PUT",
            headers = [ "Authorization", token ])
    printfn "Adding %s, status: %i" user.UserName addRes.StatusCode
    if user.Permission.CourseRole = "student" then
        let! permRes = 
            Http.AsyncRequest(
                atelierUrl + "permission/course/" + sportsdayCourseId + "/user/" + user.UserId,
                httpMethod = "PUT",
                headers = [ "Authorization", token; "Content-Type", "application/json" ],
                body = TextRequest (sprintf """{ "permissions": { "viewRestrictedComments": true } }""")
            )
        printfn "Set permission for %s, status: %i" user.UserName permRes.StatusCode
} ]
|> Async.Parallel
|> Async.RunSynchronously

In general, we would want to have the option to change the permissions of any role in a course, for all the users with that role.