Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 0.3 refactor share module #1875

Merged
merged 22 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f45eab4
feature: common share factor
RichardShan Apr 22, 2020
1bef144
refactor: share widget
RichardShan Apr 23, 2020
b71f2f4
refactor: post share
RichardShan Apr 23, 2020
58c9f07
refactor: Add Aspect AOP for davinci `share` module
RichardShan Apr 26, 2020
c164083
refactor: refresh share token and data token
RichardShan Apr 26, 2020
0e9e32c
refactor: add preflight and get share permissions api
RichardShan Apr 26, 2020
d019542
refactor: share aop add download permission check
RichardShan Apr 29, 2020
dd7b096
fix: spelling mistakes
RichardShan Jul 27, 2020
4c0c117
fix: import objects
RichardShan Jul 28, 2020
36b1d28
refactor: share
RichardShan Jul 28, 2020
cad3e28
feature: common share factor
RichardShan Apr 22, 2020
0d62104
refactor: share widget
RichardShan Apr 23, 2020
f915e8a
refactor: post share
RichardShan Apr 23, 2020
220a240
refactor: Add Aspect AOP for davinci `share` module
RichardShan Apr 26, 2020
6afe245
refactor: refresh share token and data token
RichardShan Apr 26, 2020
ab8c527
refactor: add preflight and get share permissions api
RichardShan Apr 26, 2020
fe0ccd8
refactor: share aop add download permission check
RichardShan Apr 29, 2020
61d1352
fix: spelling mistakes
RichardShan Jul 27, 2020
21be397
fix: import objects
RichardShan Jul 28, 2020
eca33be
Merge branch 'dev-0.3' of github.com:RichardShan/davinci into dev-0.3
RichardShan Aug 6, 2020
f3e9081
fix: auth share get permission error
RichardShan Aug 7, 2020
e7ddfe2
fix: auth share get parse Display
RichardShan Aug 17, 2020
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
Prev Previous commit
Next Next commit
refactor: Add Aspect AOP for davinci share module
1. adapt pre-version share token
2. check token and data permission
  • Loading branch information
RichardShan committed Aug 6, 2020
commit 220a240f784f9036e84aa661ab779cc255b0cda4
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@
<scope>runtime</scope>
</dependency>

<!--oracle -->
<!--oracle -->
<!--<dependency> -->
<!--<groupId>com.oracle</groupId> -->
<!--<artifactId>ojdbc6</artifactId> -->
Expand Down
6 changes: 6 additions & 0 deletions server/src/main/java/edp/core/annotation/AuthShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package edp.core.annotation;

import edp.davinci.service.share.ShareOperation;
import edp.davinci.service.share.ShareType;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -31,4 +34,7 @@
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface AuthShare {
ShareType type();

ShareOperation operation() default ShareOperation.READ;
}
74 changes: 38 additions & 36 deletions server/src/main/java/edp/davinci/controller/DownloadController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import edp.core.utils.FileUtils;
import edp.davinci.common.controller.BaseController;
import edp.davinci.core.common.Constants;
import edp.davinci.core.common.ErrorMsg;
import edp.davinci.core.common.ResultMap;
import edp.davinci.core.enums.DownloadType;
import edp.davinci.core.enums.FileTypeEnum;
Expand All @@ -35,6 +36,8 @@
import edp.davinci.model.User;
import edp.davinci.service.DownloadService;
import edp.davinci.service.ShareDownloadService;
import edp.davinci.service.share.ShareOperation;
import edp.davinci.service.share.ShareType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
Expand Down Expand Up @@ -124,61 +127,38 @@ public ResponseEntity submitDownloadTask(@PathVariable String type,


@ApiOperation(value = "submit share download")
@PostMapping(value = "/share/submit/{type}/{uuid}/{dataToken:.*}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@AuthShare
public ResponseEntity submitShareDownloadTask(@PathVariable(name = "type") String type,
@PostMapping(value = "/share/submit/{type}/{uuid}/{token:.*}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@AuthShare(type = ShareType.DATA, operation = ShareOperation.DOWNLOAD)
public ResponseEntity submitShareDownloadTask(@PathVariable(name = "token") String token,
@RequestParam(required = false) String password,
@PathVariable(name = "uuid") String uuid,
@PathVariable(name = "dataToken") String dataToken,
@PathVariable(name = "type") String type,
@Valid @RequestBody(required = false) DownloadViewExecuteParam[] params,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request) {


if (StringUtils.isEmpty(dataToken)) {
ResultMap resultMap = new ResultMap().fail().message("Invalid share token");
if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message(ErrorMsg.ERR_INVALID_TOKEN);
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

List<DownloadViewExecuteParam> downloadViewExecuteParams = Arrays.asList(params);
boolean rst = shareDownloadService.submit(DownloadType.getDownloadType(type), uuid, dataToken, user, downloadViewExecuteParams);
boolean rst = shareDownloadService.submit(DownloadType.getDownloadType(type), uuid, token, user, downloadViewExecuteParams);

return ResponseEntity.ok(rst ? new ResultMap().success() : new ResultMap().fail());
}


@ApiOperation(value = "get share download record page")
@GetMapping(value = "/share/page/{uuid}/{token:.*}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@AuthShare
public ResponseEntity getShareDownloadRecordPage(@PathVariable(name = "uuid") String uuid,
@PathVariable(name = "token") String token,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request) {
if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message("Invalid share token");
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

List<ShareDownloadRecord> records = shareDownloadService.queryDownloadRecordPage(uuid, token, user);

if (null == user) {
return ResponseEntity.ok(new ResultMap(tokenUtils).payloads(records));
} else {
return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payloads(records));
}
}


@ApiOperation(value = "get download record file")
@GetMapping(value = "/share/record/file/{id}/{uuid}/{token:.*}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@AuthShare
public ResponseEntity getShareDownloadRecordFile(@PathVariable(name = "id") String id,
@AuthShare(type = ShareType.FILE, operation = ShareOperation.DOWNLOAD)
public ResponseEntity getShareDownloadRecordFile(@PathVariable(name = "token") String token,
@RequestParam(required = false) String password,
@PathVariable(name = "uuid") String uuid,
@PathVariable(name = "token") String token,
@PathVariable(name = "id") String id,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request,
HttpServletResponse response) {
if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message("Invalid share token");
ResultMap resultMap = new ResultMap().fail().message(ErrorMsg.ERR_INVALID_TOKEN);
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

Expand All @@ -196,6 +176,28 @@ public ResponseEntity getShareDownloadRecordFile(@PathVariable(name = "id") Stri
return null;
}

@ApiOperation(value = "get share download record page")
@GetMapping(value = "/share/page/{uuid}/{token:.*}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@AuthShare(type = ShareType.RECORD, operation = ShareOperation.DOWNLOAD)
public ResponseEntity getShareDownloadRecordPage(@PathVariable(name = "token") String token,
@RequestParam(required = false) String password,
@PathVariable(name = "uuid") String uuid,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request) {
if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message(ErrorMsg.ERR_INVALID_TOKEN);
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

List<ShareDownloadRecord> records = shareDownloadService.queryDownloadRecordPage(uuid, token, user);

if (null == user) {
return ResponseEntity.ok(new ResultMap(tokenUtils).payloads(records));
} else {
return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payloads(records));
}
}


private void encodeFileName(HttpServletRequest request, HttpServletResponse response, String filename) throws UnsupportedEncodingException {
response.setHeader("Content-Type", "application/force-download");
Expand Down
63 changes: 21 additions & 42 deletions server/src/main/java/edp/davinci/controller/ShareController.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import edp.core.model.Paginate;
import edp.davinci.common.controller.BaseController;
import edp.davinci.core.common.Constants;
import edp.davinci.core.common.ErrorMsg;
import edp.davinci.core.common.ResultMap;
import edp.davinci.dto.shareDto.ShareDashboard;
import edp.davinci.dto.shareDto.ShareDisplay;
Expand All @@ -37,6 +38,8 @@
import edp.davinci.dto.viewDto.ViewExecuteParam;
import edp.davinci.model.User;
import edp.davinci.service.ShareService;
import edp.davinci.service.share.ShareOperation;
import edp.davinci.service.share.ShareType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
Expand Down Expand Up @@ -105,13 +108,14 @@ public ResponseEntity shareLogin(@PathVariable String token,
* @return
*/
@ApiOperation(value = "get share dashboard")
@AuthShare
@AuthShare(type = ShareType.DASHBOARD, operation = ShareOperation.READ)
@GetMapping("/dashboard/{token}")
public ResponseEntity getShareDashboard(@PathVariable String token,
@RequestParam(required = false) String password,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request) {
if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message("Invalid share token");
ResultMap resultMap = new ResultMap().fail().message(ErrorMsg.ERR_INVALID_TOKEN);
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

Expand All @@ -133,13 +137,14 @@ public ResponseEntity getShareDashboard(@PathVariable String token,
* @return
*/
@ApiOperation(value = "get share display")
@AuthShare
@AuthShare(type = ShareType.DISPLAY, operation = ShareOperation.READ)
@GetMapping("/display/{token}")
public ResponseEntity getShareDisplay(@PathVariable String token,
@RequestParam(required = false) String password,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request) {
if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message("Invalid share token");
ResultMap resultMap = new ResultMap().fail().message(ErrorMsg.ERR_INVALID_TOKEN);
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

Expand All @@ -161,13 +166,14 @@ public ResponseEntity getShareDisplay(@PathVariable String token,
* @return
*/
@ApiOperation(value = "get share widget")
@AuthShare
@AuthShare(type = ShareType.WIDGET, operation = ShareOperation.READ)
@GetMapping("/widget/{token}")
public ResponseEntity getShareWidget(@PathVariable String token,
@RequestParam(required = false) String password,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request) {
if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message("Invalid share token");
ResultMap resultMap = new ResultMap().fail().message(ErrorMsg.ERR_INVALID_TOKEN);
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

Expand All @@ -190,15 +196,16 @@ public ResponseEntity getShareWidget(@PathVariable String token,
* @return
*/
@ApiOperation(value = "get share data")
@AuthShare
@AuthShare(type = ShareType.DATA, operation = ShareOperation.LOAD_DATA)
@PostMapping(value = "/data/{token}", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getShareData(@PathVariable String token,
@RequestParam(required = false) String password,
@RequestBody(required = false) ViewExecuteParam executeParam,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request) throws SQLException {

if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message("Invalid share token");
ResultMap resultMap = new ResultMap().fail().message(ErrorMsg.ERR_INVALID_TOKEN);
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

Expand All @@ -223,17 +230,18 @@ public ResponseEntity getShareData(@PathVariable String token,
* @return
*/
@ApiOperation(value = "get share data")
@AuthShare
@AuthShare(type = ShareType.DATA, operation = ShareOperation.LOAD_DATA)
@PostMapping(value = "/data/{token}/distinctvalue/{viewId}", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getDistinctValue(@PathVariable("token") String token,
@RequestParam(required = false) String password,
@PathVariable("viewId") Long viewId,
@Valid @RequestBody DistinctParam param,
@ApiIgnore BindingResult bindingResult,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request) {

if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message("Invalid share token");
ResultMap resultMap = new ResultMap().fail().message(ErrorMsg.ERR_INVALID_TOKEN);
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

Expand All @@ -248,43 +256,14 @@ public ResponseEntity getDistinctValue(@PathVariable("token") String token,
}

try {
ResultMap resultMap = shareService.getDistinctValue(token, viewId, param, user, request);
//TODO
// shareService.getDistinctValue(token, viewId, param, user, request);
ResultMap resultMap = null;
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
return ResponseEntity.status(HttpCodeEnum.SERVER_ERROR.getCode()).body(HttpCodeEnum.SERVER_ERROR.getMessage());
}
}


/**
* share页获取csv信息
*
* @param token
* @param executeParam
* @param user
* @param request
* @return
*/
@ApiOperation(value = "get share data csv")
@AuthShare
@PostMapping(value = "/csv/{token}", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity generationShareDataCsv(@PathVariable String token,
@RequestBody(required = false) ViewExecuteParam executeParam,
@ApiIgnore @CurrentUser User user,
HttpServletRequest request) {

if (StringUtils.isEmpty(token)) {
ResultMap resultMap = new ResultMap().fail().message("Invalid share token");
return ResponseEntity.status(resultMap.getCode()).body(resultMap);
}

String filePath = shareService.generationShareDataCsv(executeParam, user, token);
if (null == user) {
return ResponseEntity.ok(new ResultMap().success().payload(filePath));
} else {
return ResponseEntity.ok(new ResultMap(tokenUtils).successAndRefreshToken(request).payload(filePath));
}
}
}
4 changes: 4 additions & 0 deletions server/src/main/java/edp/davinci/dao/RelRoleUserMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface RelRoleUserMapper {
int insert(RelRoleUser relRoleUser);
Expand Down Expand Up @@ -56,6 +57,9 @@ public interface RelRoleUserMapper {
List<RelRoleUser> getByIds(List<Long> ids);


Set<RelRoleUser> selectByUserAndRoles(@Param("userId") Long userId, @Param("roleIds") Set<Long> roleIds);


@Select({
"SELECT rru.id, u.id as 'user.id', IFNULL(u.`name`, u.username) as 'user.username', u.avatar",
"FROM rel_role_user rru LEFT JOIN `user` u on u.id = rru.user_id",
Expand Down
23 changes: 4 additions & 19 deletions server/src/main/java/edp/davinci/dto/shareDto/ShareEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package edp.davinci.dto.shareDto;

import edp.core.utils.CollectionUtils;
import edp.davinci.core.common.Constants;
import edp.davinci.service.share.ShareDataPermission;
import edp.davinci.service.share.ShareMode;
import lombok.Data;
Expand Down Expand Up @@ -54,14 +53,7 @@ public class ShareEntity {
* <p>
* for mode == 3
*/
private Set<Long> viewerIds;

/**
* viewer email
* <p>
* for mode == 3
*/
private Set<String> viewerEmails;
private Set<Long> viewers;

/**
* role id
Expand All @@ -83,23 +75,16 @@ public void valid() throws IllegalArgumentException {
}
break;
case AUTH:
if (CollectionUtils.isEmpty(this.viewerEmails) && CollectionUtils.isEmpty(this.roles) && CollectionUtils.isEmpty(viewerEmails)) {
if (CollectionUtils.isEmpty(this.viewers) && CollectionUtils.isEmpty(this.roles)) {
throw new IllegalArgumentException("Invalid shared user in AUTH share mode");
}
if (!CollectionUtils.isEmpty(viewerIds)) {
viewerIds.forEach(id -> {
if (!CollectionUtils.isEmpty(viewers)) {
viewers.forEach(id -> {
if (id < 1L) {
throw new IllegalArgumentException("Invalid viewer: " + id);
}
});
}
if (!CollectionUtils.isEmpty(viewerEmails)) {
viewerEmails.forEach(email -> {
if (!Constants.PATTERN_EMAIL_FORMAT.matcher(email).find()) {
throw new IllegalArgumentException("Invalid email: " + email);
}
});
}
if (!CollectionUtils.isEmpty(roles)) {
roles.forEach(id -> {
if (id < 1L) {
Expand Down
Loading