Skip to content

Commit

Permalink
Merge pull request #1087 from amvanbaren/namespace-details-url
Browse files Browse the repository at this point in the history
Use detailsUrl to update namespace details
  • Loading branch information
amvanbaren authored Jan 28, 2025
2 parents 3f10591 + 641f92d commit 0c073d1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions server/src/main/java/org/eclipse/openvsx/UserAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public List<NamespaceJson> getOwnNamespaces() {
if(isOwner) {
json.setMembersUrl(createApiUrl(serverUrl, "user", "namespace", namespace.getName(), "members"));
json.setRoleUrl(createApiUrl(serverUrl, "user", "namespace", namespace.getName(), "role"));
json.setDetailsUrl(createApiUrl(serverUrl, "user", "namespace", namespace.getName(), "details"));
}

return json;
Expand Down
11 changes: 11 additions & 0 deletions server/src/main/java/org/eclipse/openvsx/json/NamespaceJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public static NamespaceJson error(String message) {
@Schema(hidden = true)
private String roleUrl;

@Schema(hidden = true)
private String detailsUrl;

public String getName() {
return name;
}
Expand Down Expand Up @@ -102,4 +105,12 @@ public String getRoleUrl() {
public void setRoleUrl(String roleUrl) {
this.roleUrl = roleUrl;
}

public String getDetailsUrl() {
return detailsUrl;
}

public void setDetailsUrl(String detailsUrl) {
this.detailsUrl = detailsUrl;
}
}
7 changes: 3 additions & 4 deletions webui/src/extension-registry-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ExtensionRegistryService {
return sendRequest({ abortController, endpoint });
}

async setNamespaceDetails(abortController: AbortController, details: NamespaceDetails): Promise<Readonly<SuccessResult | ErrorResult>> {
async setNamespaceDetails(abortController: AbortController, endpoint: string, details: NamespaceDetails): Promise<Readonly<SuccessResult | ErrorResult>> {
const csrfResponse = await this.getCsrfToken(abortController);
const headers: Record<string, string> = {
'Content-Type': 'application/json;charset=UTF-8'
Expand All @@ -59,7 +59,6 @@ export class ExtensionRegistryService {
headers[csrfToken.header] = csrfToken.value;
}

const endpoint = createAbsoluteURL([this.serverUrl, 'user', 'namespace', details.name, 'details']);
return sendRequest({
abortController,
method: 'POST',
Expand All @@ -70,7 +69,7 @@ export class ExtensionRegistryService {
});
}

async setNamespaceLogo(abortController: AbortController, namespace: string, logoFile: Blob, logoName: string): Promise<Readonly<SuccessResult | ErrorResult>> {
async setNamespaceLogo(abortController: AbortController, endpoint: string, logoFile: Blob, logoName: string): Promise<Readonly<SuccessResult | ErrorResult>> {
const csrfResponse = await this.getCsrfToken(abortController);
const headers: Record<string, string> = {};
if (!isError(csrfResponse)) {
Expand All @@ -80,7 +79,7 @@ export class ExtensionRegistryService {

const form = new FormData();
form.append('file', logoFile, logoName);
const endpoint = createAbsoluteURL([this.serverUrl, 'user', 'namespace', namespace, 'details', 'logo']);
endpoint = createAbsoluteURL([endpoint, 'logo']);
return sendRequest({
abortController,
method: 'POST',
Expand Down
1 change: 1 addition & 0 deletions webui/src/extension-registry-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export interface Namespace {
verified: boolean;
membersUrl: UrlString;
roleUrl: UrlString;
detailsUrl: UrlString;
}

export interface NamespaceDetails {
Expand Down
4 changes: 2 additions & 2 deletions webui/src/pages/user/user-namespace-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ export const UserNamespaceDetails: FunctionComponent<UserNamespaceDetailsProps>
? 'https://twitter.com/' + details.socialLinks.twitter
: undefined;

const result = await context.service.setNamespaceDetails(abortController.current, details);
const result = await context.service.setNamespaceDetails(abortController.current, props.namespace.detailsUrl, details);
if (isError(result)) {
throw result;
}

if (logoPreview) {
const logoFile = await (await fetch(logoPreview)).blob();
await context.service.setNamespaceLogo(abortController.current, details.name, logoFile, details.logo as string);
await context.service.setNamespaceLogo(abortController.current, props.namespace.detailsUrl, logoFile, details.logo as string);
await getNamespaceDetails();
} else {
setCurrentDetails(copy(newDetails));
Expand Down
26 changes: 14 additions & 12 deletions webui/src/pages/user/user-settings-namespace-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,20 @@ export const NamespaceDetail: FunctionComponent<NamespaceDetailProps> = props =>
</Grid>
{
props.namespace.membersUrl
? <>
<Grid item>
<UserNamespaceMemberList
setLoadingState={props.setLoadingState}
namespace={props.namespace}
filterUsers={props.filterUsers}
fixSelf={props.fixSelf} />
</Grid>
<Grid item>
<UserNamespaceDetails namespace={props.namespace}/>
</Grid>
</>
? <Grid item>
<UserNamespaceMemberList
setLoadingState={props.setLoadingState}
namespace={props.namespace}
filterUsers={props.filterUsers}
fixSelf={props.fixSelf} />
</Grid>
: null
}
{
props.namespace.detailsUrl
? <Grid item>
<UserNamespaceDetails namespace={props.namespace}/>
</Grid>
: null
}
<Grid item>
Expand Down

0 comments on commit 0c073d1

Please sign in to comment.