diff --git a/test/datasets-live.jl b/test/datasets-live.jl index f5b081196..dd73eca4d 100644 --- a/test/datasets-live.jl +++ b/test/datasets-live.jl @@ -1,31 +1,14 @@ import HTTP, JSON, JuliaHub -function _get_user_groups_rest(auth::JuliaHub.Authentication) - r = HTTP.get( - JuliaHub._url(auth, "user", "groups"), - JuliaHub._authheaders(auth), - ) - r.status == 200 && return String.(JSON.parse(String(r.body))) - JuliaHub._throw_invalidresponse(r) -end -function _get_user_groups_gql(auth::JuliaHub.Authentication) +function _get_user_groups(auth::JuliaHub.Authentication)::Vector{String} # Note: this query is newer than the one we use in src/userinfo.jl, and works # with newer JuliaHub versions, whereas the other one specifically works with - # older versions. + # older versions. This specific query has been tested with JuliaHub 6.8+ userinfo_gql = read(joinpath(@__DIR__, "userInfo.gql"), String) - r = JuliaHub._gql_request(auth, userinfo_gql) - r.status == 200 || error("Invalid response from GQL ($(r.status))\n$(r.body)") - user = only(r.json["data"]["users"]) - String[g["group"]["name"] for g in user["groups"]] -end -function _get_user_groups(auth::JuliaHub.Authentication)::Vector{String} - rest_exception = try - return _get_user_groups_rest(auth) - catch e - @debug "Failed to fetch user groups via REST API" exception = (e, catch_backtrace()) - e, catch_backtrace() - end try - return _get_user_groups_gql(auth) + r = JuliaHub._gql_request(auth, userinfo_gql) + r.status == 200 || error("Invalid response from GQL ($(r.status))\n$(r.body)") + user = only(r.json["data"]["users"]) + return String[g["group"]["name"] for g in user["groups"]] catch e @error "Unable to determine valid user groups" @error "> REST API failure" exception = rest_exception diff --git a/test/userInfo.gql b/test/userInfo.gql index 8b2a45580..0dfff23d8 100644 --- a/test/userInfo.gql +++ b/test/userInfo.gql @@ -1,3 +1,10 @@ +# # LIMITATIONS ON EXTERNAL USE: external users are only allowed to depend +# # on certain fields exposed in this query. No backwards compatibility +# # guarantees are made for the fields marked "DISALLOWED". +# +# external_query = true +# roles = ["default"] + query UserInfo { users(limit: 1) { id @@ -6,7 +13,19 @@ query UserInfo { emails { email } - groups: user_groups { + # DISALLOWED: .features is disallowed for external users + # No guarantees are made about the contents or validity of this field. + features: user_feature_maps { + feature { + name + id + product_id + } + } + # DISALLOWED: .get_started_viewed is disallowed for external users + # No guarantees are made about the contents or validity of this field. + get_started_viewed + groups: user_groups(where: { _not: { is_deleted: { _eq: true } } }) { id: group_id group { name @@ -22,6 +41,15 @@ query UserInfo { } } accepted_tos + # DISALLOWED: .accepted_tos_time is disallowed for external users + # No guarantees are made about the contents or validity of this field. + accepted_tos_time survey_submitted_time } + # DISALLOWED: .features is disallowed for external users + # No guarantees are made about the contents or validity of this field. + features(where: { public: { _eq: true } }) { + id + name + } }