refactor(auth): 移除控制器方法中的权限注解

移除了多个控制器类中方法的 @PreAuthorize 注解,包括:
- PPTController
- Spider2Controller
- SpiderController
- V1ChatController
- V1DatasetController
- V1ServerController
- V1WorkflowController
- WordController

这些权限控制将通过其他方式进行实现。
This commit is contained in:
Kven 2025-05-28 19:44:20 +08:00
parent 241aeeeffb
commit 087591fc20
8 changed files with 0 additions and 38 deletions

View File

@ -24,7 +24,6 @@ public class PPTController {
* @return * @return
*/ */
@PostMapping("/run") @PostMapping("/run")
@PreAuthorize("hasAuthority('dify:ppt:run')")
@OperationLogAnnotation(content = "'dify工作流'", operationType = "运行") @OperationLogAnnotation(content = "'dify工作流'", operationType = "运行")
public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request) { public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request) {
request.setUserId(SecurityUtil.getUserInfo().id.toString()); request.setUserId(SecurityUtil.getUserInfo().id.toString());

View File

@ -26,7 +26,6 @@ public class Spider2Controller {
* @return * @return
*/ */
@PostMapping("/run") @PostMapping("/run")
@PreAuthorize("hasAuthority('dify:spider2:run')")
@OperationLogAnnotation(content = "'dify工作流'", operationType = "运行") @OperationLogAnnotation(content = "'dify工作流'", operationType = "运行")
public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request) { public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request) {
request.setUserId(SecurityUtil.getUserInfo().id.toString()); request.setUserId(SecurityUtil.getUserInfo().id.toString());

View File

@ -25,7 +25,6 @@ public class SpiderController {
private static final String API_KEY = "77c068fd-d5b6-4c33-97d8-db5511a09b26"; private static final String API_KEY = "77c068fd-d5b6-4c33-97d8-db5511a09b26";
@PostMapping("/run") @PostMapping("/run")
@PreAuthorize("hasAuthority('dify:spider:run')")
public JSONObject run(@RequestBody SpiderDto dto) throws JsonProcessingException { public JSONObject run(@RequestBody SpiderDto dto) throws JsonProcessingException {
dto.setLlm_api_key(API_KEY); dto.setLlm_api_key(API_KEY);
String body = objectMapper.writeValueAsString(dto); String body = objectMapper.writeValueAsString(dto);
@ -38,7 +37,6 @@ public class SpiderController {
} }
@PostMapping("/status") @PostMapping("/status")
@PreAuthorize("hasAuthority('dify:spider:status')")
public JSONObject status() { public JSONObject status() {
return WebClient.create(SPIDER_URL).post().uri("/crawl_status") return WebClient.create(SPIDER_URL).post().uri("/crawl_status")
.retrieve() .retrieve()
@ -47,7 +45,6 @@ public class SpiderController {
} }
@PostMapping("/logs") @PostMapping("/logs")
@PreAuthorize("hasAuthority('dify:spider:log')")
public JSONObject logs() { public JSONObject logs() {
return WebClient.create(SPIDER_URL).post().uri("/logs") return WebClient.create(SPIDER_URL).post().uri("/logs")
.retrieve() .retrieve()
@ -56,7 +53,6 @@ public class SpiderController {
} }
@PostMapping("/stop") @PostMapping("/stop")
@PreAuthorize("hasAuthority('dify:spider:stop')")
public JSONObject stop() { public JSONObject stop() {
return WebClient.create(SPIDER_URL).post().uri("/stop_crawl") return WebClient.create(SPIDER_URL).post().uri("/stop_crawl")
.retrieve() .retrieve()

View File

@ -45,7 +45,6 @@ public class V1ChatController {
* apikey 建议在数据库进行存储前端调用时传智能体 id从数据库查询 * apikey 建议在数据库进行存储前端调用时传智能体 id从数据库查询
*/ */
@PostMapping("/completions/{appId}") @PostMapping("/completions/{appId}")
@PreAuthorize("hasAnyAuthority('dify:chat:send','dify:word:send')")
@OperationLogAnnotation(content = "'dify对话'", operationType = "发送") @OperationLogAnnotation(content = "'dify对话'", operationType = "发送")
public ChatMessageSendResponse sendChatMessage( public ChatMessageSendResponse sendChatMessage(
@RequestBody ChatMessageSendRequest sendRequest, @RequestBody ChatMessageSendRequest sendRequest,
@ -81,7 +80,6 @@ public class V1ChatController {
* @return 会话列表 * @return 会话列表
*/ */
@PostMapping("/conversations/{appId}") @PostMapping("/conversations/{appId}")
@PreAuthorize("hasAnyAuthority('dify:chat:query','dify:word:query')")
public DifyPageResult<MessageConversationsResponse> conversations( public DifyPageResult<MessageConversationsResponse> conversations(
@RequestBody MessageConversationsRequest request, @RequestBody MessageConversationsRequest request,
@PathVariable String appId @PathVariable String appId
@ -98,7 +96,6 @@ public class V1ChatController {
* @return 消息列表 * @return 消息列表
*/ */
@PostMapping("/messages/{appid}") @PostMapping("/messages/{appid}")
@PreAuthorize("hasAnyAuthority('dify:chat:query','dify:word:query')")
public DifyPageResult<MessagesResponseVO> messages( public DifyPageResult<MessagesResponseVO> messages(
@RequestBody MessagesRequest request, @RequestBody MessagesRequest request,
@PathVariable String appid @PathVariable String appid
@ -115,7 +112,6 @@ public class V1ChatController {
* @param taskId 任务id * @param taskId 任务id
*/ */
@PatchMapping("/stream/stop") @PatchMapping("/stream/stop")
@PreAuthorize("hasAnyAuthority('dify:chat:stop','dify:word:stop')")
public void stopMessagesStream(@RequestParam String taskId, @RequestParam String appId) { public void stopMessagesStream(@RequestParam String taskId, @RequestParam String appId) {
String apiKey = appEntityService.getApikey(appId); String apiKey = appEntityService.getApikey(appId);
String userId = SecurityUtil.getUserInfo().id.toString(); String userId = SecurityUtil.getUserInfo().id.toString();
@ -128,7 +124,6 @@ public class V1ChatController {
* @param conversationId 会话id * @param conversationId 会话id
*/ */
@DeleteMapping("/conversation") @DeleteMapping("/conversation")
@PreAuthorize("hasAnyAuthority('dify:chat:delete','dify:word:delete')")
@OperationLogAnnotation(content = "'dify对话'", operationType = "删除") @OperationLogAnnotation(content = "'dify对话'", operationType = "删除")
public void deleteConversation(@RequestParam String conversationId, @RequestParam String appId) { public void deleteConversation(@RequestParam String conversationId, @RequestParam String appId) {
String apiKey = appEntityService.getApikey(appId); String apiKey = appEntityService.getApikey(appId);
@ -147,7 +142,6 @@ public class V1ChatController {
* @return * @return
*/ */
@GetMapping("/messages/suggested") @GetMapping("/messages/suggested")
@PreAuthorize("hasAnyAuthority('dify:chat:query','dify:word:query')")
public List<String> messagesSuggested(String messageId,String appId){ public List<String> messagesSuggested(String messageId,String appId){
String apiKey = appEntityService.getApikey(appId); String apiKey = appEntityService.getApikey(appId);
String userId = SecurityUtil.getUserInfo().id.toString(); String userId = SecurityUtil.getUserInfo().id.toString();
@ -160,7 +154,6 @@ public class V1ChatController {
* @return * @return
*/ */
@GetMapping("/parameters/{appid}") @GetMapping("/parameters/{appid}")
@PreAuthorize("hasAnyAuthority('dify:chat:query','dify:word:query')")
public AppParametersResponseVO parameters(@PathVariable String appid){ public AppParametersResponseVO parameters(@PathVariable String appid){
String apiKey = appEntityService.getApikey(appid); String apiKey = appEntityService.getApikey(appid);
return ExceptionUtil.difyException(()->difyChat.parameters(apiKey)); return ExceptionUtil.difyException(()->difyChat.parameters(apiKey));

View File

@ -28,7 +28,6 @@ public class V1DatasetController {
* @return * @return
*/ */
@PostMapping("/page") @PostMapping("/page")
@PreAuthorize("hasAuthority('dify:dataset:query')")
public DifyPageResult<DatasetResponse> page(@RequestBody DatasetPageRequest request){ public DifyPageResult<DatasetResponse> page(@RequestBody DatasetPageRequest request){
request.setApiKey(apiKey); request.setApiKey(apiKey);
return difyDataset.page(request); return difyDataset.page(request);
@ -41,7 +40,6 @@ public class V1DatasetController {
* @return * @return
*/ */
@PostMapping("/createDocumentByFile") @PostMapping("/createDocumentByFile")
@PreAuthorize("hasAuthority('dify:dataset:create')")
@OperationLogAnnotation(content = "'dify知识库文档'", operationType = "新建") @OperationLogAnnotation(content = "'dify知识库文档'", operationType = "新建")
public DocumentCreateResponse createDocumentByFile(DocumentCreateByFileRequest request){ public DocumentCreateResponse createDocumentByFile(DocumentCreateByFileRequest request){
return ExceptionUtil.difyException(() -> difyDataset.createDocumentByFile(request)); return ExceptionUtil.difyException(() -> difyDataset.createDocumentByFile(request));
@ -54,7 +52,6 @@ public class V1DatasetController {
* @return * @return
*/ */
@GetMapping("/pageDocument") @GetMapping("/pageDocument")
@PreAuthorize("hasAuthority('dify:dataset:query')")
public DifyPageResult<DocumentInfo> pageDocument(@RequestBody DatasetPageDocumentRequest request){ public DifyPageResult<DocumentInfo> pageDocument(@RequestBody DatasetPageDocumentRequest request){
request.setApiKey(apiKey); request.setApiKey(apiKey);
return difyDataset.pageDocument(request); return difyDataset.pageDocument(request);
@ -68,7 +65,6 @@ public class V1DatasetController {
* @return * @return
*/ */
@PostMapping("/uploadFileInfo") @PostMapping("/uploadFileInfo")
@PreAuthorize("hasAuthority('dify:dataset:query')")
public UploadFileInfoResponse uploadFileInfo(String datasetId, String documentId){ public UploadFileInfoResponse uploadFileInfo(String datasetId, String documentId){
return difyDataset.uploadFileInfo(datasetId, documentId,apiKey); return difyDataset.uploadFileInfo(datasetId, documentId,apiKey);
} }
@ -81,7 +77,6 @@ public class V1DatasetController {
* @return * @return
*/ */
@DeleteMapping("/deleteDocument") @DeleteMapping("/deleteDocument")
@PreAuthorize("hasAuthority('dify:dataset:delete')")
@OperationLogAnnotation(content = "'dify知识库文档'", operationType = "删除") @OperationLogAnnotation(content = "'dify知识库文档'", operationType = "删除")
public void deleteDocument(String datasetId, String documentId){ public void deleteDocument(String datasetId, String documentId){
difyDataset.deleteDocument(datasetId, documentId, apiKey); difyDataset.deleteDocument(datasetId, documentId, apiKey);
@ -94,7 +89,6 @@ public class V1DatasetController {
* @return * @return
*/ */
@PostMapping("/createSegment") @PostMapping("/createSegment")
@PreAuthorize("hasAuthority('dify:dataset:create')")
@OperationLogAnnotation(content = "'dify知识库文档分段'", operationType = "新建") @OperationLogAnnotation(content = "'dify知识库文档分段'", operationType = "新建")
public SegmentResponse createSegment(@RequestBody SegmentCreateRequest request){ public SegmentResponse createSegment(@RequestBody SegmentCreateRequest request){
return difyDataset.createSegment(request); return difyDataset.createSegment(request);
@ -107,7 +101,6 @@ public class V1DatasetController {
* @return * @return
*/ */
@PostMapping("/createSegmentChildChunk") @PostMapping("/createSegmentChildChunk")
@PreAuthorize("hasAuthority('dify:dataset:create')")
@OperationLogAnnotation(content = "'dify知识库文档子分段'", operationType = "新建") @OperationLogAnnotation(content = "'dify知识库文档子分段'", operationType = "新建")
public SegmentChildChunkCreateResponse createSegmentChildChunk(@RequestBody SegmentChildChunkCreateRequest request){ public SegmentChildChunkCreateResponse createSegmentChildChunk(@RequestBody SegmentChildChunkCreateRequest request){
return difyDataset.createSegmentChildChunk(request); return difyDataset.createSegmentChildChunk(request);
@ -120,7 +113,6 @@ public class V1DatasetController {
* @return * @return
*/ */
@GetMapping("/retrieve") @GetMapping("/retrieve")
@PreAuthorize("hasAuthority('dify:dataset:retrieve')")
public RetrieveResponse retrieve(@RequestBody RetrieveRequest request){ public RetrieveResponse retrieve(@RequestBody RetrieveRequest request){
return difyDataset.retrieve(request); return difyDataset.retrieve(request);
} }

View File

@ -31,7 +31,6 @@ public class V1ServerController {
* @return * @return
*/ */
@GetMapping("/apps") @GetMapping("/apps")
@PreAuthorize("hasAuthority('dify:server:query')")
@DataPermission @DataPermission
public List<AppsResponseVO> getApps(String mode, String name) { public List<AppsResponseVO> getApps(String mode, String name) {
return appEntityService.getApps(mode, name); return appEntityService.getApps(mode, name);
@ -43,7 +42,6 @@ public class V1ServerController {
* @return * @return
*/ */
@GetMapping("/{id}") @GetMapping("/{id}")
@PreAuthorize("hasAuthority('dify:server:query')")
public AppsResponseVO getApp(@PathVariable("id") String id) { public AppsResponseVO getApp(@PathVariable("id") String id) {
return difyServer.app(id); return difyServer.app(id);
} }
@ -54,7 +52,6 @@ public class V1ServerController {
* @return * @return
*/ */
@GetMapping("/api-key/{id}") @GetMapping("/api-key/{id}")
@PreAuthorize("hasAuthority('dify:server:query')")
public List<ApiKeyResponseVO> getAppApiKey(@PathVariable("id") String id) { public List<ApiKeyResponseVO> getAppApiKey(@PathVariable("id") String id) {
return difyServer.getAppApiKey(id); return difyServer.getAppApiKey(id);
} }
@ -65,7 +62,6 @@ public class V1ServerController {
* @return * @return
*/ */
@PostMapping("/api-key/init/{id}") @PostMapping("/api-key/init/{id}")
@PreAuthorize("hasAuthority('dify:server:init')")
public List<ApiKeyResponseVO> initAppApiKey(@PathVariable("id") String id) { public List<ApiKeyResponseVO> initAppApiKey(@PathVariable("id") String id) {
return difyServer.initAppApiKey(id); return difyServer.initAppApiKey(id);
} }
@ -75,7 +71,6 @@ public class V1ServerController {
* @return * @return
*/ */
@GetMapping("/api-key/dataset") @GetMapping("/api-key/dataset")
@PreAuthorize("hasAuthority('dify:server:query')")
public List<DatasetApiKeyResponseVO> getDatasetApiKey() { public List<DatasetApiKeyResponseVO> getDatasetApiKey() {
return difyServer.getDatasetApiKey(); return difyServer.getDatasetApiKey();
} }
@ -85,7 +80,6 @@ public class V1ServerController {
* @return * @return
*/ */
@PostMapping("/api-key/dataset/init") @PostMapping("/api-key/dataset/init")
@PreAuthorize("hasAuthority('dify:server:init')")
public List<DatasetApiKeyResponseVO> initDatasetApiKey() { public List<DatasetApiKeyResponseVO> initDatasetApiKey() {
return difyServer.initDatasetApiKey(); return difyServer.initDatasetApiKey();
} }
@ -97,7 +91,6 @@ public class V1ServerController {
* @return * @return
*/ */
@PostMapping("/app/{id}/toggle") @PostMapping("/app/{id}/toggle")
@PreAuthorize("hasAuthority('dify:server:update')")
@OperationLogAnnotation(content = "'dify服务启用状态'", operationType = "更新") @OperationLogAnnotation(content = "'dify服务启用状态'", operationType = "更新")
public boolean enabledApp(@PathVariable String id) { public boolean enabledApp(@PathVariable String id) {
return appEntityService.enabledApp(id); return appEntityService.enabledApp(id);
@ -108,7 +101,6 @@ public class V1ServerController {
* @return * @return
*/ */
@GetMapping("/apps/enabled") @GetMapping("/apps/enabled")
@PreAuthorize("hasAuthority('dify:server:query')")
@DataPermission @DataPermission
public List<AppEntity> getEnableApps() { public List<AppEntity> getEnableApps() {
LambdaQueryWrapper<AppEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<AppEntity> queryWrapper = new LambdaQueryWrapper<>();
@ -122,7 +114,6 @@ public class V1ServerController {
* @return * @return
*/ */
@GetMapping("/apps/type") @GetMapping("/apps/type")
@PreAuthorize("hasAuthority('dify:server:query')")
@DataPermission @DataPermission
public List<AppEntity> getAppsByAppType(Integer appType){ public List<AppEntity> getAppsByAppType(Integer appType){
return appEntityService.selectByAppType(appType); return appEntityService.selectByAppType(appType);

View File

@ -41,7 +41,6 @@ public class V1WorkflowController {
* @return * @return
*/ */
@PostMapping("/run/{appId}") @PostMapping("/run/{appId}")
@PreAuthorize("hasAnyAuthority('dify:workflow:run','dify:ppt:run','dify:spider2:run')")
@OperationLogAnnotation(content = "'dify工作流'", operationType = "运行") @OperationLogAnnotation(content = "'dify工作流'", operationType = "运行")
public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request, @PathVariable String appId) { public WorkflowRunResponse runWorkflow(@RequestBody WorkflowRunRequest request, @PathVariable String appId) {
request.setUserId(SecurityUtil.getUserInfo().id.toString()); request.setUserId(SecurityUtil.getUserInfo().id.toString());
@ -79,7 +78,6 @@ public class V1WorkflowController {
* @return * @return
*/ */
@GetMapping("/info/{appId}") @GetMapping("/info/{appId}")
@PreAuthorize("hasAnyAuthority('dify:workflow:info','dify:ppt:info','dify:spider2:info')")
public WorkflowInfoResponse info(String workflowRunId, @PathVariable String appId) { public WorkflowInfoResponse info(String workflowRunId, @PathVariable String appId) {
String apiKey =appEntityService.getApikey(appId); String apiKey =appEntityService.getApikey(appId);
return ExceptionUtil.difyException(() -> difyWorkflow.info(workflowRunId, apiKey)); return ExceptionUtil.difyException(() -> difyWorkflow.info(workflowRunId, apiKey));
@ -92,7 +90,6 @@ public class V1WorkflowController {
* @return * @return
*/ */
@PostMapping("/logs/{appId}") @PostMapping("/logs/{appId}")
@PreAuthorize("hasAnyAuthority('dify:workflow:log','dify:ppt:log','dify:spider2:log')")
public DifyPageResult<WorkflowLogs> logs(@RequestBody WorkflowLogsRequest request, @PathVariable String appId) { public DifyPageResult<WorkflowLogs> logs(@RequestBody WorkflowLogsRequest request, @PathVariable String appId) {
String apiKey = appEntityService.getApikey(appId); String apiKey = appEntityService.getApikey(appId);
request.setApiKey(apiKey); request.setApiKey(apiKey);
@ -107,7 +104,6 @@ public class V1WorkflowController {
* @return * @return
*/ */
@GetMapping("/list/{appId}") @GetMapping("/list/{appId}")
@PreAuthorize("hasAnyAuthority('dify:workflow:query','dify:ppt:query','dify:spider2:query')")
@DataPermission @DataPermission
public List<WorkflowData> list(@PathVariable String appId){ public List<WorkflowData> list(@PathVariable String appId){
return difyWorkflowService.list(new QueryWrapper<WorkflowData>().eq("app_id",appId)); return difyWorkflowService.list(new QueryWrapper<WorkflowData>().eq("app_id",appId));
@ -120,7 +116,6 @@ public class V1WorkflowController {
* @return * @return
*/ */
@GetMapping("/detail/{id}") @GetMapping("/detail/{id}")
@PreAuthorize("hasAnyAuthority('dify:workflow:query','dify:ppt:query','dify:spider2:query')")
@DataPermission @DataPermission
public WorkflowData detail(@PathVariable Long id){ public WorkflowData detail(@PathVariable Long id){
return difyWorkflowService.detail(id); return difyWorkflowService.detail(id);
@ -133,7 +128,6 @@ public class V1WorkflowController {
* @return * @return
*/ */
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
@PreAuthorize("hasAuthority('dify:workflow:delete')")
@OperationLogAnnotation(content = "'dify工作流日志'", operationType = "删除") @OperationLogAnnotation(content = "'dify工作流日志'", operationType = "删除")
public boolean delete(@PathVariable Long id){ public boolean delete(@PathVariable Long id){
return difyWorkflowService.delete(id); return difyWorkflowService.delete(id);
@ -146,7 +140,6 @@ public class V1WorkflowController {
* @return * @return
*/ */
@GetMapping("/query") @GetMapping("/query")
@PreAuthorize("hasAuthority('dify:workflow:query')")
@DataPermission @DataPermission
public Page<WorkflowData> query(Page<WorkflowData> page){ public Page<WorkflowData> query(Page<WorkflowData> page){
return difyWorkflowService.query(page); return difyWorkflowService.query(page);

View File

@ -28,7 +28,6 @@ public class WordController {
* apikey 建议在数据库进行存储前端调用时传智能体 id从数据库查询 * apikey 建议在数据库进行存储前端调用时传智能体 id从数据库查询
*/ */
@PostMapping("/completions") @PostMapping("/completions")
@PreAuthorize("hasAuthority('dify:word:send')")
@OperationLogAnnotation(content = "'dify对话'", operationType = "发送") @OperationLogAnnotation(content = "'dify对话'", operationType = "发送")
public ChatMessageSendResponse sendChatMessage(@RequestBody ChatMessageSendRequest sendRequest){ public ChatMessageSendResponse sendChatMessage(@RequestBody ChatMessageSendRequest sendRequest){
sendRequest.setApiKey(appEntityService.getApikey("baca08c1-e92b-4dc9-a445-3584803f54d4")); sendRequest.setApiKey(appEntityService.getApikey("baca08c1-e92b-4dc9-a445-3584803f54d4"));