mirror of https://github.com/halo-dev/halo
Add support for configuring my preferences (#7495)
* Add support for configuring my preferences * Update api client Signed-off-by: Ryan Wang <i@ryanc.cc> * Update api client Signed-off-by: Ryan Wang <i@ryanc.cc> --------- Signed-off-by: Ryan Wang <i@ryanc.cc> Co-authored-by: Ryan Wang <i@ryanc.cc>pull/7501/head
parent
ebbe6a91e9
commit
fb62c1acff
|
@ -14743,6 +14743,71 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"/apis/uc.api.halo.run/v1alpha1/user-preferences/{group}": {
|
||||
"get": {
|
||||
"description": "Get my preference by group.",
|
||||
"operationId": "getMyPreference",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Group of user preference, e.g. `notification`.",
|
||||
"in": "path",
|
||||
"name": "group",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"content": {
|
||||
"*/*": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/JsonNode"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "default response"
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"UserPreferenceV1alpha1Uc"
|
||||
]
|
||||
},
|
||||
"put": {
|
||||
"description": "Create or update my preference by group.",
|
||||
"operationId": "updateMyPreference",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Group of user preference, e.g. `notification`.",
|
||||
"in": "path",
|
||||
"name": "group",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"*/*": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/JsonNode"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No content, preference updated successfully."
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"UserPreferenceV1alpha1Uc"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/apis/uc.api.security.halo.run/v1alpha1/authentications/two-factor/settings": {
|
||||
"get": {
|
||||
"description": "Get Two-factor authentication settings.",
|
||||
|
@ -17895,6 +17960,9 @@
|
|||
},
|
||||
"description": "The subject name of reason type to be interested in"
|
||||
},
|
||||
"JsonNode": {
|
||||
"type": "object"
|
||||
},
|
||||
"JsonPatch": {
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
|
|
|
@ -826,6 +826,71 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"/apis/uc.api.halo.run/v1alpha1/user-preferences/{group}": {
|
||||
"get": {
|
||||
"description": "Get my preference by group.",
|
||||
"operationId": "getMyPreference",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Group of user preference, e.g. `notification`.",
|
||||
"in": "path",
|
||||
"name": "group",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"default": {
|
||||
"content": {
|
||||
"*/*": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/JsonNode"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "default response"
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"UserPreferenceV1alpha1Uc"
|
||||
]
|
||||
},
|
||||
"put": {
|
||||
"description": "Create or update my preference by group.",
|
||||
"operationId": "updateMyPreference",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Group of user preference, e.g. `notification`.",
|
||||
"in": "path",
|
||||
"name": "group",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"*/*": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/JsonNode"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No content, preference updated successfully."
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"UserPreferenceV1alpha1Uc"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/apis/uc.api.security.halo.run/v1alpha1/authentications/two-factor/settings": {
|
||||
"get": {
|
||||
"description": "Get Two-factor authentication settings.",
|
||||
|
@ -1817,6 +1882,9 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"JsonNode": {
|
||||
"type": "object"
|
||||
},
|
||||
"JsonPatch": {
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
package run.halo.app.core.endpoint.uc;
|
||||
|
||||
import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder;
|
||||
import static org.springdoc.core.fn.builders.parameter.Builder.parameterBuilder;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.NullNode;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import org.springdoc.core.fn.builders.requestbody.Builder;
|
||||
import org.springdoc.webflux.core.fn.SpringdocRouteBuilder;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.authentication.AuthenticationTrustResolver;
|
||||
import org.springframework.security.authentication.AuthenticationTrustResolverImpl;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
import reactor.core.publisher.Mono;
|
||||
import run.halo.app.core.extension.endpoint.CustomEndpoint;
|
||||
import run.halo.app.extension.ConfigMap;
|
||||
import run.halo.app.extension.GroupVersion;
|
||||
import run.halo.app.extension.Metadata;
|
||||
import run.halo.app.extension.ReactiveExtensionClient;
|
||||
|
||||
/**
|
||||
* User preference endpoint for UC (User Center).
|
||||
* This endpoint allows users to get and update their preferences by group.
|
||||
*
|
||||
* @author JohnNiang
|
||||
* @since 2.21.0
|
||||
*/
|
||||
@Component
|
||||
class UcUserPreferenceEndpoint implements CustomEndpoint {
|
||||
|
||||
private static final String PREFERENCE_PREFIX = "user-preferences-";
|
||||
|
||||
private final AuthenticationTrustResolver trustResolver = new AuthenticationTrustResolverImpl();
|
||||
|
||||
private final ReactiveExtensionClient client;
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
UcUserPreferenceEndpoint(ReactiveExtensionClient client, ObjectMapper mapper) {
|
||||
this.client = client;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouterFunction<ServerResponse> endpoint() {
|
||||
var tag = "UserPreferenceV1alpha1Uc";
|
||||
return SpringdocRouteBuilder.route()
|
||||
.GET(
|
||||
"/user-preferences/{group}",
|
||||
this::getMyPreference,
|
||||
builder -> builder.operationId("getMyPreference")
|
||||
.tag(tag)
|
||||
.description("Get my preference by group.")
|
||||
.parameter(parameterBuilder()
|
||||
.in(ParameterIn.PATH)
|
||||
.name("group")
|
||||
.description("Group of user preference, e.g. `notification`.")
|
||||
.implementation(String.class)
|
||||
.required(true)
|
||||
)
|
||||
.response(responseBuilder()
|
||||
.implementation(JsonNode.class)
|
||||
)
|
||||
)
|
||||
.PUT(
|
||||
"/user-preferences/{group}",
|
||||
this::updateMyPreference,
|
||||
builder -> builder.operationId("updateMyPreference")
|
||||
.tag(tag)
|
||||
.description("Create or update my preference by group.")
|
||||
.parameter(parameterBuilder()
|
||||
.in(ParameterIn.PATH)
|
||||
.name("group")
|
||||
.description("Group of user preference, e.g. `notification`.")
|
||||
.implementation(String.class)
|
||||
.required(true)
|
||||
)
|
||||
.requestBody(Builder.requestBodyBuilder()
|
||||
.required(true)
|
||||
.implementation(JsonNode.class))
|
||||
.response(responseBuilder()
|
||||
.description("No content, preference updated successfully.")
|
||||
.responseCode(String.valueOf(HttpStatus.NO_CONTENT.value()))
|
||||
)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private Mono<ServerResponse> updateMyPreference(ServerRequest serverRequest) {
|
||||
var group = serverRequest.pathVariable("group");
|
||||
return authenticated()
|
||||
.map(Authentication::getName)
|
||||
.flatMap(username -> client.fetch(ConfigMap.class, PREFERENCE_PREFIX + username)
|
||||
.switchIfEmpty(Mono.fromSupplier(() -> {
|
||||
var cm = new ConfigMap();
|
||||
cm.setMetadata(new Metadata());
|
||||
cm.getMetadata().setName(PREFERENCE_PREFIX + username);
|
||||
return cm;
|
||||
}))
|
||||
)
|
||||
.flatMap(cm -> serverRequest.bodyToMono(JsonNode.class)
|
||||
.switchIfEmpty(
|
||||
Mono.error(() -> new ServerWebInputException("Request body is required."))
|
||||
)
|
||||
.flatMap(jsonNode -> Mono.fromCallable(() -> {
|
||||
if (cm.getData() == null) {
|
||||
cm.setData(new HashMap<>());
|
||||
}
|
||||
var json = mapper.writeValueAsString(jsonNode);
|
||||
if (Objects.equals(json, cm.getData().get(group))) {
|
||||
return null;
|
||||
}
|
||||
cm.getData().put(group, json);
|
||||
return cm;
|
||||
}))
|
||||
.flatMap(extension -> {
|
||||
if (extension.getMetadata().getVersion() == null) {
|
||||
return client.create(extension);
|
||||
}
|
||||
return client.update(extension);
|
||||
})
|
||||
.defaultIfEmpty(cm)
|
||||
)
|
||||
.flatMap(cm -> ServerResponse.noContent().build());
|
||||
}
|
||||
|
||||
private Mono<ServerResponse> getMyPreference(ServerRequest serverRequest) {
|
||||
var group = serverRequest.pathVariable("group");
|
||||
return authenticated()
|
||||
.map(Authentication::getName)
|
||||
.flatMap(username -> client.fetch(ConfigMap.class, PREFERENCE_PREFIX + username))
|
||||
.mapNotNull(ConfigMap::getData)
|
||||
.mapNotNull(data -> data.get(group))
|
||||
.flatMap(json -> Mono.fromCallable(() -> mapper.readTree(json)))
|
||||
.defaultIfEmpty(NullNode.getInstance())
|
||||
.flatMap(jsonNode -> ServerResponse.ok().bodyValue(jsonNode));
|
||||
}
|
||||
|
||||
private Mono<Authentication> authenticated() {
|
||||
return ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.filter(trustResolver::isAuthenticated)
|
||||
.switchIfEmpty(Mono.error(() -> new ResponseStatusException(HttpStatus.FORBIDDEN,
|
||||
"Anonymous user is not allowed to access user preference."
|
||||
)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupVersion groupVersion() {
|
||||
return GroupVersion.parseAPIVersion("uc.api.halo.run/v1alpha1");
|
||||
}
|
||||
}
|
|
@ -32,6 +32,9 @@ rules:
|
|||
- apiGroups: [ "uc.api.auth.halo.run" ]
|
||||
resources: [ "user-connections/disconnect" ]
|
||||
verbs: [ "update" ]
|
||||
- apiGroups: [ "uc.api.halo.run" ]
|
||||
resources: [ "user-preferences" ]
|
||||
verbs: [ "get", "update" ]
|
||||
---
|
||||
apiVersion: v1alpha1
|
||||
kind: "Role"
|
||||
|
|
|
@ -0,0 +1,240 @@
|
|||
package run.halo.app.core.endpoint.uc;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.assertArg;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.security.core.authority.AuthorityUtils.createAuthorityList;
|
||||
import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockAuthentication;
|
||||
import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockUser;
|
||||
import static org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.springSecurity;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import com.fasterxml.jackson.databind.node.NullNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import java.util.HashMap;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.skyscreamer.jsonassert.JSONAssert;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
import run.halo.app.extension.ConfigMap;
|
||||
import run.halo.app.extension.Metadata;
|
||||
import run.halo.app.extension.ReactiveExtensionClient;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UcUserPreferenceEndpointTest {
|
||||
|
||||
WebTestClient webClient;
|
||||
|
||||
@InjectMocks
|
||||
UcUserPreferenceEndpoint endpoint;
|
||||
|
||||
@Mock
|
||||
ReactiveExtensionClient client;
|
||||
|
||||
@Spy
|
||||
ObjectMapper mapper = JsonMapper.builder().build();
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
webClient = WebTestClient.bindToRouterFunction(endpoint.endpoint())
|
||||
.apply(springSecurity())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGroupVersion() {
|
||||
var gv = endpoint.groupVersion();
|
||||
assertEquals("uc.api.halo.run", gv.group());
|
||||
assertEquals("v1alpha1", gv.version());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotGetPreferenceWhenUnauthenticated() {
|
||||
webClient.mutate()
|
||||
.apply(mockAuthentication(new AnonymousAuthenticationToken(
|
||||
"key", "anonymousUser", createAuthorityList("ROLE_ANONYMOUS")
|
||||
)))
|
||||
.build()
|
||||
.get()
|
||||
.uri("/user-preferences/fake")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isForbidden();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldGetNullPreferenceWhenAuthenticatedAndConfigMapAbsent() {
|
||||
when(client.fetch(ConfigMap.class, "user-preferences-faker")).thenReturn(Mono.empty());
|
||||
webClient.mutate()
|
||||
.apply(mockUser("faker"))
|
||||
.build()
|
||||
.get()
|
||||
.uri("/user-preferences/fake")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(JsonNode.class)
|
||||
.isEqualTo(NullNode.getInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldGetPreferenceWhenAuthenticatedAndConfigMapPresent() {
|
||||
var cm = new ConfigMap();
|
||||
cm.setData(new HashMap<>());
|
||||
cm.getData().put("fake", """
|
||||
{
|
||||
"key": "value"
|
||||
}\
|
||||
""");
|
||||
when(client.fetch(ConfigMap.class, "user-preferences-faker"))
|
||||
.thenReturn(Mono.just(cm));
|
||||
webClient.mutate()
|
||||
.apply(mockUser("faker"))
|
||||
.build()
|
||||
.get()
|
||||
.uri("/user-preferences/fake")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(ObjectNode.class)
|
||||
.value(node -> assertEquals("value", node.get("key").asText()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotCreatePreferenceWhenUnauthenticated() {
|
||||
webClient.mutate()
|
||||
.apply(mockAuthentication(new AnonymousAuthenticationToken(
|
||||
"key", "anonymousUser", createAuthorityList("ROLE_ANONYMOUS")
|
||||
)))
|
||||
.build()
|
||||
.put()
|
||||
.uri("/user-preferences/faker")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isForbidden();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreatePreferenceWithoutConfigMap() {
|
||||
when(client.fetch(ConfigMap.class, "user-preferences-faker")).thenReturn(Mono.empty());
|
||||
when(client.create(any(ConfigMap.class))).thenReturn(Mono.just(new ConfigMap()));
|
||||
webClient.mutate()
|
||||
.apply(mockUser("faker"))
|
||||
.build()
|
||||
.put()
|
||||
.uri("/user-preferences/fake")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue("""
|
||||
{
|
||||
"key": "value"
|
||||
}\
|
||||
""")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isNoContent();
|
||||
|
||||
verify(client).<ConfigMap>create(assertArg(cm -> JSONAssert.assertEquals(
|
||||
"""
|
||||
{"key":"value"}\
|
||||
""",
|
||||
cm.getData().get("fake"),
|
||||
true
|
||||
)));
|
||||
verify(client, never()).update(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUpdatePreferenceWhenConfigMapExists() {
|
||||
var cm = new ConfigMap();
|
||||
cm.setMetadata(new Metadata());
|
||||
cm.getMetadata().setName("user-preferences-faker");
|
||||
cm.getMetadata().setVersion(1L);
|
||||
cm.setData(new HashMap<>());
|
||||
cm.getData().put("fake1", """
|
||||
{
|
||||
"key1": "value1"
|
||||
}\
|
||||
""");
|
||||
cm.getData().put("fake2", """
|
||||
{
|
||||
"key2": "value2"
|
||||
}
|
||||
""");
|
||||
when(client.fetch(ConfigMap.class, "user-preferences-faker")).thenReturn(Mono.just(cm));
|
||||
when(client.update(any(ConfigMap.class))).thenReturn(Mono.just(cm));
|
||||
webClient.mutate()
|
||||
.apply(mockUser("faker"))
|
||||
.build()
|
||||
.put()
|
||||
.uri("/user-preferences/fake1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue("""
|
||||
{
|
||||
"newKey": "newValue"
|
||||
}\
|
||||
""")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isNoContent();
|
||||
|
||||
verify(client).<ConfigMap>update(assertArg(cmToUpdate -> {
|
||||
JSONAssert.assertEquals(
|
||||
"""
|
||||
{"newKey":"newValue"}\
|
||||
""",
|
||||
cmToUpdate.getData().get("fake1"),
|
||||
true
|
||||
);
|
||||
JSONAssert.assertEquals(
|
||||
"""
|
||||
{"key2":"value2"}\
|
||||
""",
|
||||
cmToUpdate.getData().get("fake2"),
|
||||
true
|
||||
);
|
||||
}));
|
||||
|
||||
verify(client, never()).create(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotUpdatePreferenceWhenNotChange() {
|
||||
var cm = new ConfigMap();
|
||||
cm.setMetadata(new Metadata());
|
||||
cm.getMetadata().setName("user-preferences-faker");
|
||||
cm.getMetadata().setVersion(1L);
|
||||
cm.setData(new HashMap<>());
|
||||
cm.getData().put("fake", """
|
||||
{"key":"value"}\
|
||||
""");
|
||||
when(client.fetch(ConfigMap.class, "user-preferences-faker")).thenReturn(Mono.just(cm));
|
||||
webClient.mutate()
|
||||
.apply(mockUser("faker"))
|
||||
.build()
|
||||
.put()
|
||||
.uri("/user-preferences/fake")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue("""
|
||||
{"key":"value"}\
|
||||
""")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isNoContent();
|
||||
|
||||
verify(client, never()).update(any(ConfigMap.class));
|
||||
verify(client, never()).create(any(ConfigMap.class));
|
||||
}
|
||||
}
|
|
@ -65,6 +65,7 @@ import {
|
|||
UserConnectionV1alpha1Api,
|
||||
UserV1alpha1Api,
|
||||
UserV1alpha1ConsoleApi,
|
||||
UserPreferenceV1alpha1UcApi,
|
||||
} from "../src";
|
||||
|
||||
const defaultAxiosInstance = axios.create({
|
||||
|
@ -386,6 +387,13 @@ function createUcApiClient(axiosInstance: AxiosInstance) {
|
|||
axiosInstance
|
||||
),
|
||||
},
|
||||
user: {
|
||||
preference: new UserPreferenceV1alpha1UcApi(
|
||||
undefined,
|
||||
baseURL,
|
||||
axiosInstance
|
||||
),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ api/thumbnail-v1alpha1-public-api.ts
|
|||
api/two-factor-auth-v1alpha1-uc-api.ts
|
||||
api/user-connection-v1alpha1-api.ts
|
||||
api/user-connection-v1alpha1-uc-api.ts
|
||||
api/user-preference-v1alpha1-uc-api.ts
|
||||
api/user-v1alpha1-api.ts
|
||||
api/user-v1alpha1-console-api.ts
|
||||
base.ts
|
||||
|
|
|
@ -89,6 +89,7 @@ export * from './api/thumbnail-v1alpha1-public-api';
|
|||
export * from './api/two-factor-auth-v1alpha1-uc-api';
|
||||
export * from './api/user-connection-v1alpha1-api';
|
||||
export * from './api/user-connection-v1alpha1-uc-api';
|
||||
export * from './api/user-preference-v1alpha1-uc-api';
|
||||
export * from './api/user-v1alpha1-api';
|
||||
export * from './api/user-v1alpha1-console-api';
|
||||
|
||||
|
|
|
@ -0,0 +1,248 @@
|
|||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Halo
|
||||
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||
*
|
||||
* The version of the OpenAPI document: 2.21.0-SNAPSHOT
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
import type { Configuration } from '../configuration';
|
||||
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
|
||||
import globalAxios from 'axios';
|
||||
// Some imports not used depending on template conditions
|
||||
// @ts-ignore
|
||||
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common';
|
||||
// @ts-ignore
|
||||
import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base';
|
||||
/**
|
||||
* UserPreferenceV1alpha1UcApi - axios parameter creator
|
||||
* @export
|
||||
*/
|
||||
export const UserPreferenceV1alpha1UcApiAxiosParamCreator = function (configuration?: Configuration) {
|
||||
return {
|
||||
/**
|
||||
* Get my preference by group.
|
||||
* @param {string} group Group of user preference, e.g. `notification`.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
getMyPreference: async (group: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'group' is not null or undefined
|
||||
assertParamExists('getMyPreference', 'group', group)
|
||||
const localVarPath = `/apis/uc.api.halo.run/v1alpha1/user-preferences/{group}`
|
||||
.replace(`{${"group"}}`, encodeURIComponent(String(group)));
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
// authentication basicAuth required
|
||||
// http basic authentication required
|
||||
setBasicAuthToObject(localVarRequestOptions, configuration)
|
||||
|
||||
// authentication bearerAuth required
|
||||
// http bearer authentication required
|
||||
await setBearerAuthToObject(localVarHeaderParameter, configuration)
|
||||
|
||||
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Create or update my preference by group.
|
||||
* @param {string} group Group of user preference, e.g. `notification`.
|
||||
* @param {object} body
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
updateMyPreference: async (group: string, body: object, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'group' is not null or undefined
|
||||
assertParamExists('updateMyPreference', 'group', group)
|
||||
// verify required parameter 'body' is not null or undefined
|
||||
assertParamExists('updateMyPreference', 'body', body)
|
||||
const localVarPath = `/apis/uc.api.halo.run/v1alpha1/user-preferences/{group}`
|
||||
.replace(`{${"group"}}`, encodeURIComponent(String(group)));
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
// authentication basicAuth required
|
||||
// http basic authentication required
|
||||
setBasicAuthToObject(localVarRequestOptions, configuration)
|
||||
|
||||
// authentication bearerAuth required
|
||||
// http bearer authentication required
|
||||
await setBearerAuthToObject(localVarHeaderParameter, configuration)
|
||||
|
||||
|
||||
|
||||
localVarHeaderParameter['Content-Type'] = 'application/json';
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
localVarRequestOptions.data = serializeDataIfNeeded(body, localVarRequestOptions, configuration)
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* UserPreferenceV1alpha1UcApi - functional programming interface
|
||||
* @export
|
||||
*/
|
||||
export const UserPreferenceV1alpha1UcApiFp = function(configuration?: Configuration) {
|
||||
const localVarAxiosParamCreator = UserPreferenceV1alpha1UcApiAxiosParamCreator(configuration)
|
||||
return {
|
||||
/**
|
||||
* Get my preference by group.
|
||||
* @param {string} group Group of user preference, e.g. `notification`.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async getMyPreference(group: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<object>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.getMyPreference(group, options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['UserPreferenceV1alpha1UcApi.getMyPreference']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
/**
|
||||
* Create or update my preference by group.
|
||||
* @param {string} group Group of user preference, e.g. `notification`.
|
||||
* @param {object} body
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async updateMyPreference(group: string, body: object, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.updateMyPreference(group, body, options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['UserPreferenceV1alpha1UcApi.updateMyPreference']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* UserPreferenceV1alpha1UcApi - factory interface
|
||||
* @export
|
||||
*/
|
||||
export const UserPreferenceV1alpha1UcApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
|
||||
const localVarFp = UserPreferenceV1alpha1UcApiFp(configuration)
|
||||
return {
|
||||
/**
|
||||
* Get my preference by group.
|
||||
* @param {UserPreferenceV1alpha1UcApiGetMyPreferenceRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
getMyPreference(requestParameters: UserPreferenceV1alpha1UcApiGetMyPreferenceRequest, options?: RawAxiosRequestConfig): AxiosPromise<object> {
|
||||
return localVarFp.getMyPreference(requestParameters.group, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
* Create or update my preference by group.
|
||||
* @param {UserPreferenceV1alpha1UcApiUpdateMyPreferenceRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
updateMyPreference(requestParameters: UserPreferenceV1alpha1UcApiUpdateMyPreferenceRequest, options?: RawAxiosRequestConfig): AxiosPromise<void> {
|
||||
return localVarFp.updateMyPreference(requestParameters.group, requestParameters.body, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Request parameters for getMyPreference operation in UserPreferenceV1alpha1UcApi.
|
||||
* @export
|
||||
* @interface UserPreferenceV1alpha1UcApiGetMyPreferenceRequest
|
||||
*/
|
||||
export interface UserPreferenceV1alpha1UcApiGetMyPreferenceRequest {
|
||||
/**
|
||||
* Group of user preference, e.g. `notification`.
|
||||
* @type {string}
|
||||
* @memberof UserPreferenceV1alpha1UcApiGetMyPreference
|
||||
*/
|
||||
readonly group: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Request parameters for updateMyPreference operation in UserPreferenceV1alpha1UcApi.
|
||||
* @export
|
||||
* @interface UserPreferenceV1alpha1UcApiUpdateMyPreferenceRequest
|
||||
*/
|
||||
export interface UserPreferenceV1alpha1UcApiUpdateMyPreferenceRequest {
|
||||
/**
|
||||
* Group of user preference, e.g. `notification`.
|
||||
* @type {string}
|
||||
* @memberof UserPreferenceV1alpha1UcApiUpdateMyPreference
|
||||
*/
|
||||
readonly group: string
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {object}
|
||||
* @memberof UserPreferenceV1alpha1UcApiUpdateMyPreference
|
||||
*/
|
||||
readonly body: object
|
||||
}
|
||||
|
||||
/**
|
||||
* UserPreferenceV1alpha1UcApi - object-oriented interface
|
||||
* @export
|
||||
* @class UserPreferenceV1alpha1UcApi
|
||||
* @extends {BaseAPI}
|
||||
*/
|
||||
export class UserPreferenceV1alpha1UcApi extends BaseAPI {
|
||||
/**
|
||||
* Get my preference by group.
|
||||
* @param {UserPreferenceV1alpha1UcApiGetMyPreferenceRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof UserPreferenceV1alpha1UcApi
|
||||
*/
|
||||
public getMyPreference(requestParameters: UserPreferenceV1alpha1UcApiGetMyPreferenceRequest, options?: RawAxiosRequestConfig) {
|
||||
return UserPreferenceV1alpha1UcApiFp(this.configuration).getMyPreference(requestParameters.group, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update my preference by group.
|
||||
* @param {UserPreferenceV1alpha1UcApiUpdateMyPreferenceRequest} requestParameters Request parameters.
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof UserPreferenceV1alpha1UcApi
|
||||
*/
|
||||
public updateMyPreference(requestParameters: UserPreferenceV1alpha1UcApiUpdateMyPreferenceRequest, options?: RawAxiosRequestConfig) {
|
||||
return UserPreferenceV1alpha1UcApiFp(this.configuration).updateMyPreference(requestParameters.group, requestParameters.body, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue