6
6
7
7
import com .ctrip .framework .apollo .common .dto .GrayReleaseRuleDTO ;
8
8
import com .ctrip .framework .apollo .common .dto .NamespaceDTO ;
9
+ import com .ctrip .framework .apollo .common .exception .BadRequestException ;
9
10
import com .ctrip .framework .apollo .common .utils .BeanUtils ;
11
+ import com .ctrip .framework .apollo .common .utils .RequestPrecondition ;
10
12
import com .ctrip .framework .apollo .core .enums .Env ;
13
+ import com .ctrip .framework .apollo .core .utils .StringUtils ;
11
14
import com .ctrip .framework .apollo .openapi .auth .ConsumerPermissionValidator ;
12
15
import com .ctrip .framework .apollo .openapi .dto .OpenGrayReleaseRuleDTO ;
13
16
import com .ctrip .framework .apollo .openapi .dto .OpenNamespaceDTO ;
16
19
import com .ctrip .framework .apollo .portal .entity .bo .NamespaceBO ;
17
20
import com .ctrip .framework .apollo .portal .service .NamespaceBranchService ;
18
21
import com .ctrip .framework .apollo .portal .service .ReleaseService ;
22
+ import com .ctrip .framework .apollo .portal .spi .UserService ;
19
23
import org .springframework .beans .factory .annotation .Autowired ;
20
24
import org .springframework .security .access .AccessDeniedException ;
21
25
import org .springframework .security .access .prepost .PreAuthorize ;
@@ -33,6 +37,8 @@ public class NamespaceBranchController {
33
37
private ReleaseService releaseService ;
34
38
@ Autowired
35
39
private NamespaceBranchService namespaceBranchService ;
40
+ @ Autowired
41
+ private UserService userService ;
36
42
37
43
@ RequestMapping (value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches" , method = RequestMethod .GET )
38
44
public OpenNamespaceDTO findBranch (@ PathVariable String appId ,
@@ -54,6 +60,12 @@ public OpenNamespaceDTO createBranch(@PathVariable String appId,
54
60
@ PathVariable String namespaceName ,
55
61
@ RequestParam ("operator" ) String operator ,
56
62
HttpServletRequest request ) {
63
+ RequestPrecondition .checkArguments (!StringUtils .isContainEmpty (operator ),"operator can not be empty" );
64
+
65
+ if (userService .findByUserId (operator ) == null ) {
66
+ throw new BadRequestException ("operator " + operator + " not exists" );
67
+ }
68
+
57
69
NamespaceDTO namespaceDTO = namespaceBranchService .createBranch (appId , Env .valueOf (env .toUpperCase ()), clusterName , namespaceName , operator );
58
70
if (namespaceDTO == null ) {
59
71
return null ;
@@ -70,6 +82,12 @@ public void deleteBranch(@PathVariable String appId,
70
82
@ PathVariable String branchName ,
71
83
@ RequestParam ("operator" ) String operator ,
72
84
HttpServletRequest request ) {
85
+ RequestPrecondition .checkArguments (!StringUtils .isContainEmpty (operator ),"operator can not be empty" );
86
+
87
+ if (userService .findByUserId (operator ) == null ) {
88
+ throw new BadRequestException ("operator " + operator + " not exists" );
89
+ }
90
+
73
91
boolean canDelete = consumerPermissionValidator .hasReleaseNamespacePermission (request , appId , namespaceName , env ) ||
74
92
(consumerPermissionValidator .hasModifyNamespacePermission (request , appId , namespaceName , env ) &&
75
93
releaseService .loadLatestRelease (appId , Env .valueOf (env ), branchName , namespaceName ) == null );
@@ -103,6 +121,17 @@ public void updateBranchRules(@PathVariable String appId, @PathVariable String e
103
121
@ PathVariable String branchName , @ RequestBody OpenGrayReleaseRuleDTO rules ,
104
122
@ RequestParam ("operator" ) String operator ,
105
123
HttpServletRequest request ) {
124
+ RequestPrecondition .checkArguments (!StringUtils .isContainEmpty (operator ),"operator can not be empty" );
125
+
126
+ if (userService .findByUserId (operator ) == null ) {
127
+ throw new BadRequestException ("operator " + operator + " not exists" );
128
+ }
129
+
130
+ rules .setAppId (appId );
131
+ rules .setClusterName (clusterName );
132
+ rules .setNamespaceName (namespaceName );
133
+ rules .setBranchName (branchName );
134
+
106
135
GrayReleaseRuleDTO grayReleaseRuleDTO = OpenApiBeanUtils .transformToGrayReleaseRuleDTO (rules );
107
136
namespaceBranchService
108
137
.updateBranchGrayRules (appId , Env .valueOf (env .toUpperCase ()), clusterName , namespaceName , branchName , grayReleaseRuleDTO , operator );
0 commit comments