正在显示
12 个修改的文件
包含
149 行增加
和
90 行删除
@@ -18,8 +18,11 @@ func (controller *RoleController) CreateCycle() { | @@ -18,8 +18,11 @@ func (controller *RoleController) CreateCycle() { | ||
18 | if err := controller.Unmarshal(in); err != nil { | 18 | if err := controller.Unmarshal(in); err != nil { |
19 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 19 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
20 | } else { | 20 | } else { |
21 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
22 | - in.CreatorId = middlewares.GetUserId(controller.Ctx) | 21 | + ua := middlewares.GetUser(controller.Ctx) |
22 | + in.CompanyId = ua.CompanyId | ||
23 | + in.CreatorId = ua.UserId | ||
24 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
25 | + //in.CreatorId = middlewares.GetUserId(controller.Ctx) | ||
23 | controller.Response(ruService.Create(in)) | 26 | controller.Response(ruService.Create(in)) |
24 | } | 27 | } |
25 | } | 28 | } |
@@ -30,7 +33,9 @@ func (controller *CycleController) UpdateCycle() { | @@ -30,7 +33,9 @@ func (controller *CycleController) UpdateCycle() { | ||
30 | if err := controller.Unmarshal(in); err != nil { | 33 | if err := controller.Unmarshal(in); err != nil { |
31 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 34 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
32 | } else { | 35 | } else { |
33 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 36 | + ua := middlewares.GetUser(controller.Ctx) |
37 | + in.CompanyId = ua.CompanyId | ||
38 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
34 | controller.Response(ruService.Update(in)) | 39 | controller.Response(ruService.Update(in)) |
35 | } | 40 | } |
36 | } | 41 | } |
@@ -65,7 +70,9 @@ func (controller *CycleController) ListCycle() { | @@ -65,7 +70,9 @@ func (controller *CycleController) ListCycle() { | ||
65 | if len(in.Name) > 0 { | 70 | if len(in.Name) > 0 { |
66 | in.Name = "%" + in.Name + "%" | 71 | in.Name = "%" + in.Name + "%" |
67 | } | 72 | } |
68 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 73 | + ua := middlewares.GetUser(controller.Ctx) |
74 | + in.CompanyId = ua.CompanyId | ||
75 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
69 | controller.Response(ruService.List(in)) | 76 | controller.Response(ruService.List(in)) |
70 | } | 77 | } |
71 | } | 78 | } |
@@ -18,8 +18,11 @@ func (controller *RoleController) CreateProject() { | @@ -18,8 +18,11 @@ func (controller *RoleController) CreateProject() { | ||
18 | if err := controller.Unmarshal(in); err != nil { | 18 | if err := controller.Unmarshal(in); err != nil { |
19 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 19 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
20 | } else { | 20 | } else { |
21 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
22 | - in.CreatorId = middlewares.GetUserId(controller.Ctx) | 21 | + ua := middlewares.GetUser(controller.Ctx) |
22 | + in.CompanyId = ua.CompanyId | ||
23 | + in.CreatorId = ua.UserId | ||
24 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
25 | + //in.CreatorId = middlewares.GetUserId(controller.Ctx) | ||
23 | controller.Response(ruService.Create(in)) | 26 | controller.Response(ruService.Create(in)) |
24 | } | 27 | } |
25 | } | 28 | } |
@@ -30,7 +33,9 @@ func (controller *ProjectController) UpdateProject() { | @@ -30,7 +33,9 @@ func (controller *ProjectController) UpdateProject() { | ||
30 | if err := controller.Unmarshal(in); err != nil { | 33 | if err := controller.Unmarshal(in); err != nil { |
31 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 34 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
32 | } else { | 35 | } else { |
33 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 36 | + ua := middlewares.GetUser(controller.Ctx) |
37 | + in.CompanyId = ua.CompanyId | ||
38 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
34 | controller.Response(ruService.Update(in)) | 39 | controller.Response(ruService.Update(in)) |
35 | } | 40 | } |
36 | } | 41 | } |
@@ -41,7 +46,9 @@ func (controller *ProjectController) UpdateProjectForTemplate() { | @@ -41,7 +46,9 @@ func (controller *ProjectController) UpdateProjectForTemplate() { | ||
41 | if err := controller.Unmarshal(in); err != nil { | 46 | if err := controller.Unmarshal(in); err != nil { |
42 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 47 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
43 | } else { | 48 | } else { |
44 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 49 | + ua := middlewares.GetUser(controller.Ctx) |
50 | + in.CompanyId = ua.CompanyId | ||
51 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
45 | controller.Response(ruService.UpdateTemplate(in)) | 52 | controller.Response(ruService.UpdateTemplate(in)) |
46 | } | 53 | } |
47 | } | 54 | } |
@@ -52,7 +59,9 @@ func (controller *ProjectController) UpdateProjectForTemplateNode() { | @@ -52,7 +59,9 @@ func (controller *ProjectController) UpdateProjectForTemplateNode() { | ||
52 | if err := controller.Unmarshal(in); err != nil { | 59 | if err := controller.Unmarshal(in); err != nil { |
53 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 60 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
54 | } else { | 61 | } else { |
55 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 62 | + ua := middlewares.GetUser(controller.Ctx) |
63 | + in.CompanyId = ua.CompanyId | ||
64 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
56 | controller.Response(ruService.UpdateTemplateNode(in)) | 65 | controller.Response(ruService.UpdateTemplateNode(in)) |
57 | } | 66 | } |
58 | } | 67 | } |
@@ -88,7 +97,9 @@ func (controller *ProjectController) ListProject() { | @@ -88,7 +97,9 @@ func (controller *ProjectController) ListProject() { | ||
88 | if len(in.Name) > 0 { | 97 | if len(in.Name) > 0 { |
89 | in.Name = "%" + in.Name + "%" | 98 | in.Name = "%" + in.Name + "%" |
90 | } | 99 | } |
91 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 100 | + ua := middlewares.GetUser(controller.Ctx) |
101 | + in.CompanyId = ua.CompanyId | ||
102 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
92 | controller.Response(ruService.List(in)) | 103 | controller.Response(ruService.List(in)) |
93 | } | 104 | } |
94 | } | 105 | } |
@@ -119,7 +130,9 @@ func (controller *ProjectController) StatisticCycleUser() { | @@ -119,7 +130,9 @@ func (controller *ProjectController) StatisticCycleUser() { | ||
119 | if err := controller.Unmarshal(in); err != nil { | 130 | if err := controller.Unmarshal(in); err != nil { |
120 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 131 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
121 | } else { | 132 | } else { |
122 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 133 | + ua := middlewares.GetUser(controller.Ctx) |
134 | + in.CompanyId = ua.CompanyId | ||
135 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
123 | controller.Response(ruService.StatisticCycleUser(in)) | 136 | controller.Response(ruService.StatisticCycleUser(in)) |
124 | } | 137 | } |
125 | } | 138 | } |
@@ -18,8 +18,11 @@ func (controller *RoleController) CreateRule() { | @@ -18,8 +18,11 @@ func (controller *RoleController) CreateRule() { | ||
18 | if err := controller.Unmarshal(in); err != nil { | 18 | if err := controller.Unmarshal(in); err != nil { |
19 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 19 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
20 | } else { | 20 | } else { |
21 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
22 | - in.CreatorId = middlewares.GetUserId(controller.Ctx) | 21 | + ua := middlewares.GetUser(controller.Ctx) |
22 | + in.CompanyId = ua.CompanyId | ||
23 | + in.CreatorId = ua.UserId | ||
24 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
25 | + //in.CreatorId = middlewares.GetUserId(controller.Ctx) | ||
23 | controller.Response(ruService.Create(in)) | 26 | controller.Response(ruService.Create(in)) |
24 | } | 27 | } |
25 | } | 28 | } |
@@ -30,8 +33,11 @@ func (controller *RuleController) UpdateRule() { | @@ -30,8 +33,11 @@ func (controller *RuleController) UpdateRule() { | ||
30 | if err := controller.Unmarshal(in); err != nil { | 33 | if err := controller.Unmarshal(in); err != nil { |
31 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 34 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
32 | } else { | 35 | } else { |
33 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
34 | - in.CreatorId = middlewares.GetUserId(controller.Ctx) | 36 | + ua := middlewares.GetUser(controller.Ctx) |
37 | + in.CompanyId = ua.CompanyId | ||
38 | + in.CreatorId = ua.UserId | ||
39 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
40 | + //in.CreatorId = middlewares.GetUserId(controller.Ctx) | ||
35 | controller.Response(ruService.Update(in)) | 41 | controller.Response(ruService.Update(in)) |
36 | } | 42 | } |
37 | } | 43 | } |
@@ -82,7 +88,9 @@ func (controller *RuleController) ListRuleRelCreator() { | @@ -82,7 +88,9 @@ func (controller *RuleController) ListRuleRelCreator() { | ||
82 | if len(in.NameOrRemark) > 0 { | 88 | if len(in.NameOrRemark) > 0 { |
83 | in.NameOrRemark = "%" + in.NameOrRemark + "%" | 89 | in.NameOrRemark = "%" + in.NameOrRemark + "%" |
84 | } | 90 | } |
85 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 91 | + ua := middlewares.GetUser(controller.Ctx) |
92 | + in.CompanyId = ua.CompanyId | ||
93 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
86 | controller.Response(ruService.ListRelCreator(in)) | 94 | controller.Response(ruService.ListRelCreator(in)) |
87 | } | 95 | } |
88 | } | 96 | } |
@@ -19,8 +19,11 @@ func (controller *RoleController) CreateTemplate() { | @@ -19,8 +19,11 @@ func (controller *RoleController) CreateTemplate() { | ||
19 | if err := controller.Unmarshal(in); err != nil { | 19 | if err := controller.Unmarshal(in); err != nil { |
20 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 20 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
21 | } else { | 21 | } else { |
22 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
23 | - in.CreatorId = middlewares.GetUserId(controller.Ctx) | 22 | + ua := middlewares.GetUser(controller.Ctx) |
23 | + in.CompanyId = ua.CompanyId | ||
24 | + in.CreatorId = ua.UserId | ||
25 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
26 | + //in.CreatorId = middlewares.GetUserId(controller.Ctx) | ||
24 | controller.Response(ruService.Create(in)) | 27 | controller.Response(ruService.Create(in)) |
25 | } | 28 | } |
26 | } | 29 | } |
@@ -31,7 +34,9 @@ func (controller *TemplateController) UpdateTemplate() { | @@ -31,7 +34,9 @@ func (controller *TemplateController) UpdateTemplate() { | ||
31 | if err := controller.Unmarshal(in); err != nil { | 34 | if err := controller.Unmarshal(in); err != nil { |
32 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 35 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
33 | } else { | 36 | } else { |
34 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 37 | + ua := middlewares.GetUser(controller.Ctx) |
38 | + in.CompanyId = ua.CompanyId | ||
39 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
35 | controller.Response(ruService.Update(in)) | 40 | controller.Response(ruService.Update(in)) |
36 | } | 41 | } |
37 | } | 42 | } |
@@ -67,7 +72,9 @@ func (controller *TemplateController) ListTemplate() { | @@ -67,7 +72,9 @@ func (controller *TemplateController) ListTemplate() { | ||
67 | if len(in.Name) > 0 { | 72 | if len(in.Name) > 0 { |
68 | in.Name = "%" + in.Name + "%" | 73 | in.Name = "%" + in.Name + "%" |
69 | } | 74 | } |
70 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 75 | + ua := middlewares.GetUser(controller.Ctx) |
76 | + in.CompanyId = ua.CompanyId | ||
77 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
71 | controller.Response(ruService.List(in)) | 78 | controller.Response(ruService.List(in)) |
72 | } | 79 | } |
73 | } | 80 | } |
@@ -81,7 +88,9 @@ func (controller *TemplateController) ListEnableTemplate() { | @@ -81,7 +88,9 @@ func (controller *TemplateController) ListEnableTemplate() { | ||
81 | if err := controller.Unmarshal(in); err != nil { | 88 | if err := controller.Unmarshal(in); err != nil { |
82 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 89 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
83 | } else { | 90 | } else { |
84 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 91 | + ua := middlewares.GetUser(controller.Ctx) |
92 | + in.CompanyId = ua.CompanyId | ||
93 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
85 | controller.Response(ruService.List(in)) | 94 | controller.Response(ruService.List(in)) |
86 | } | 95 | } |
87 | } | 96 | } |
@@ -92,7 +101,9 @@ func (controller *TemplateController) StateTemplate() { | @@ -92,7 +101,9 @@ func (controller *TemplateController) StateTemplate() { | ||
92 | if err := controller.Unmarshal(in); err != nil { | 101 | if err := controller.Unmarshal(in); err != nil { |
93 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 102 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
94 | } else { | 103 | } else { |
95 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 104 | + ua := middlewares.GetUser(controller.Ctx) |
105 | + in.CompanyId = ua.CompanyId | ||
106 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
96 | controller.Response(ruService.State(in)) | 107 | controller.Response(ruService.State(in)) |
97 | } | 108 | } |
98 | } | 109 | } |
@@ -103,8 +114,11 @@ func (controller *TemplateController) CopyTemplate() { | @@ -103,8 +114,11 @@ func (controller *TemplateController) CopyTemplate() { | ||
103 | if err := controller.Unmarshal(in); err != nil { | 114 | if err := controller.Unmarshal(in); err != nil { |
104 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 115 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
105 | } else { | 116 | } else { |
106 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
107 | - in.CreatorId = middlewares.GetUserId(controller.Ctx) | 117 | + ua := middlewares.GetUser(controller.Ctx) |
118 | + in.CompanyId = ua.CompanyId | ||
119 | + in.CreatorId = ua.UserId | ||
120 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
121 | + //in.CreatorId = middlewares.GetUserId(controller.Ctx) | ||
108 | controller.Response(ruService.Copy(in)) | 122 | controller.Response(ruService.Copy(in)) |
109 | } | 123 | } |
110 | } | 124 | } |
@@ -51,7 +51,9 @@ func (controller *RoleController) ListForUserRole() { | @@ -51,7 +51,9 @@ func (controller *RoleController) ListForUserRole() { | ||
51 | if err := controller.Unmarshal(in); err != nil { | 51 | if err := controller.Unmarshal(in); err != nil { |
52 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 52 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
53 | } else { | 53 | } else { |
54 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 54 | + ua := middlewares.GetUser(controller.Ctx) |
55 | + in.CompanyId = ua.CompanyId | ||
56 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
55 | controller.Response(ruService.ListForUser(in)) | 57 | controller.Response(ruService.ListForUser(in)) |
56 | } | 58 | } |
57 | } | 59 | } |
@@ -18,7 +18,9 @@ func (controller *RoleUserController) CreateRoleUser() { | @@ -18,7 +18,9 @@ func (controller *RoleUserController) CreateRoleUser() { | ||
18 | if err := controller.Unmarshal(in); err != nil { | 18 | if err := controller.Unmarshal(in); err != nil { |
19 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 19 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
20 | } else { | 20 | } else { |
21 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 21 | + ua := middlewares.GetUser(controller.Ctx) |
22 | + in.CompanyId = ua.CompanyId | ||
23 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
22 | controller.Response(ruService.Create(in)) | 24 | controller.Response(ruService.Create(in)) |
23 | } | 25 | } |
24 | } | 26 | } |
@@ -29,7 +31,9 @@ func (controller *RoleUserController) RemoveRoleUser() { | @@ -29,7 +31,9 @@ func (controller *RoleUserController) RemoveRoleUser() { | ||
29 | if err := controller.Unmarshal(in); err != nil { | 31 | if err := controller.Unmarshal(in); err != nil { |
30 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 32 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
31 | } else { | 33 | } else { |
32 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 34 | + ua := middlewares.GetUser(controller.Ctx) |
35 | + in.CompanyId = ua.CompanyId | ||
36 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
33 | controller.Response(ruService.Remove(in)) | 37 | controller.Response(ruService.Remove(in)) |
34 | } | 38 | } |
35 | } | 39 | } |
@@ -40,7 +44,9 @@ func (controller *RoleUserController) ListRoleUser() { | @@ -40,7 +44,9 @@ func (controller *RoleUserController) ListRoleUser() { | ||
40 | if err := controller.Unmarshal(in); err != nil { | 44 | if err := controller.Unmarshal(in); err != nil { |
41 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) | 45 | controller.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error())) |
42 | } else { | 46 | } else { |
43 | - in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | 47 | + ua := middlewares.GetUser(controller.Ctx) |
48 | + in.CompanyId = ua.CompanyId | ||
49 | + //in.CompanyId = middlewares.GetCompanyId(controller.Ctx) | ||
44 | controller.Response(ruService.ListRole(in)) | 50 | controller.Response(ruService.ListRole(in)) |
45 | } | 51 | } |
46 | } | 52 | } |
@@ -6,6 +6,14 @@ import ( | @@ -6,6 +6,14 @@ import ( | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
7 | ) | 7 | ) |
8 | 8 | ||
9 | +func GetUser(ctx *context.Context) *domain.UserAuth { | ||
10 | + user := ctx.Input.GetData(domain.UserAuth{}) | ||
11 | + if user != nil { | ||
12 | + return user.(*domain.UserAuth) | ||
13 | + } | ||
14 | + return nil | ||
15 | +} | ||
16 | + | ||
9 | func CheckAdminToken() func(ctx *context.Context) { | 17 | func CheckAdminToken() func(ctx *context.Context) { |
10 | return func(ctx *context.Context) { | 18 | return func(ctx *context.Context) { |
11 | adminToken := ctx.Input.Header("x-admin-token") | 19 | adminToken := ctx.Input.Header("x-admin-token") |
1 | package middlewares | 1 | package middlewares |
2 | 2 | ||
3 | -import ( | ||
4 | - "github.com/beego/beego/v2/server/web/context" | ||
5 | -) | ||
6 | - | ||
7 | -func setUserId(userId int64, ctx *context.Context) { | ||
8 | - ctx.Input.SetData("_UserId", userId) | ||
9 | -} | ||
10 | - | ||
11 | -func GetUserId(ctx *context.Context) int64 { | ||
12 | - userId := ctx.Input.GetData("_UserId") | ||
13 | - return userId.(int64) | ||
14 | -} | ||
15 | - | ||
16 | -func setCompanyId(companyId int64, ctx *context.Context) { | ||
17 | - ctx.Input.SetData("_CompanyId", companyId) | ||
18 | -} | ||
19 | - | ||
20 | -func GetCompanyId(ctx *context.Context) int64 { | ||
21 | - companyId := ctx.Input.GetData("_CompanyId") | ||
22 | - return companyId.(int64) | ||
23 | -} | ||
24 | - | ||
25 | -func setCompanyType(companyId int, ctx *context.Context) { | ||
26 | - ctx.Input.SetData("_CompanyType", companyId) | ||
27 | -} | ||
28 | - | ||
29 | -func GetCompanyType(ctx *context.Context) int { | ||
30 | - companyId := ctx.Input.GetData("_CompanyType") | ||
31 | - return companyId.(int) | ||
32 | -} | ||
33 | - | ||
34 | -func invalidOrExpired(ctx *context.Context) { | ||
35 | - resp := map[string]interface{}{ | ||
36 | - "code": 902, | ||
37 | - "msg": "Authorization过期或无效,需要进行重新获取令牌", | ||
38 | - } | ||
39 | - _ = ctx.Output.JSON(resp, false, false) | ||
40 | -} | ||
41 | - | ||
42 | -func CheckToken() func(ctx *context.Context) { | ||
43 | - return func(ctx *context.Context) { | ||
44 | - tokenStr := ctx.Input.Header("x-mmm-accesstoken") | ||
45 | - if tokenStr == "" { //没有带token | ||
46 | - invalidOrExpired(ctx) | ||
47 | - return | ||
48 | - } | ||
49 | - | ||
50 | - //userServe := service.UserService{} | ||
51 | - //userTk, err := userServe.ValidLoginToken(tokenStr) | ||
52 | - //if err != nil { | ||
53 | - // invalidOrExpired(ctx) | ||
54 | - // return | ||
55 | - //} | ||
56 | - //setUserId(userTk.UserId, ctx) | ||
57 | - //setCompanyId(userTk.CompanyId, ctx) | ||
58 | - //setCompanyType(userTk.CompanyType, ctx) | ||
59 | - } | ||
60 | -} | 3 | +// |
4 | +//import ( | ||
5 | +// "github.com/beego/beego/v2/server/web/context" | ||
6 | +//) | ||
7 | +// | ||
8 | +//func setUserId(userId int64, ctx *context.Context) { | ||
9 | +// ctx.Input.SetData("_UserId", userId) | ||
10 | +//} | ||
11 | +// | ||
12 | +//func GetUserId(ctx *context.Context) int64 { | ||
13 | +// userId := ctx.Input.GetData("_UserId") | ||
14 | +// return userId.(int64) | ||
15 | +//} | ||
16 | +// | ||
17 | +//func setCompanyId(companyId int64, ctx *context.Context) { | ||
18 | +// ctx.Input.SetData("_CompanyId", companyId) | ||
19 | +//} | ||
20 | +// | ||
21 | +//func GetCompanyId(ctx *context.Context) int64 { | ||
22 | +// companyId := ctx.Input.GetData("_CompanyId") | ||
23 | +// return companyId.(int64) | ||
24 | +//} | ||
25 | +// | ||
26 | +//func setCompanyType(companyId int, ctx *context.Context) { | ||
27 | +// ctx.Input.SetData("_CompanyType", companyId) | ||
28 | +//} | ||
29 | +// | ||
30 | +//func GetCompanyType(ctx *context.Context) int { | ||
31 | +// companyId := ctx.Input.GetData("_CompanyType") | ||
32 | +// return companyId.(int) | ||
33 | +//} | ||
34 | +// | ||
35 | +//func invalidOrExpired(ctx *context.Context) { | ||
36 | +// resp := map[string]interface{}{ | ||
37 | +// "code": 902, | ||
38 | +// "msg": "Authorization过期或无效,需要进行重新获取令牌", | ||
39 | +// } | ||
40 | +// _ = ctx.Output.JSON(resp, false, false) | ||
41 | +//} | ||
42 | +// | ||
43 | +//func CheckToken() func(ctx *context.Context) { | ||
44 | +// return func(ctx *context.Context) { | ||
45 | +// tokenStr := ctx.Input.Header("x-mmm-accesstoken") | ||
46 | +// if tokenStr == "" { //没有带token | ||
47 | +// invalidOrExpired(ctx) | ||
48 | +// return | ||
49 | +// } | ||
50 | +// | ||
51 | +// //userServe := service.UserService{} | ||
52 | +// //userTk, err := userServe.ValidLoginToken(tokenStr) | ||
53 | +// //if err != nil { | ||
54 | +// // invalidOrExpired(ctx) | ||
55 | +// // return | ||
56 | +// //} | ||
57 | +// //setUserId(userTk.UserId, ctx) | ||
58 | +// //setCompanyId(userTk.CompanyId, ctx) | ||
59 | +// //setCompanyType(userTk.CompanyType, ctx) | ||
60 | +// } | ||
61 | +//} |
@@ -9,7 +9,7 @@ import ( | @@ -9,7 +9,7 @@ import ( | ||
9 | 9 | ||
10 | func init() { | 10 | func init() { |
11 | ns := web.NewNamespace("/v1/evaluation-rule", | 11 | ns := web.NewNamespace("/v1/evaluation-rule", |
12 | - web.NSBefore(filters.AllowCors(), middlewares.CheckToken()), | 12 | + web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()), |
13 | web.NSRouter("/", &controllers.RuleController{}, "Post:CreateRule"), | 13 | web.NSRouter("/", &controllers.RuleController{}, "Post:CreateRule"), |
14 | web.NSRouter("/", &controllers.RuleController{}, "Put:UpdateRule"), | 14 | web.NSRouter("/", &controllers.RuleController{}, "Put:UpdateRule"), |
15 | web.NSRouter("/", &controllers.RuleController{}, "Delete:RemoveRule"), | 15 | web.NSRouter("/", &controllers.RuleController{}, "Delete:RemoveRule"), |
@@ -9,7 +9,7 @@ import ( | @@ -9,7 +9,7 @@ import ( | ||
9 | 9 | ||
10 | func init() { | 10 | func init() { |
11 | ns := web.NewNamespace("/v1/evaluation-template", | 11 | ns := web.NewNamespace("/v1/evaluation-template", |
12 | - web.NSBefore(filters.AllowCors(), middlewares.CheckToken()), | 12 | + web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()), |
13 | web.NSRouter("/", &controllers.TemplateController{}, "Post:CreateTemplate"), | 13 | web.NSRouter("/", &controllers.TemplateController{}, "Post:CreateTemplate"), |
14 | web.NSRouter("/", &controllers.TemplateController{}, "Put:UpdateTemplate"), | 14 | web.NSRouter("/", &controllers.TemplateController{}, "Put:UpdateTemplate"), |
15 | web.NSRouter("/", &controllers.TemplateController{}, "Delete:RemoveTemplate"), | 15 | web.NSRouter("/", &controllers.TemplateController{}, "Delete:RemoveTemplate"), |
@@ -9,7 +9,7 @@ import ( | @@ -9,7 +9,7 @@ import ( | ||
9 | 9 | ||
10 | func init() { | 10 | func init() { |
11 | ns := web.NewNamespace("/v1/role", | 11 | ns := web.NewNamespace("/v1/role", |
12 | - web.NSBefore(filters.AllowCors(), middlewares.CheckToken()), | 12 | + web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()), |
13 | //web.NSRouter("/", &controllers.RoleController{}, "Post:CreateRole"), | 13 | //web.NSRouter("/", &controllers.RoleController{}, "Post:CreateRole"), |
14 | //web.NSRouter("/", &controllers.RoleController{}, "Put:UpdateRole"), | 14 | //web.NSRouter("/", &controllers.RoleController{}, "Put:UpdateRole"), |
15 | //web.NSRouter("/", &controllers.RoleController{}, "Delete:RemoveRole"), | 15 | //web.NSRouter("/", &controllers.RoleController{}, "Delete:RemoveRole"), |
@@ -9,7 +9,7 @@ import ( | @@ -9,7 +9,7 @@ import ( | ||
9 | 9 | ||
10 | func init() { | 10 | func init() { |
11 | ns := web.NewNamespace("/v1/role-user", | 11 | ns := web.NewNamespace("/v1/role-user", |
12 | - web.NSBefore(filters.AllowCors(), middlewares.CheckToken()), | 12 | + web.NSBefore(filters.AllowCors(), middlewares.CheckAdminToken()), |
13 | web.NSRouter("/", &controllers.RoleUserController{}, "Post:CreateRole"), | 13 | web.NSRouter("/", &controllers.RoleUserController{}, "Post:CreateRole"), |
14 | web.NSRouter("/", &controllers.RoleUserController{}, "Delete:RemoveRole"), | 14 | web.NSRouter("/", &controllers.RoleUserController{}, "Delete:RemoveRole"), |
15 | web.NSRouter("/all", &controllers.RoleUserController{}, "Post:ListRoleUser"), | 15 | web.NSRouter("/all", &controllers.RoleUserController{}, "Post:ListRoleUser"), |
-
请 注册 或 登录 后发表评论