Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
refactor: request api of user data (#882)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/kind improvement

#### What this PR does / why we need it:

重构获取用户信息的请求方式,无需再请求所有角色即可获取当前用户的角色信息,适配:halo-dev/halo#3372

相关 PR:#847

#### Which issue(s) this PR fixes:

Fixes halo-dev/halo#3342

#### Special notes for your reviewer:

测试方式:

1. Halo 需要切换到 halo-dev/halo#3372 分支。
2. Console 需要 `pnpm install && pnpm build:packages`
3. 测试用户列表、登录、检查角色信息是否显示正确。

#### Does this PR introduce a user-facing change?

```release-note
优化 Console 端用户角色标识的显示名称。
```
  • Loading branch information
ruibaby authored Feb 24, 2023
1 parent 66a626c commit 6244e8b
Show file tree
Hide file tree
Showing 14 changed files with 370 additions and 152 deletions.
3 changes: 3 additions & 0 deletions packages/api-client/src/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ models/counter-request.ts
models/counter.ts
models/custom-templates.ts
models/dashboard-stats.ts
models/detailed-user.ts
models/excerpt.ts
models/extension.ts
models/file-reverse-proxy-provider.ts
Expand All @@ -96,6 +97,8 @@ models/listed-reply-list.ts
models/listed-reply.ts
models/listed-single-page-list.ts
models/listed-single-page.ts
models/listed-user-list.ts
models/listed-user.ts
models/login-history.ts
models/menu-item-list.ts
models/menu-item-spec.ts
Expand Down
146 changes: 122 additions & 24 deletions packages/api-client/src/api/api-console-halo-run-v1alpha1-user-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr
// @ts-ignore
import { ChangePasswordRequest } from '../models'
// @ts-ignore
import { DetailedUser } from '../models'
// @ts-ignore
import { GrantRequest } from '../models'
// @ts-ignore
import { User } from '../models'
import { ListedUserList } from '../models'
// @ts-ignore
import { UserList } from '../models'
import { User } from '../models'
// @ts-ignore
import { UserPermission } from '../models'
/**
Expand Down Expand Up @@ -174,6 +176,47 @@ export const ApiConsoleHaloRunV1alpha1UserApiAxiosParamCreator = function (confi
options: localVarRequestOptions,
}
},
/**
* Get user detail by name
* @param {string} name User name
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUserDetail: async (name: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'name' is not null or undefined
assertParamExists('getUserDetail', 'name', name)
const localVarPath = `/apis/api.console.halo.run/v1alpha1/users/{name}`.replace(
`{${'name'}}`,
encodeURIComponent(String(name)),
)
// 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,
}
},
/**
* Grant permissions to user
* @param {string} name User name
Expand Down Expand Up @@ -231,9 +274,9 @@ export const ApiConsoleHaloRunV1alpha1UserApiAxiosParamCreator = function (confi
* @param {string} [keyword]
* @param {string} [role]
* @param {number} [size] Size of one page. Zero indicates no limit.
* @param {number} [page] The page number. Zero indicates no page.
* @param {Array<string>} [labelSelector] Label selector for filtering.
* @param {Array<string>} [fieldSelector] Field selector for filtering.
* @param {number} [page] The page number. Zero indicates no page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
Expand All @@ -242,9 +285,9 @@ export const ApiConsoleHaloRunV1alpha1UserApiAxiosParamCreator = function (confi
keyword?: string,
role?: string,
size?: number,
page?: number,
labelSelector?: Array<string>,
fieldSelector?: Array<string>,
page?: number,
options: AxiosRequestConfig = {},
): Promise<RequestArgs> => {
const localVarPath = `/apis/api.console.halo.run/v1alpha1/users`
Expand Down Expand Up @@ -283,10 +326,6 @@ export const ApiConsoleHaloRunV1alpha1UserApiAxiosParamCreator = function (confi
localVarQueryParameter['size'] = size
}

if (page !== undefined) {
localVarQueryParameter['page'] = page
}

if (labelSelector) {
localVarQueryParameter['labelSelector'] = labelSelector
}
Expand All @@ -295,6 +334,10 @@ export const ApiConsoleHaloRunV1alpha1UserApiAxiosParamCreator = function (confi
localVarQueryParameter['fieldSelector'] = fieldSelector
}

if (page !== undefined) {
localVarQueryParameter['page'] = page
}

setSearchParams(localVarUrlObj, localVarQueryParameter)
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers }
Expand Down Expand Up @@ -377,7 +420,7 @@ export const ApiConsoleHaloRunV1alpha1UserApiFp = function (configuration?: Conf
*/
async getCurrentUserDetail(
options?: AxiosRequestConfig,
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<User>> {
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<DetailedUser>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getCurrentUserDetail(options)
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)
},
Expand All @@ -394,6 +437,19 @@ export const ApiConsoleHaloRunV1alpha1UserApiFp = function (configuration?: Conf
const localVarAxiosArgs = await localVarAxiosParamCreator.getPermissions(name, options)
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)
},
/**
* Get user detail by name
* @param {string} name User name
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getUserDetail(
name: string,
options?: AxiosRequestConfig,
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<DetailedUser>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getUserDetail(name, options)
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)
},
/**
* Grant permissions to user
* @param {string} name User name
Expand All @@ -415,9 +471,9 @@ export const ApiConsoleHaloRunV1alpha1UserApiFp = function (configuration?: Conf
* @param {string} [keyword]
* @param {string} [role]
* @param {number} [size] Size of one page. Zero indicates no limit.
* @param {number} [page] The page number. Zero indicates no page.
* @param {Array<string>} [labelSelector] Label selector for filtering.
* @param {Array<string>} [fieldSelector] Field selector for filtering.
* @param {number} [page] The page number. Zero indicates no page.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
Expand All @@ -426,19 +482,19 @@ export const ApiConsoleHaloRunV1alpha1UserApiFp = function (configuration?: Conf
keyword?: string,
role?: string,
size?: number,
page?: number,
labelSelector?: Array<string>,
fieldSelector?: Array<string>,
page?: number,
options?: AxiosRequestConfig,
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<UserList>> {
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ListedUserList>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.listUsers(
sort,
keyword,
role,
size,
page,
labelSelector,
fieldSelector,
page,
options,
)
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)
Expand Down Expand Up @@ -489,7 +545,7 @@ export const ApiConsoleHaloRunV1alpha1UserApiFactory = function (
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getCurrentUserDetail(options?: AxiosRequestConfig): AxiosPromise<User> {
getCurrentUserDetail(options?: AxiosRequestConfig): AxiosPromise<DetailedUser> {
return localVarFp.getCurrentUserDetail(options).then((request) => request(axios, basePath))
},
/**
Expand All @@ -504,6 +560,18 @@ export const ApiConsoleHaloRunV1alpha1UserApiFactory = function (
): AxiosPromise<UserPermission> {
return localVarFp.getPermissions(requestParameters.name, options).then((request) => request(axios, basePath))
},
/**
* Get user detail by name
* @param {ApiConsoleHaloRunV1alpha1UserApiGetUserDetailRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUserDetail(
requestParameters: ApiConsoleHaloRunV1alpha1UserApiGetUserDetailRequest,
options?: AxiosRequestConfig,
): AxiosPromise<DetailedUser> {
return localVarFp.getUserDetail(requestParameters.name, options).then((request) => request(axios, basePath))
},
/**
* Grant permissions to user
* @param {ApiConsoleHaloRunV1alpha1UserApiGrantPermissionRequest} requestParameters Request parameters.
Expand All @@ -527,16 +595,16 @@ export const ApiConsoleHaloRunV1alpha1UserApiFactory = function (
listUsers(
requestParameters: ApiConsoleHaloRunV1alpha1UserApiListUsersRequest = {},
options?: AxiosRequestConfig,
): AxiosPromise<UserList> {
): AxiosPromise<ListedUserList> {
return localVarFp
.listUsers(
requestParameters.sort,
requestParameters.keyword,
requestParameters.role,
requestParameters.size,
requestParameters.page,
requestParameters.labelSelector,
requestParameters.fieldSelector,
requestParameters.page,
options,
)
.then((request) => request(axios, basePath))
Expand Down Expand Up @@ -591,6 +659,20 @@ export interface ApiConsoleHaloRunV1alpha1UserApiGetPermissionsRequest {
readonly name: string
}

/**
* Request parameters for getUserDetail operation in ApiConsoleHaloRunV1alpha1UserApi.
* @export
* @interface ApiConsoleHaloRunV1alpha1UserApiGetUserDetailRequest
*/
export interface ApiConsoleHaloRunV1alpha1UserApiGetUserDetailRequest {
/**
* User name
* @type {string}
* @memberof ApiConsoleHaloRunV1alpha1UserApiGetUserDetail
*/
readonly name: string
}

/**
* Request parameters for grantPermission operation in ApiConsoleHaloRunV1alpha1UserApi.
* @export
Expand Down Expand Up @@ -646,13 +728,6 @@ export interface ApiConsoleHaloRunV1alpha1UserApiListUsersRequest {
*/
readonly size?: number

/**
* The page number. Zero indicates no page.
* @type {number}
* @memberof ApiConsoleHaloRunV1alpha1UserApiListUsers
*/
readonly page?: number

/**
* Label selector for filtering.
* @type {Array<string>}
Expand All @@ -666,6 +741,13 @@ export interface ApiConsoleHaloRunV1alpha1UserApiListUsersRequest {
* @memberof ApiConsoleHaloRunV1alpha1UserApiListUsers
*/
readonly fieldSelector?: Array<string>

/**
* The page number. Zero indicates no page.
* @type {number}
* @memberof ApiConsoleHaloRunV1alpha1UserApiListUsers
*/
readonly page?: number
}

/**
Expand Down Expand Up @@ -733,6 +815,22 @@ export class ApiConsoleHaloRunV1alpha1UserApi extends BaseAPI {
.then((request) => request(this.axios, this.basePath))
}

/**
* Get user detail by name
* @param {ApiConsoleHaloRunV1alpha1UserApiGetUserDetailRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ApiConsoleHaloRunV1alpha1UserApi
*/
public getUserDetail(
requestParameters: ApiConsoleHaloRunV1alpha1UserApiGetUserDetailRequest,
options?: AxiosRequestConfig,
) {
return ApiConsoleHaloRunV1alpha1UserApiFp(this.configuration)
.getUserDetail(requestParameters.name, options)
.then((request) => request(this.axios, this.basePath))
}

/**
* Grant permissions to user
* @param {ApiConsoleHaloRunV1alpha1UserApiGrantPermissionRequest} requestParameters Request parameters.
Expand Down Expand Up @@ -766,9 +864,9 @@ export class ApiConsoleHaloRunV1alpha1UserApi extends BaseAPI {
requestParameters.keyword,
requestParameters.role,
requestParameters.size,
requestParameters.page,
requestParameters.labelSelector,
requestParameters.fieldSelector,
requestParameters.page,
options,
)
.then((request) => request(this.axios, this.basePath))
Expand Down
40 changes: 40 additions & 0 deletions packages/api-client/src/models/detailed-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* tslint:disable */
/* eslint-disable */
/**
* Halo Next API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 2.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

// May contain unused imports in some cases
// @ts-ignore
import { Role } from './role'
// May contain unused imports in some cases
// @ts-ignore
import { User } from './user'

/**
*
* @export
* @interface DetailedUser
*/
export interface DetailedUser {
/**
*
* @type {User}
* @memberof DetailedUser
*/
user: User
/**
*
* @type {Array<Role>}
* @memberof DetailedUser
*/
roles: Array<Role>
}
3 changes: 3 additions & 0 deletions packages/api-client/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export * from './counter-list'
export * from './counter-request'
export * from './custom-templates'
export * from './dashboard-stats'
export * from './detailed-user'
export * from './excerpt'
export * from './extension'
export * from './file-reverse-proxy-provider'
Expand All @@ -49,6 +50,8 @@ export * from './listed-reply'
export * from './listed-reply-list'
export * from './listed-single-page'
export * from './listed-single-page-list'
export * from './listed-user'
export * from './listed-user-list'
export * from './login-history'
export * from './menu'
export * from './menu-item'
Expand Down
Loading

1 comment on commit 6244e8b

@vercel
Copy link

@vercel vercel bot commented on 6244e8b Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-halo-dev.vercel.app
halo-admin-ui.vercel.app
ui-git-main-halo-dev.vercel.app

Please sign in to comment.