Skip to content

Commit

Permalink
Merge pull request #5364 from artsy/revert-5359-jonallured/chore-reve…
Browse files Browse the repository at this point in the history
…rt-role-change

Revert "Revert "Merge pull request #5356 from artsy/joeyAghion/userRoles""
  • Loading branch information
joeyAghion committed Oct 19, 2023
2 parents 56577a2 + 50cc8b9 commit c2105ef
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 9 deletions.
21 changes: 15 additions & 6 deletions _schemaV2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11153,6 +11153,11 @@ type LinkAuthenticationMutationPayload {

union ListPrice = Money | PriceRange

enum LiveAuctionRole {
OPERATOR
PARTICIPANT
}

type Location {
address: String
address2: String
Expand Down Expand Up @@ -16249,11 +16254,6 @@ type ReverseImageSearchResults {
results: [ReverseImageSearchResult]!
}

enum Role {
OPERATOR
PARTICIPANT
}

# The conditions for uploading assets to media.artsy.net
type S3PolicyConditionsType {
# The assigned access control
Expand Down Expand Up @@ -17821,7 +17821,7 @@ type System {

# Creates, and authorizes, a JWT custom for Causality
causalityJWT(
role: Role
role: LiveAuctionRole

# The id of the auction to participate in
saleID: String!
Expand All @@ -17833,6 +17833,9 @@ type System {

# Gravity system time, necessary for synchronizing device clocks.
time: SystemTime

# List of all available product privileges
userRoles: [UserRole]
}

type SystemTime {
Expand Down Expand Up @@ -19498,6 +19501,12 @@ type UserPurchasesEdge {
source: String
}

# Fields corresponding to a given product privilege
type UserRole {
# unique label for this role
name: String
}

type UserSaleProfile {
# The first line of address for this user.
addressLine1: String
Expand Down
1 change: 1 addition & 0 deletions src/lib/loaders/loaders_with_authentication/gravity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ export default (accessToken, userID, opts) => {
{},
{ method: "POST" }
),
userRolesLoader: gravityLoader("system/roles"),
saleArtworksAllLoader: gravityLoader(
"sale_artworks",
{},
Expand Down
36 changes: 36 additions & 0 deletions src/schema/v2/system/__tests__/userRoles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { runAuthenticatedQuery } from "schema/v2/test/utils"
import gql from "lib/gql"

const ROLES_FIXTURE = [
{
name: "content_manager",
},
{
name: "sales_observer",
},
]

describe("userRoles", () => {
it("returns a list of roles", async () => {
const userRolesLoader = jest
.fn()
.mockReturnValue(Promise.resolve(ROLES_FIXTURE))

const query = gql`
{
system {
userRoles {
name
}
}
}
`
const {
system: { userRoles },
} = await runAuthenticatedQuery(query, {
userRolesLoader,
})

expect(userRoles[0].name).toEqual("content_manager")
})
})
6 changes: 3 additions & 3 deletions src/schema/v2/system/causality_jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CausalityJWT: GraphQLFieldConfig<void, ResolverContext> = {
args: {
role: {
type: new GraphQLEnumType({
name: "Role",
name: "LiveAuctionRole",
values: {
PARTICIPANT: { value: "PARTICIPANT" },
OPERATOR: { value: "OPERATOR" },
Expand All @@ -53,7 +53,7 @@ const CausalityJWT: GraphQLFieldConfig<void, ResolverContext> = {
}
// Observer role for logged out users
if (!meLoader || !meBiddersLoader || !mePartnersLoader) {
return saleLoader(options.sale_id).then(sale =>
return saleLoader(options.sale_id).then((sale) =>
causalityJwt({
role: "observer",
userId: null,
Expand Down Expand Up @@ -99,7 +99,7 @@ const CausalityJWT: GraphQLFieldConfig<void, ResolverContext> = {

if (sale.partner) {
return mePartnersLoader({ "partner_ids[]": sale.partner._id }).then(
mePartners => {
(mePartners) => {
// Check if current user has access to partner running the sale
if (mePartners.length === 0) {
throw new Error("Unauthorized to be operator")
Expand Down
2 changes: 2 additions & 0 deletions src/schema/v2/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SystemTime from "./time"
import Services from "./services"
import { ResolverContext } from "types/graphql"
import { Algolia } from "../algolia"
import { UserRoles } from "./userRoles"

const SystemType = new GraphQLObjectType<any, ResolverContext>({
name: "System",
Expand All @@ -31,6 +32,7 @@ const SystemType = new GraphQLObjectType<any, ResolverContext>({
}),
resolve: () => ({}),
},
userRoles: UserRoles,
},
})

Expand Down
32 changes: 32 additions & 0 deletions src/schema/v2/system/userRoles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
GraphQLList,
GraphQLFieldConfig,
GraphQLObjectType,
GraphQLString,
} from "graphql"
import { ResolverContext } from "types/graphql"

const UserRoleType = new GraphQLObjectType<any, ResolverContext>({
name: "UserRole",
description: "Fields corresponding to a given product privilege",
fields: {
name: {
type: GraphQLString,
description: "unique label for this role",
},
},
})

export const UserRoles: GraphQLFieldConfig<void, ResolverContext> = {
type: new GraphQLList(UserRoleType),
description: "List of all available product privileges",
resolve: async (_root, _args, { userRolesLoader }) => {
if (!userRolesLoader) {
throw new Error(
"You need to pass a X-Access-Token header to perform this action"
)
}

return userRolesLoader()
},
}

0 comments on commit c2105ef

Please sign in to comment.