Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.
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
16 changes: 8 additions & 8 deletions client/browser/src/integration/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe('GitHub', () => {
})

testContext.overrideGraphQL({
ViewerConfiguration: () => ({
viewerConfiguration: {
ViewerSettings: () => ({
viewerSettings: {
subjects: [],
merged: { contents: '', messages: [] },
},
Expand Down Expand Up @@ -158,8 +158,8 @@ describe('GitHub', () => {
// extensions: extensionSettings,
// }
// testContext.overrideGraphQL({
// ViewerConfiguration: () => ({
// viewerConfiguration: {
// ViewerSettings: () => ({
// viewerSettings: {
// subjects: [
// {
// __typename: 'User',
Expand Down Expand Up @@ -321,8 +321,8 @@ describe('GitHub', () => {
extensions: extensionSettings,
}
testContext.overrideGraphQL({
ViewerConfiguration: () => ({
viewerConfiguration: {
ViewerSettings: () => ({
viewerSettings: {
subjects: [
{
__typename: 'User',
Expand Down Expand Up @@ -643,8 +643,8 @@ describe('GitHub', () => {
extensions: extensionSettings,
}
testContext.overrideGraphQL({
ViewerConfiguration: () => ({
viewerConfiguration: {
ViewerSettings: () => ({
viewerSettings: {
subjects: [
{
__typename: 'User',
Expand Down
8 changes: 4 additions & 4 deletions client/browser/src/integration/gitlab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ describe('GitLab', () => {
})

testContext.overrideGraphQL({
ViewerConfiguration: () => ({
viewerConfiguration: {
ViewerSettings: () => ({
viewerSettings: {
subjects: [],
merged: { contents: '', messages: [] },
},
Expand Down Expand Up @@ -152,8 +152,8 @@ describe('GitLab', () => {
extensions: extensionSettings,
}
testContext.overrideGraphQL({
ViewerConfiguration: () => ({
viewerConfiguration: {
ViewerSettings: () => ({
viewerSettings: {
subjects: [
{
__typename: 'User',
Expand Down
34 changes: 16 additions & 18 deletions client/browser/src/shared/platform/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@sourcegraph/shared/src/settings/settings'

import { observeStorageKey, storage } from '../../browser-extension/web-extension-api/storage'
import type { ViewerConfigurationResult } from '../../graphql-operations'
import type { ViewerSettingsResult } from '../../graphql-operations'
import { isInPage } from '../context'

const inPageClientSettingsKey = 'sourcegraphClientSettings'
Expand All @@ -35,7 +35,8 @@ function observeLocalStorageKey(key: string, defaultValue: string): Observable<s
}

const createStorageSettingsCascade: () => Observable<SettingsCascade> = () => {
/** Observable of the JSONC string of the settings.
/**
* Observable of the JSONC string of the settings.
*
* NOTE: We can't use LocalStorageSubject here because the JSONC string is stored raw in localStorage and LocalStorageSubject also does parsing.
* This could be changed, but users already have settings stored, so it would need a migration for little benefit.
Expand Down Expand Up @@ -95,9 +96,8 @@ export function mergeCascades(
}
}

// This is a fragment on the DEPRECATED GraphQL API type ConfigurationCascade (not SettingsCascade) for backcompat.
const configurationCascadeFragment = gql`
fragment ConfigurationCascadeFields on ConfigurationCascade {
const settingsCascadeFragment = gql`
fragment SettingsCascadeFields on SettingsCascade {
subjects {
__typename
...OrgSettingFields
Expand Down Expand Up @@ -167,42 +167,40 @@ const configurationCascadeFragment = gql`

/**
* Fetches the settings cascade for the viewer.
*
* TODO(sqs): This uses the DEPRECATED GraphQL Query.viewerConfiguration and ConfigurationCascade for backcompat.
*/
export function fetchViewerSettings(requestGraphQL: PlatformContext['requestGraphQL']): Observable<{
final: string
subjects: SettingsSubject[]
}> {
return from(
requestGraphQL<ViewerConfigurationResult>({
requestGraphQL<ViewerSettingsResult>({
request: gql`
query ViewerConfiguration {
viewerConfiguration {
...ConfigurationCascadeFields
query ViewerSettings {
viewerSettings {
...SettingsCascadeFields
}
}
${configurationCascadeFragment}
${settingsCascadeFragment}
`,
variables: {},
mightContainPrivateInfo: false,
})
).pipe(
map(dataOrThrowErrors),
map(({ viewerConfiguration }) => {
if (!viewerConfiguration) {
throw new Error('fetchViewerSettings: empty viewerConfiguration')
map(({ viewerSettings }) => {
if (!viewerSettings) {
throw new Error('fetchViewerSettings: empty viewerSettings')
}

for (const subject of viewerConfiguration.subjects) {
for (const subject of viewerSettings.subjects) {
// User/org/global settings cannot be edited from the
// browser extension (only client settings can).
subject.viewerCanAdminister = false
}

return {
subjects: viewerConfiguration.subjects,
final: viewerConfiguration.merged.contents,
subjects: viewerSettings.subjects,
final: viewerSettings.merged.contents,
}
})
)
Expand Down