Skip to content

Commit b84c282

Browse files
authored
Merge branch 'master' into issue_1077_3
2 parents d647c73 + a343171 commit b84c282

File tree

9 files changed

+67
-29
lines changed

9 files changed

+67
-29
lines changed

api/internal/handler/global_rule/global_rule.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ package global_rule
1818

1919
import (
2020
"encoding/json"
21+
"net/http"
2122
"reflect"
2223

2324
"github.com/gin-gonic/gin"
2425
"github.com/shiningrush/droplet"
26+
"github.com/shiningrush/droplet/data"
2527
"github.com/shiningrush/droplet/wrapper"
2628
wgin "github.com/shiningrush/droplet/wrapper/gin"
2729

@@ -49,9 +51,9 @@ func (h *Handler) ApplyRoute(r *gin.Engine) {
4951
r.GET("/apisix/admin/global_rules", wgin.Wraps(h.List,
5052
wrapper.InputType(reflect.TypeOf(ListInput{}))))
5153
r.PUT("/apisix/admin/global_rules/:id", wgin.Wraps(h.Set,
52-
wrapper.InputType(reflect.TypeOf(entity.GlobalPlugins{}))))
54+
wrapper.InputType(reflect.TypeOf(SetInput{}))))
5355
r.PUT("/apisix/admin/global_rules", wgin.Wraps(h.Set,
54-
wrapper.InputType(reflect.TypeOf(entity.GlobalPlugins{}))))
56+
wrapper.InputType(reflect.TypeOf(SetInput{}))))
5557

5658
r.PATCH("/apisix/admin/global_rules/:id", consts.ErrorWrapper(Patch))
5759
r.PATCH("/apisix/admin/global_rules/:id/*path", consts.ErrorWrapper(Patch))
@@ -121,10 +123,25 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
121123
return ret, nil
122124
}
123125

126+
type SetInput struct {
127+
entity.GlobalPlugins
128+
ID string `auto_read:"id,path"`
129+
}
130+
124131
func (h *Handler) Set(c droplet.Context) (interface{}, error) {
125-
input := c.Input().(*entity.GlobalPlugins)
132+
input := c.Input().(*SetInput)
133+
134+
// check if ID in body is equal ID in path
135+
if err := handler.IDCompare(input.ID, input.GlobalPlugins.ID); err != nil {
136+
return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest}, err
137+
}
138+
139+
// if has id in path, use it
140+
if input.ID != "" {
141+
input.GlobalPlugins.ID = input.ID
142+
}
126143

127-
if err := h.globalRuleStore.Create(c.Context(), input); err != nil {
144+
if err := h.globalRuleStore.Update(c.Context(), &input.GlobalPlugins, true); err != nil {
128145
return handler.SpecCodeResponse(err), err
129146
}
130147

api/internal/handler/global_rule/global_rule_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func TestHandler_List(t *testing.T) {
209209
func TestHandler_Set(t *testing.T) {
210210
tests := []struct {
211211
caseDesc string
212-
giveInput *entity.GlobalPlugins
212+
giveInput *SetInput
213213
giveCtx context.Context
214214
giveErr error
215215
wantErr error
@@ -219,10 +219,12 @@ func TestHandler_Set(t *testing.T) {
219219
}{
220220
{
221221
caseDesc: "normal",
222-
giveInput: &entity.GlobalPlugins{
222+
giveInput: &SetInput{
223223
ID: "name",
224-
Plugins: map[string]interface{}{
225-
"jwt-auth": map[string]interface{}{},
224+
GlobalPlugins: entity.GlobalPlugins{
225+
Plugins: map[string]interface{}{
226+
"jwt-auth": map[string]interface{}{},
227+
},
226228
},
227229
},
228230
giveCtx: context.WithValue(context.Background(), "test", "value"),
@@ -237,9 +239,9 @@ func TestHandler_Set(t *testing.T) {
237239
},
238240
{
239241
caseDesc: "store create failed",
240-
giveInput: &entity.GlobalPlugins{
241-
ID: "name",
242-
Plugins: nil,
242+
giveInput: &SetInput{
243+
ID: "name",
244+
GlobalPlugins: entity.GlobalPlugins{},
243245
},
244246
giveErr: fmt.Errorf("create failed"),
245247
wantInput: &entity.GlobalPlugins{
@@ -258,10 +260,11 @@ func TestHandler_Set(t *testing.T) {
258260
t.Run(tc.caseDesc, func(t *testing.T) {
259261
methodCalled := true
260262
mStore := &store.MockInterface{}
261-
mStore.On("Create", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
263+
mStore.On("Update", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
262264
methodCalled = true
263265
assert.Equal(t, tc.giveCtx, args.Get(0))
264266
assert.Equal(t, tc.wantInput, args.Get(1))
267+
assert.True(t, args.Bool(2))
265268
}).Return(tc.giveErr)
266269

267270
h := Handler{globalRuleStore: mStore}

api/test/e2e/global_rule_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ func TestGlobalRule(t *testing.T) {
5656
Path: "/apisix/admin/global_rules/1",
5757
Method: http.MethodPut,
5858
Body: `{
59-
"id": "1",
6059
"plugins": {
6160
"response-rewrite": {
6261
"headers": {
@@ -182,6 +181,36 @@ func TestGlobalRule(t *testing.T) {
182181
ExpectHeaders: map[string]string{"X-VERSION": "2.0"},
183182
Sleep: sleepTime,
184183
},
184+
{
185+
Desc: "update global rule",
186+
Object: ManagerApiExpect(t),
187+
Path: "/apisix/admin/global_rules/1",
188+
Method: http.MethodPut,
189+
Body: `{
190+
"id": "1",
191+
"plugins": {
192+
"response-rewrite": {
193+
"headers": {
194+
"X-VERSION":"1.0"
195+
}
196+
},
197+
"uri-blocker": {
198+
"block_rules": ["root.exe", "root.m+"]
199+
}
200+
}
201+
}`,
202+
Headers: map[string]string{"Authorization": token},
203+
ExpectStatus: http.StatusOK,
204+
},
205+
{
206+
Desc: "make sure that update succeeded",
207+
Object: APISIXExpect(t),
208+
Method: http.MethodGet,
209+
Path: "/hello",
210+
Query: "file=root.exe",
211+
ExpectStatus: http.StatusForbidden,
212+
Sleep: sleepTime,
213+
},
185214
{
186215
Desc: "delete global rule",
187216
Object: ManagerApiExpect(t),

docs/I18N_USER_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ the key can be like this : [basicModule].[moduleName].[elementName].[...desc]
4545

4646
## Global locale keys
4747

48-
we have already defined many global keys, before you do i18n, you can refer to [those](https://github.com/apache/apisix-dashboard/blob/master/src/locales/zh-CN/component.ts).
48+
we have already defined many global keys, before you do i18n, you can refer to [those](https://github.com/apache/apisix-dashboard/blob/master/web/src/locales/zh-CN/component.ts).
4949

5050
## Recommended subkey naming
5151

web/src/pages/Consumer/List.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ import { history, useIntl } from 'umi';
2222
import { PlusOutlined } from '@ant-design/icons';
2323

2424
import { timestampToLocaleString } from '@/helpers';
25-
import useForceIntl from '@/hooks/useForceIntl';
2625

2726
import { fetchList, remove } from './service';
2827

2928
const Page: React.FC = () => {
30-
useForceIntl();
31-
3229
const ref = useRef<ActionType>();
3330
const { formatMessage } = useIntl();
3431

web/src/pages/Route/List.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ import { history, useIntl } from 'umi';
2222
import { PlusOutlined, BugOutlined } from '@ant-design/icons';
2323

2424
import { timestampToLocaleString } from '@/helpers';
25-
import useForceIntl from '@/hooks/useForceIntl';
2625
import { fetchList, remove, fetchLabelList, updateRouteStatus } from './service';
2726
import { DebugDrawView } from './components/DebugViews';
2827

2928
const { OptGroup, Option } = Select;
3029

3130
const Page: React.FC = () => {
32-
useForceIntl();
33-
3431
const ref = useRef<ActionType>();
3532
const { formatMessage } = useIntl();
3633

web/src/pages/SSL/List.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ import { PlusOutlined } from '@ant-design/icons';
2323

2424
import { fetchList, remove as removeSSL } from '@/pages/SSL/service';
2525
import { timestampToLocaleString } from '@/helpers';
26-
import useForceIntl from '@/hooks/useForceIntl';
2726

2827
const Page: React.FC = () => {
29-
useForceIntl();
3028
const tableRef = useRef<ActionType>();
3129
const { formatMessage } = useIntl();
3230

web/src/pages/Service/List.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table';
2121
import { PlusOutlined } from '@ant-design/icons';
2222
import { Button, notification, Popconfirm, Space } from 'antd';
2323

24-
import useForceIntl from '@/hooks/useForceIntl';
25-
2624
import { fetchList, remove } from './service';
2725

2826
const Page: React.FC = () => {
29-
useForceIntl();
30-
3127
const ref = useRef<ActionType>();
3228
const { formatMessage } = useIntl();
3329

@@ -96,6 +92,10 @@ const Page: React.FC = () => {
9692
rowKey="id"
9793
columns={columns}
9894
request={fetchList}
95+
search={{
96+
searchText: formatMessage({ id: 'component.global.search' }),
97+
resetText: formatMessage({ id: 'component.global.reset' }),
98+
}}
9999
toolBarRender={() => [
100100
<Button type="primary" onClick={() => history.push(`/service/create`)}>
101101
<PlusOutlined />

web/src/pages/Upstream/List.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ import { Popconfirm, Button, notification } from 'antd';
2121
import { history, useIntl } from 'umi';
2222
import { PlusOutlined } from '@ant-design/icons';
2323
import { timestampToLocaleString } from '@/helpers';
24-
import useForceIntl from '@/hooks/useForceIntl';
2524

2625
import { fetchList, remove } from './service';
2726

2827
const Page: React.FC = () => {
29-
useForceIntl();
30-
3128
const ref = useRef<ActionType>();
3229

3330
const { formatMessage } = useIntl();

0 commit comments

Comments
 (0)