Skip to content

Commit 3fbd618

Browse files
authored
[app-builder] fix wrong domain access (#577)
* [app-builder] resolve query limitation of only self-owned apps when allGroupUser is enabled * [app-builder] resolve query limitation of only self-owned forms when allGroupUser is enabled * [app-builder] correct plugin query logic in permission scenarios * [app-builder] support compatibility with empty system prompt error scenarios for some LLMs * [app-builder] adapter allGroupUsers case * [app-builder] adapter allGroupUsers case
1 parent f21f976 commit 3fbd618

File tree

8 files changed

+121
-99
lines changed

8 files changed

+121
-99
lines changed

app-builder/plugins/aipp-domain-division/src/main/java/modelengine/fit/jade/aipp/domain/division/aop/GetSourceAspect.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public void beforeGet(JoinPoint joinPoint) {
5959
}
6060
String username = this.getUserName();
6161
if (this.allGroupUsers != null && this.allGroupUsers.contains(username)) {
62+
UserInfo userInfo = this.buildUserInfo(username, "*allGroupUser*");
63+
UserInfoHolder.set(userInfo);
6264
return;
6365
}
6466
UserGroup userGroup = this.getUserGroup(username);

app-builder/plugins/aipp-domain-division/src/test/java/modelengine/fit/jade/aipp/domain/division/aop/GetSourceAspectTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1010
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1112
import static org.junit.jupiter.api.Assertions.assertNull;
1213
import static org.mockito.ArgumentMatchers.any;
1314
import static org.mockito.ArgumentMatchers.eq;
@@ -97,6 +98,9 @@ void testBeforeGetUserInAllGroupUsers() {
9798
UserContext context = new UserContext("admin1", "localhost", "en");
9899
UserContextHolder.apply(context, () -> {
99100
this.getSourceAspect.beforeGet(this.joinPoint);
101+
assertNotNull(UserInfoHolder.get());
102+
assertEquals("*allGroupUser*", UserInfoHolder.get().getUserGroupId());
103+
this.getSourceAspect.afterGet(this.joinPoint);
100104
assertNull(UserInfoHolder.get());
101105
});
102106
}

app-builder/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/fitable/LlmComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
@Component
9292
public class LlmComponent implements FlowableService {
9393
private static final Logger log = Logger.get(LlmComponent.class);
94-
private static final String SYSTEM_PROMPT = "{{0}}";
94+
private static final String SYSTEM_PROMPT = ":{{0}}";
9595
private static final String PROMPT_TEMPLATE = "{{1}}";
9696
private static final String AGENT_NODE_ID = "agent";
9797
private static final String REGEX_MODEL = "statusCode=(\\d+)";

app-builder/plugins/aipp-plugin/src/main/resources/mapper/AppBuilderAppMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<if test="cond.userGroupId == null and cond.createBy != null">
127127
and create_by = #{cond.createBy}
128128
</if>
129-
<if test='cond.userGroupId != null'>
129+
<if test="cond.userGroupId != null and cond.userGroupId != '*allGroupUser*'">
130130
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
131131
</if>
132132
ORDER BY
@@ -208,7 +208,7 @@
208208
<if test="cond.userGroupId == null and cond.createBy != null">
209209
and create_by = #{cond.createBy}
210210
</if>
211-
<if test='cond.userGroupId != null'>
211+
<if test="cond.userGroupId != null and cond.userGroupId != '*allGroupUser*'">
212212
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
213213
</if>
214214
) as latest_records WHERE <include refid="appTypeCondition"/>;

app-builder/plugins/aipp-plugin/src/main/resources/mapper/AppBuilderFormMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
<if test="cond.userGroupId == null and cond.createBy != null">
103103
and create_by = #{cond.createBy}
104104
</if>
105-
<if test='cond.userGroupId != null'>
105+
<if test="cond.userGroupId != null and cond.userGroupId != '*allGroupUser*'">
106106
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
107107
</if>
108108
<if test="cond.type != null">
@@ -135,7 +135,7 @@
135135
<if test="cond.userGroupId == null and cond.createBy != null">
136136
and create_by = #{cond.createBy}
137137
</if>
138-
<if test='cond.userGroupId != null'>
138+
<if test="cond.userGroupId != null and cond.userGroupId != '*allGroupUser*'">
139139
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
140140
</if>
141141
<if test="cond.type != null">

store/plugins/store-repository-postgresql/src/main/resources/mapper/AppMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
<if test="appCategory != null and appCategory != ''">
120120
and i."app_category" ilike '%\' || #{appCategory} || '%' ESCAPE '\'
121121
</if>
122-
<if test='userGroupId != null and userGroupId != ""'>
122+
<if test='userGroupId != null and userGroupId != "" and userGroupId != "*allGroupUser*"'>
123123
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
124124
</if>
125125
</where>
@@ -135,7 +135,7 @@
135135
<if test="appCategory != null and appCategory != ''">
136136
and i."app_category" ilike '%\' || #{appCategory} || '%' ESCAPE '\'
137137
</if>
138-
<if test='userGroupId != null and userGroupId != ""'>
138+
<if test='userGroupId != null and userGroupId != "" and userGroupId != "*allGroupUser*"'>
139139
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
140140
</if>
141141
</where>

store/plugins/store-repository-postgresql/src/main/resources/mapper/PluginMapper.xml

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -118,29 +118,33 @@
118118
from "store_tag" t
119119
group by t."tool_unique_name") tg on tg."tool_unique_name" = pt."tool_unique_name"
120120
<where>
121-
<if test='isBuiltin != null and isBuiltin and userGroupId != null and userGroupId != ""'>
122-
and (i."is_builtin" = true or i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
123-
</if>
124-
<if test='isBuiltin != null and !isBuiltin and userGroupId != null and userGroupId != ""'>
125-
and (i."is_builtin" = false and i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
126-
</if>
127-
<if test="isBuiltin != null and userGroupId == null">
128-
and i."is_builtin" = #{isBuiltin}
129-
</if>
130-
<if test='isBuiltin == null and userGroupId != null and userGroupId != ""'>
131-
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
132-
</if>
133-
<if test="isBuiltin != null and isBuiltin and creator != null and creator != ''">
134-
and (i."is_builtin" = true or i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
135-
</if>
136-
<if test="isBuiltin != null and !isBuiltin and creator != null and creator != ''">
137-
and (i."is_builtin" = false and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
138-
</if>
139-
<if test="isBuiltin != null and creator == null">
140-
and i."is_builtin" = #{isBuiltin}
141-
</if>
142-
<if test="isBuiltin == null and creator != null and creator != ''">
143-
and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\'
121+
<if test='userGroupId != null and userGroupId != ""'>
122+
<if test='isBuiltin != null and isBuiltin and userGroupId != "*allGroupUser*"'>
123+
and (i."is_builtin" = true or i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
124+
</if>
125+
<if test='isBuiltin != null and !isBuiltin and userGroupId != "*allGroupUser*"'>
126+
and (i."is_builtin" = false and i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
127+
</if>
128+
<if test="isBuiltin != null and !isBuiltin and userGroupId == '*allGroupUser*'">
129+
and i."is_builtin" = false
130+
</if>
131+
<if test='isBuiltin == null and userGroupId != "*allGroupUser*"'>
132+
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
133+
</if>
134+
</if>
135+
<if test='userGroupId == null or userGroupId == ""'>
136+
<if test="isBuiltin != null and isBuiltin and creator != null and creator != ''">
137+
and (i."is_builtin" = true or i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
138+
</if>
139+
<if test="isBuiltin != null and !isBuiltin and creator != null and creator != ''">
140+
and (i."is_builtin" = false and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
141+
</if>
142+
<if test="isBuiltin != null and creator == null">
143+
and i."is_builtin" = #{isBuiltin}
144+
</if>
145+
<if test="isBuiltin == null and creator != null and creator != ''">
146+
and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\'
147+
</if>
144148
</if>
145149
<if test="isDeployed != null and isDeployed">
146150
and (i."deploy_status" = 'DEPLOYED' or i."deploy_status" = 'RELEASED')
@@ -156,29 +160,33 @@
156160
<select id="getPluginsCount" parameterType="modelengine.jade.store.entity.query.PluginQuery">
157161
<include refid="getCount"/>
158162
<where>
159-
<if test='isBuiltin != null and isBuiltin and userGroupId != null and userGroupId != ""'>
160-
and (i."is_builtin" = true or i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
161-
</if>
162-
<if test='isBuiltin != null and !isBuiltin and userGroupId != null and userGroupId != ""'>
163-
and (i."is_builtin" = false and i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
164-
</if>
165-
<if test="isBuiltin != null and userGroupId == null">
166-
and i."is_builtin" = #{isBuiltin}
167-
</if>
168-
<if test='isBuiltin == null and userGroupId != null and userGroupId != ""'>
169-
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
170-
</if>
171-
<if test="isBuiltin != null and isBuiltin and creator != null and creator != ''">
172-
and (i."is_builtin" = true or i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
173-
</if>
174-
<if test="isBuiltin != null and !isBuiltin and creator != null and creator != ''">
175-
and (i."is_builtin" = false and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
176-
</if>
177-
<if test="isBuiltin != null and creator == null">
178-
and i."is_builtin" = #{isBuiltin}
179-
</if>
180-
<if test="isBuiltin == null and creator != null and creator != ''">
181-
and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\'
163+
<if test='userGroupId != null and userGroupId != ""'>
164+
<if test='isBuiltin != null and isBuiltin and userGroupId != "*allGroupUser*"'>
165+
and (i."is_builtin" = true or i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
166+
</if>
167+
<if test='isBuiltin != null and !isBuiltin and userGroupId != "*allGroupUser*"'>
168+
and (i."is_builtin" = false and i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
169+
</if>
170+
<if test="isBuiltin != null and !isBuiltin and userGroupId == '*allGroupUser*'">
171+
and i."is_builtin" = false
172+
</if>
173+
<if test='isBuiltin == null and userGroupId != "*allGroupUser*"'>
174+
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
175+
</if>
176+
</if>
177+
<if test='userGroupId == null or userGroupId == ""'>
178+
<if test="isBuiltin != null and isBuiltin and creator != null and creator != ''">
179+
and (i."is_builtin" = true or i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
180+
</if>
181+
<if test="isBuiltin != null and !isBuiltin and creator != null and creator != ''">
182+
and (i."is_builtin" = false and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
183+
</if>
184+
<if test="isBuiltin != null and creator == null">
185+
and i."is_builtin" = #{isBuiltin}
186+
</if>
187+
<if test="isBuiltin == null and creator != null and creator != ''">
188+
and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\'
189+
</if>
182190
</if>
183191
<if test="isDeployed != null and isDeployed">
184192
and (i."deploy_status" = 'DEPLOYED' or i."deploy_status" = 'RELEASED')

store/plugins/store-repository-postgresql/src/main/resources/mapper/PluginToolMapper.xml

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -136,29 +136,33 @@
136136
<if test="isDeployed != null and isDeployed">
137137
and (p."deploy_status" = 'DEPLOYED' or p."deploy_status" = 'RELEASED')
138138
</if>
139-
<if test='isBuiltin != null and isBuiltin and userGroupId != null and userGroupId != ""'>
140-
and (p."is_builtin" = true or i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
141-
</if>
142-
<if test='isBuiltin != null and !isBuiltin and userGroupId != null and userGroupId != ""'>
143-
and (p."is_builtin" = false and i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
144-
</if>
145-
<if test="isBuiltin != null and userGroupId == null">
146-
and p."is_builtin" = #{isBuiltin}
147-
</if>
148-
<if test='isBuiltin == null and userGroupId != null and userGroupId != ""'>
149-
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
150-
</if>
151-
<if test="isBuiltin != null and isBuiltin and creator != null and creator != '' and userGroupId == null">
152-
and (p."is_builtin" = true or i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
153-
</if>
154-
<if test="isBuiltin != null and !isBuiltin and creator != null and creator != '' and userGroupId == null">
155-
and (p."is_builtin" = false and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
156-
</if>
157-
<if test="isBuiltin != null and creator == null and userGroupId == null">
158-
and p."is_builtin" = #{isBuiltin}
159-
</if>
160-
<if test="isBuiltin == null and creator != null and creator != '' and userGroupId == null">
161-
and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\'
139+
<if test='userGroupId != null and userGroupId != ""'>
140+
<if test='isBuiltin != null and isBuiltin and userGroupId != "*allGroupUser*"'>
141+
and (p."is_builtin" = true or i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
142+
</if>
143+
<if test='isBuiltin != null and !isBuiltin and userGroupId != "*allGroupUser*"'>
144+
and (p."is_builtin" = false and i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
145+
</if>
146+
<if test="isBuiltin != null and !isBuiltin and userGroupId == '*allGroupUser*'">
147+
and p."is_builtin" = false
148+
</if>
149+
<if test='isBuiltin == null and userGroupId != "*allGroupUser*"'>
150+
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
151+
</if>
152+
</if>
153+
<if test='userGroupId == null or userGroupId == ""'>
154+
<if test="isBuiltin != null and isBuiltin and creator != null and creator != ''">
155+
and (p."is_builtin" = true or i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
156+
</if>
157+
<if test="isBuiltin != null and !isBuiltin and creator != null and creator != ''">
158+
and (p."is_builtin" = false and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
159+
</if>
160+
<if test="isBuiltin != null and creator == null">
161+
and p."is_builtin" = #{isBuiltin}
162+
</if>
163+
<if test="isBuiltin == null and creator != null and creator != ''">
164+
and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\'
165+
</if>
162166
</if>
163167
<include refid="getOrSearchConditions"/>
164168
<if test="toolName != null and toolName != ''">
@@ -173,29 +177,33 @@
173177
<if test="isDeployed != null and isDeployed">
174178
and (p."deploy_status" = 'DEPLOYED' or p."deploy_status" = 'RELEASED')
175179
</if>
176-
<if test='isBuiltin != null and isBuiltin and userGroupId != null and userGroupId != ""'>
177-
and (p."is_builtin" = true or i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
178-
</if>
179-
<if test='isBuiltin != null and !isBuiltin and userGroupId != null and userGroupId != ""'>
180-
and (p."is_builtin" = false and i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
181-
</if>
182-
<if test="isBuiltin != null and userGroupId == null">
183-
and p."is_builtin" = #{isBuiltin}
184-
</if>
185-
<if test='isBuiltin == null and userGroupId != null and userGroupId != ""'>
186-
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
187-
</if>
188-
<if test="isBuiltin != null and isBuiltin and creator != null and creator != '' and userGroupId == null">
189-
and (p."is_builtin" = true or i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
190-
</if>
191-
<if test="isBuiltin != null and !isBuiltin and creator != null and creator != '' and userGroupId == null">
192-
and (p."is_builtin" = false and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
193-
</if>
194-
<if test="isBuiltin != null and creator == null and userGroupId == null">
195-
and p."is_builtin" = #{isBuiltin}
196-
</if>
197-
<if test="isBuiltin == null and creator != null and creator != '' and userGroupId == null">
198-
and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\'
180+
<if test='userGroupId != null and userGroupId != ""'>
181+
<if test='isBuiltin != null and isBuiltin and userGroupId != "*allGroupUser*"'>
182+
and (p."is_builtin" = true or i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
183+
</if>
184+
<if test='isBuiltin != null and !isBuiltin and userGroupId != "*allGroupUser*"'>
185+
and (p."is_builtin" = false and i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
186+
</if>
187+
<if test="isBuiltin != null and !isBuiltin and userGroupId == '*allGroupUser*'">
188+
and p."is_builtin" = false
189+
</if>
190+
<if test='isBuiltin == null and userGroupId != "*allGroupUser*"'>
191+
and (i."user_group_id" = #{userGroupId} or i."user_group_id" = '*')
192+
</if>
193+
</if>
194+
<if test='userGroupId == null or userGroupId == ""'>
195+
<if test="isBuiltin != null and isBuiltin and creator != null and creator != ''">
196+
and (p."is_builtin" = true or i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
197+
</if>
198+
<if test="isBuiltin != null and !isBuiltin and creator != null and creator != ''">
199+
and (p."is_builtin" = false and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\')
200+
</if>
201+
<if test="isBuiltin != null and creator == null">
202+
and p."is_builtin" = #{isBuiltin}
203+
</if>
204+
<if test="isBuiltin == null and creator != null and creator != ''">
205+
and i."creator" ilike '%\' || #{creator} || '%' ESCAPE '\'
206+
</if>
199207
</if>
200208
<include refid="getOrSearchConditions"/>
201209
<if test="toolName != null and toolName != ''">

0 commit comments

Comments
 (0)