feat: collection level headers and authorization (#3505)

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Nivedin
2023-12-13 22:43:18 +05:30
committed by GitHub
parent f3edd001d7
commit 47e009267b
95 changed files with 3221 additions and 970 deletions

View File

@@ -0,0 +1,15 @@
mutation UpdateTeamCollection(
$collectionID: ID!
$newTitle: String
$data: String
) {
updateTeamCollection(
collectionID: $collectionID
newTitle: $newTitle
data: $data
) {
id
title
data
}
}

View File

@@ -3,6 +3,7 @@ query GetCollectionChildren($collectionID: ID!, $cursor: ID) {
children(cursor: $cursor) {
id
title
data
}
}
}

View File

@@ -1,5 +0,0 @@
query GetCollectionTitle($collectionID: ID!) {
collection(collectionID: $collectionID) {
title
}
}

View File

@@ -0,0 +1,6 @@
query GetCollectionTitleAndData($collectionID: ID!) {
collection(collectionID: $collectionID) {
title
data
}
}

View File

@@ -2,6 +2,7 @@ query GetSingleCollection($collectionID: ID!) {
collection(collectionID: $collectionID) {
id
title
data
parent {
id
}

View File

@@ -2,5 +2,6 @@ query RootCollectionsOfTeam($teamID: ID!, $cursor: ID) {
rootCollectionsOfTeam(teamID: $teamID, cursor: $cursor) {
id
title
data
}
}

View File

@@ -2,6 +2,7 @@ subscription TeamCollectionAdded($teamID: ID!) {
teamCollectionAdded(teamID: $teamID) {
id
title
data
parent {
id
}

View File

@@ -2,6 +2,7 @@ subscription TeamCollectionUpdated($teamID: ID!) {
teamCollectionUpdated(teamID: $teamID) {
id
title
data
parent {
id
}

View File

@@ -4,7 +4,6 @@ import * as TE from "fp-ts/TaskEither"
import { pipe, flow } from "fp-ts/function"
import {
HoppCollection,
HoppRESTRequest,
makeCollection,
translateToNewRequest,
} from "@hoppscotch/data"
@@ -15,7 +14,7 @@ import {
ExportAsJsonDocument,
GetCollectionChildrenIDsDocument,
GetCollectionRequestsDocument,
GetCollectionTitleDocument,
GetCollectionTitleAndDataDocument,
} from "./graphql"
export const BACKEND_PAGE_SIZE = 10
@@ -85,16 +84,19 @@ export const getCompleteCollectionTree = (
pipe(
TE.Do,
TE.bind("title", () =>
TE.bind("titleAndData", () =>
pipe(
() =>
runGQLQuery({
query: GetCollectionTitleDocument,
query: GetCollectionTitleAndDataDocument,
variables: {
collectionID: collID,
},
}),
TE.map((x) => x.collection!.title)
TE.map((result) => ({
title: result.collection!.title,
data: result.collection!.data,
}))
)
),
TE.bind("children", () =>
@@ -108,24 +110,36 @@ export const getCompleteCollectionTree = (
TE.bind("requests", () => () => getCollectionRequests(collID)),
TE.map(
({ title, children, requests }) =>
({ titleAndData, children, requests }) =>
<TeamCollection>{
id: collID,
children,
requests,
title,
title: titleAndData.title,
data: titleAndData.data,
}
)
)
export const teamCollToHoppRESTColl = (
coll: TeamCollection
): HoppCollection<HoppRESTRequest> =>
makeCollection({
): HoppCollection => {
const data =
coll.data && coll.data !== "null"
? JSON.parse(coll.data)
: {
auth: { authType: "inherit", authActive: true },
headers: [],
}
return makeCollection({
name: coll.title,
folders: coll.children?.map(teamCollToHoppRESTColl) ?? [],
requests: coll.requests?.map((x) => x.request) ?? [],
auth: data.auth ?? { authType: "inherit", authActive: true },
headers: data.headers ?? [],
})
}
/**
* Get the JSON string of all the collection of the specified team

View File

@@ -21,6 +21,9 @@ import {
UpdateCollectionOrderDocument,
UpdateCollectionOrderMutation,
UpdateCollectionOrderMutationVariables,
UpdateTeamCollectionDocument,
UpdateTeamCollectionMutation,
UpdateTeamCollectionMutationVariables,
} from "../graphql"
type CreateNewRootCollectionError = "team_coll/short_title"
@@ -122,3 +125,18 @@ export const importJSONToTeam = (collectionJSON: string, teamID: string) =>
teamID,
}
)
export const updateTeamCollection = (
collectionID: string,
data?: string,
newTitle?: string
) =>
runMutation<
UpdateTeamCollectionMutation,
UpdateTeamCollectionMutationVariables,
""
>(UpdateTeamCollectionDocument, {
collectionID,
data,
newTitle,
})