Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions test/datasets-live.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 29 additions & 1 deletion test/userInfo.gql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
}
}
Loading