Skip to content

Commit

Permalink
fix: fusion api param validation decorators & qr code download failed…
Browse files Browse the repository at this point in the history
… & unable to operate members and teams (#217)

fix: the default value of the percent field cannot be reset
fix(room-server): fusion api param validation decorators
fix: qr code download failed
fix: the default value of the percent field cannot be reset
fix: unable to operate members and teams

Signed-off-by: wangkailang <wangkailang@vikadata.com>
Co-authored-by: wuyitao <wuyitao@vikadata.com>
Co-authored-by: Aria <jianweisummer@gmail.com>
Co-authored-by: 王开朗 <wangkailang@users.noreply.github.com>
Co-authored-by: Zoe <zhengxu@apitable.com>
Co-authored-by: liuyi <liuyi@vikadata.com>
Co-authored-by: Troy(FengJun) <fengjun@vikadata.com>
Co-authored-by: wangkailang <wangkailang@vikadata.com>
Co-authored-by: Aria <sujian@apitable.com>
Co-authored-by: vac (Brendan) <wangjintao@apitable.com>
Co-authored-by: paylm <172749114@qq.com>
Co-authored-by: plodsoft <jianwenzhang@apitable.com>
Co-authored-by: jianwenzhang <jianwenzhang@vikadata.com>
Co-authored-by: 彭安平 <penganping@apitable.com>
Co-authored-by: Pengap <penganping@vikadata.com>
Co-authored-by: Shawn Deng <dengguiheng@vikadata.com>
Co-authored-by: Sky <huangchangpeng@vikadata.com>
Co-authored-by: plodsoft <xplzjwz@gmail.com>
Co-authored-by: Boris <wangbo@vikadata.com>
Co-authored-by: Shawn Deng <dengguiheng@apitable.com>
Co-authored-by: Bron <liuzijing@vikadata.com>
Co-authored-by: xukecheng <cnxukecheng@gmail.com>
Co-authored-by: Chambers <chenbochao@vikadata.com>
Co-authored-by: Xukecheng <wsad8254695@outlook.com>
  • Loading branch information
24 people committed Jan 18, 2023
1 parent ac314ea commit 979922a
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@

package com.apitable.player.vo;

import com.apitable.shared.support.serializer.ImageSerializer;
import com.apitable.shared.support.serializer.NullBooleanSerializer;
import com.apitable.shared.support.serializer.NullStringSerializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import com.apitable.shared.support.serializer.ImageSerializer;
import com.apitable.shared.support.serializer.NullBooleanSerializer;
import com.apitable.shared.support.serializer.NullStringSerializer;

/**
* <p>
* Basic user information
Expand Down Expand Up @@ -82,8 +81,10 @@ public class PlayerBaseVo {
private Integer playerType;

@ApiModelProperty(value = "default avatar color number", example = "1")
@JsonSerialize(nullsUsing = NullStringSerializer.class)
private Integer avatarColor;

@ApiModelProperty(value = "Nick Name", example = "Zhang San")
@JsonSerialize(nullsUsing = NullStringSerializer.class)
private String nickName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ export const getLinkId = (state: IReduxState) => {
export const allowShowCommentPane = (state: IReduxState) => {
const spaceId = state.space.activeId;
const linkId = getLinkId(state);
return Boolean(spaceId && !linkId);
const embedId = state.pageParams.embedId;

return Boolean(spaceId && !linkId) || Boolean(spaceId && embedId);
};

export const getDatasheetParentId = (state: IReduxState, id?: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Button, IconButton, useThemeColors } from '@apitable/components';
import { Strings, t } from '@apitable/core';
import { useMount } from 'ahooks';
import domtoimage from 'dom-to-image';
import { Logo, Message } from 'pc/components/common';
import { Message } from 'pc/components/common';
import { getEnvVariables } from 'pc/utils/env';
import QRCode from 'qrcode';
import { FC } from 'react';
Expand Down Expand Up @@ -97,9 +97,6 @@ export const ShareQrCode: FC<IShareQrCodeProps> = ({ url, user, nodeName, onClos
}
<div className={styles.mainContainer} style={{ position:'relative', backgroundImage: `url(${MainBgPng.src})` }}>
<IconButton id="closeBtn" icon={() => <CloseIcon />} className={styles.closeBtn} onClick={onClose} />
<div className={styles.logo}>
<Logo />
</div>
<div className={styles.user}>{t(Strings.who_shares, { userName: user })}</div>
<div className={styles.nodeName}>{nodeName}</div>
<div className={styles.qrcode}>
Expand All @@ -113,7 +110,7 @@ export const ShareQrCode: FC<IShareQrCodeProps> = ({ url, user, nodeName, onClos
<div className={styles.gapBg}>
<img src={GapBgPng.src} alt="gap background" />
</div>
<div id="footer" className={styles.footer} style={{ backgroundImage: `url(${FooterBgPng})` }}>
<div id="footer" className={styles.footer} style={{ backgroundImage: `url(${FooterBgPng.src})` }}>
<div id="downloadBtn" className={styles.downloadBtn}>
<Button
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,57 +307,59 @@ export const useDynamicCells = (props: IUseDynamicCellsProps) => {
let frozenFillHandler: React.ReactNode = null;
if (!isEditing && selectRanges.length) {
const selectionRange = selectRanges[0];
const fillHandleCellIndex = Range.bindModel(selectionRange).getUIIndexRange(state);
const { min: recordMinIndex, max: recordMaxIndex } = fillHandleCellIndex?.record || {
min: null, max: null
};
const { min: fieldMinIndex, max: fieldMaxIndex } = fillHandleCellIndex?.field || {
min: null, max: null
};
if (
recordMaxIndex != null && !isNaN(recordMaxIndex) &&
fieldMaxIndex != null && !isNaN(fieldMaxIndex)
) {
const { fieldId } = visibleColumns[fieldMaxIndex];
const maxIndexField = fieldMap[fieldId];
// Computed fields do not render drag handler
if (getCellEditable(maxIndexField, _editable)) {
const x = instance.getColumnOffset(fieldMaxIndex);
const y = instance.getRowOffset(recordMaxIndex);
const isSingleCell = recordMinIndex === recordMaxIndex && fieldMinIndex === fieldMaxIndex;
const activeField = fieldMap[activeCell!.fieldId];
const realField = Selectors.findRealField(state, activeField);
const cellHeight = getCellHeight({
field: activeField,
realField,
rowHeight,
activeHeight: activeCellBound.height,
isActive: isSingleCell
});
const columnWidth = instance.getColumnWidth(fieldMaxIndex);
const { depth } = linearRows[recordMaxIndex];
const { width, offset } = getCellHorizontalPosition({
depth,
columnWidth,
columnIndex: fieldMaxIndex,
columnCount: totalColumnCount
});
if (selectionRange != null) {
const fillHandleCellIndex = Range.bindModel(selectionRange).getUIIndexRange(state);
const { min: recordMinIndex, max: recordMaxIndex } = fillHandleCellIndex?.record || {
min: null, max: null
};
const { min: fieldMinIndex, max: fieldMaxIndex } = fillHandleCellIndex?.field || {
min: null, max: null
};
if (
recordMaxIndex != null && !isNaN(recordMaxIndex) &&
fieldMaxIndex != null && !isNaN(fieldMaxIndex)
) {
const { fieldId } = visibleColumns[fieldMaxIndex];
const maxIndexField = fieldMap[fieldId];
// Computed fields do not render drag handler
if (getCellEditable(maxIndexField, _editable)) {
const x = instance.getColumnOffset(fieldMaxIndex);
const y = instance.getRowOffset(recordMaxIndex);
const isSingleCell = recordMinIndex === recordMaxIndex && fieldMinIndex === fieldMaxIndex;
const activeField = fieldMap[activeCell!.fieldId];
const realField = Selectors.findRealField(state, activeField);
const cellHeight = getCellHeight({
field: activeField,
realField,
rowHeight,
activeHeight: activeCellBound.height,
isActive: isSingleCell
});
const columnWidth = instance.getColumnWidth(fieldMaxIndex);
const { depth } = linearRows[recordMaxIndex];
const { width, offset } = getCellHorizontalPosition({
depth,
columnWidth,
columnIndex: fieldMaxIndex,
columnCount: totalColumnCount
});

const currentHandler = (
<Rect
name={KONVA_DATASHEET_ID.GRID_CELL_FILL_HANDLER}
x={x - GRID_FILL_HANDLER_SIZE / 2 - 0.5 + width + offset}
y={y + cellHeight - GRID_FILL_HANDLER_SIZE / 2 - 0.5}
width={GRID_FILL_HANDLER_SIZE}
height={GRID_FILL_HANDLER_SIZE}
stroke={colors.primaryColor}
strokeWidth={0.5}
/>
);
if (fieldMaxIndex < frozenColumnCount) {
frozenFillHandler = currentHandler;
} else {
fillHandler = currentHandler;
const currentHandler = (
<Rect
name={KONVA_DATASHEET_ID.GRID_CELL_FILL_HANDLER}
x={x - GRID_FILL_HANDLER_SIZE / 2 - 0.5 + width + offset}
y={y + cellHeight - GRID_FILL_HANDLER_SIZE / 2 - 0.5}
width={GRID_FILL_HANDLER_SIZE}
height={GRID_FILL_HANDLER_SIZE}
stroke={colors.primaryColor}
strokeWidth={0.5}
/>
);
if (fieldMaxIndex < frozenColumnCount) {
frozenFillHandler = currentHandler;
} else {
fillHandler = currentHandler;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/room-server/src/fusion/fusion.api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export class FusionApiController {
if (fields[0]!.id === fieldId) {
throw ApiException.tipError(ApiTipConstant.api_params_primary_field_not_allowed_to_delete, { property: 'name' });
}
await this.fusionApiService.deleteField(datasheetId, fieldId, fieldDeleteRo.conversion!);
await this.fusionApiService.deleteField(datasheetId, fieldId, fieldDeleteRo.conversion);
return ApiResponse.success({});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/room-server/src/fusion/middleware/pipe/parse.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export class ParseObjectPipe implements PipeTransform<string, Object> {
transform(value: string, metadata: ArgumentMetadata): Object {
try {
if (!isString(value)) {
return plainToClass(metadata.metatype as ClassType<any>, value, { excludeExtraneousValues: true });
return value;
}
return plainToClass<any, Object>(metadata.metatype as ClassType<any>, JSON.parse(value), { excludeExtraneousValues: true });
return plainToClass<any, Object>(metadata.metatype as ClassType<any>, JSON.parse(value));
} catch (e) {
throw new BadRequestException('Bad Request');
}
Expand Down
7 changes: 5 additions & 2 deletions packages/room-server/src/fusion/ros/asset.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
*/

import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsInt, Max, Min } from 'class-validator';
import { Type } from 'class-transformer';
import { IsInt, IsOptional, Max, Min } from 'class-validator';

export class AssetUploadQueryRo {
@ApiPropertyOptional({
Expand All @@ -30,5 +31,7 @@ export class AssetUploadQueryRo {
@IsInt()
@Min(1)
@Max(20)
count!: number;
@IsOptional()
@Type(() => Number)
count?: number;
}
2 changes: 1 addition & 1 deletion packages/room-server/src/fusion/ros/field.delete.ro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class FieldDeleteRo {

@ApiProperty({
type: String,
required: true,
required: false,
description: '',
example: ''
})
Expand Down
5 changes: 3 additions & 2 deletions packages/room-server/src/fusion/ros/field.query.ro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsString } from 'class-validator';
import { IsOptional, IsString } from 'class-validator';

export class FieldQueryRo {
@ApiPropertyOptional({
Expand All @@ -28,5 +28,6 @@ export class FieldQueryRo {
'The view Id, specifying the view, returns the fields in the same order as the view, hidden fields are not returned',
})
@IsString()
viewId!: string;
@IsOptional()
viewId?: string;
}
3 changes: 2 additions & 1 deletion packages/room-server/src/fusion/ros/record.create.ro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { ApiTipConstant, FieldKeyEnum } from '@apitable/core';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { ArrayNotEmpty, IsEnum, ValidateNested } from 'class-validator';
import { ArrayNotEmpty, IsEnum, IsOptional, ValidateNested } from 'class-validator';
import { FieldCreateRo } from './record.field.create.ro';

export class RecordCreateRo {
Expand Down Expand Up @@ -59,5 +59,6 @@ export class RecordCreateRo {
default: FieldKeyEnum.NAME,
})
@IsEnum(FieldKeyEnum, { message: ApiTipConstant.api_params_invalid_field_key })
@IsOptional()
fieldKey: FieldKeyEnum = FieldKeyEnum.NAME;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class FieldUpdateRo {
'Review Date': '2019-10-30T00:00:00.000Z',
},
})
@IsDefined({ message: ApiTipConstant.api_params_instance_fields_error })
fields!: ICellValueMap;

@ApiProperty({
Expand Down
4 changes: 3 additions & 1 deletion packages/room-server/src/fusion/ros/record.query.ro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { ApiTipConstant, CellFormatEnum, FieldKeyEnum } from '@apitable/core';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsEnum, IsOptional } from 'class-validator';
import { IsEnum, IsOptional, IsString } from 'class-validator';
import { PageRo } from './page.ro';
import { stringToArray } from 'shared/helpers/fusion.helper';

Expand All @@ -42,6 +42,7 @@ export class RecordQueryRo extends PageRo {
'\nNote: You can filter the data of unwanted fields with the fields parameter',
})
@IsOptional()
@IsString()
viewId?: string;

@ApiPropertyOptional({
Expand All @@ -63,6 +64,7 @@ export class RecordQueryRo extends PageRo {
'only the ensemble of records in the specified view that satisfy this equation will be returned',
})
@IsOptional()
@IsString()
filterByFormula?: string;

@ApiPropertyOptional({
Expand Down
4 changes: 2 additions & 2 deletions packages/room-server/src/fusion/ros/sort.ro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ISortRo } from 'shared/interfaces';
export class SortRo implements ISortRo {
@ApiProperty({
type: String,
required: false,
required: true,
example: 'fldAj8ZBpzj1X',
description: 'Specify the field to sort',
})
Expand All @@ -35,7 +35,7 @@ export class SortRo implements ISortRo {

@ApiProperty({
enum: OrderEnum,
required: false,
required: true,
example: 'fldAj8ZBpzj1X',
description: 'Specify the order type(asc/desc)',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class FusionApiService {
return this.commandService.setPageParam({ datasheetId: dst.datasheet.id }, store);
}

public async deleteField(datasheetId: string, fieldId: string, conversion: Conversion) {
public async deleteField(datasheetId: string, fieldId: string, conversion?: Conversion) {
const auth = { token: this.request.headers.authorization };
const command: ICollaCommandOptions = {
cmd: CollaCommandName.DeleteField,
Expand Down
3 changes: 1 addition & 2 deletions packages/room-server/src/shared/helpers/snowflake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const SEQUENCE_NUM_BITS = 5n;
const MACHINE_ID_MASK = (1n << (DATA_CENTER_ID_NUM_BITS + WORKER_ID_NUM_BITS)) - 1n;
const SEQUENCE_MASK = (1n << SEQUENCE_NUM_BITS) - 1n;
export const TIMESTAMP_LEFT_SHIFT = MACHINE_ID_NUM_BITS + SEQUENCE_NUM_BITS;
const MACHINE_ID_LEFT_SHIFT = (1n << SEQUENCE_NUM_BITS) - 1n;

// Starting time (2018-02-01), you can set the time when you start using the system, and you can use it for 69 years
const START_EPOCH = 1548988646430n;
Expand All @@ -75,7 +74,7 @@ class SnowFlake {
*/
constructor() {
const machineId = this.getMachineId();
this.machineBits = machineId << MACHINE_ID_LEFT_SHIFT;
this.machineBits = machineId << SEQUENCE_NUM_BITS;
this.sequence = 0n;

console.log(`Initialized snowflake: machine ID: 0x${machineId.toString(16).padStart(3, '0')}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface INamedUser {
avatar: string;
nikeName: string;
isSocialNameModified: number;
avatarColor: number;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class RestService {
return response!.data.currentBundleCapacity - response!.data.usedCapacity < 0;
}

async getUploadPresignedUrl(headers: IAuthHeader, nodeId: string, count: number): Promise<AssetVo[]> {
async getUploadPresignedUrl(headers: IAuthHeader, nodeId: string, count: number | undefined): Promise<AssetVo[]> {
const response = await lastValueFrom(
this.httpService.get(this.GET_UPLOAD_PRESIGNED_URL, {
headers: HttpHelper.createAuthHeaders(headers),
Expand Down
14 changes: 14 additions & 0 deletions packages/room-server/src/unit/dtos/unit.base.info.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ export class UnitBaseInfoDto implements IUserValue {
})
name!: string;

@ApiProperty({
type: String,
example: 0,
description: 'user nickName',
})
nickName!: string;

@ApiProperty({
type: Number,
example: '1: read, 2: blue, 3: yellow',
description: 'default avatar color number',
})
avatarColor!: number;

/**
* @deprecated
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/room-server/src/unit/services/unit.member.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class UnitMemberService {
name: cur.memberName,
type: MemberType.Member,
avatar: user?.avatar,
nickName: user?.nickName,
avatarColor: user?.color,
isActive: cur.isActive,
isDeleted: cur.isDeleted,
isNickNameModified: user?.isSocialNameModified !== 0,
Expand Down
Loading

0 comments on commit 979922a

Please sign in to comment.