正在显示
13 个修改的文件
包含
159 行增加
和
47 行删除
@@ -3,10 +3,12 @@ module gitlab.fjmaimaimai.com/mmm-go/godevp | @@ -3,10 +3,12 @@ module gitlab.fjmaimaimai.com/mmm-go/godevp | ||
3 | go 1.15 | 3 | go 1.15 |
4 | 4 | ||
5 | require ( | 5 | require ( |
6 | + github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 | ||
6 | github.com/astaxie/beego v1.12.2 | 7 | github.com/astaxie/beego v1.12.2 |
8 | + github.com/dgrijalva/jwt-go v3.2.0+incompatible | ||
7 | github.com/go-pg/pg/v10 v10.0.0-beta.2 | 9 | github.com/go-pg/pg/v10 v10.0.0-beta.2 |
8 | github.com/tiptok/gocomm v1.0.2 | 10 | github.com/tiptok/gocomm v1.0.2 |
9 | - github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 | 11 | + github.com/tal-tech/go-zero v1.0.11 |
10 | ) | 12 | ) |
11 | 13 | ||
12 | replace github.com/tiptok/gocomm v1.0.2 => F:\go\src\learn_project\gocomm | 14 | replace github.com/tiptok/gocomm v1.0.2 => F:\go\src\learn_project\gocomm |
@@ -56,7 +56,7 @@ func (svr *CacheService) ValidUserAccess(userId int64, object string, method str | @@ -56,7 +56,7 @@ func (svr *CacheService) ValidUserAccess(userId int64, object string, method str | ||
56 | }() | 56 | }() |
57 | cache.GetObject(UserRoleAccessCacheKey(userId), &userAccess, 3600, svr.CacheUserAccess(userId)) | 57 | cache.GetObject(UserRoleAccessCacheKey(userId), &userAccess, 3600, svr.CacheUserAccess(userId)) |
58 | for i := range userAccess { | 58 | for i := range userAccess { |
59 | - if KeyMatch3(object, userAccess[i].Object) && KeyEqual(userAccess[i].Action, method) { | 59 | + if KeyMatch3(object, userAccess[i].Object) && ActionEqual(userAccess[i].Action, method) { |
60 | result = true | 60 | result = true |
61 | return | 61 | return |
62 | } | 62 | } |
@@ -65,18 +65,20 @@ func (svr *CacheService) ValidUserAccess(userId int64, object string, method str | @@ -65,18 +65,20 @@ func (svr *CacheService) ValidUserAccess(userId int64, object string, method str | ||
65 | } | 65 | } |
66 | 66 | ||
67 | // KeyMatch3 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *. | 67 | // KeyMatch3 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *. |
68 | -// For example, "/foo/bar" matches "/foo/*", "/resource1" matches "/{resource}" | 68 | +// For example, "/foo/bar" matches "/foo/*", "/resource1" matches "/{resource}" ,"/foo" matches "/foo/*" |
69 | func KeyMatch3(key1 string, key2 string) bool { | 69 | func KeyMatch3(key1 string, key2 string) bool { |
70 | key2 = strings.Replace(key2, "/*", "/.*", -1) | 70 | key2 = strings.Replace(key2, "/*", "/.*", -1) |
71 | 71 | ||
72 | re := regexp.MustCompile(`\{[^/]+\}`) | 72 | re := regexp.MustCompile(`\{[^/]+\}`) |
73 | key2 = re.ReplaceAllString(key2, "$1[^/]+$2") | 73 | key2 = re.ReplaceAllString(key2, "$1[^/]+$2") |
74 | - | 74 | + if RegexMatch(key1+"/", "^"+key2+"$") { |
75 | + return true | ||
76 | + } | ||
75 | return RegexMatch(key1, "^"+key2+"$") | 77 | return RegexMatch(key1, "^"+key2+"$") |
76 | } | 78 | } |
77 | 79 | ||
78 | // KeyEqual case key1='*' or key1=' ' result=true | 80 | // KeyEqual case key1='*' or key1=' ' result=true |
79 | -func KeyEqual(key1 string, key2 string) bool { | 81 | +func ActionEqual(key1 string, key2 string) bool { |
80 | if key1 == "*" { | 82 | if key1 == "*" { |
81 | return true | 83 | return true |
82 | } | 84 | } |
1 | package project_module_version | 1 | package project_module_version |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
4 | "github.com/tiptok/gocomm/common" | 5 | "github.com/tiptok/gocomm/common" |
5 | "github.com/tiptok/gocomm/pkg/log" | 6 | "github.com/tiptok/gocomm/pkg/log" |
6 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" | 7 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory" |
7 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" |
9 | + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/dao" | ||
8 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" | 10 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol" |
9 | protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_version" | 11 | protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_version" |
12 | + "strings" | ||
10 | "time" | 13 | "time" |
11 | ) | 14 | ) |
12 | 15 | ||
@@ -20,6 +23,7 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto | @@ -20,6 +23,7 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto | ||
20 | rsp = &protocolx.CreateProjectModuleVersionResponse{} | 23 | rsp = &protocolx.CreateProjectModuleVersionResponse{} |
21 | if err = request.ValidateCommand(); err != nil { | 24 | if err = request.ValidateCommand(); err != nil { |
22 | err = protocol.NewCustomMessage(2, err.Error()) | 25 | err = protocol.NewCustomMessage(2, err.Error()) |
26 | + return | ||
23 | } | 27 | } |
24 | if err = transactionContext.StartTransaction(); err != nil { | 28 | if err = transactionContext.StartTransaction(); err != nil { |
25 | log.Error(err) | 29 | log.Error(err) |
@@ -29,18 +33,36 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto | @@ -29,18 +33,36 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto | ||
29 | transactionContext.RollbackTransaction() | 33 | transactionContext.RollbackTransaction() |
30 | }() | 34 | }() |
31 | newProjectModuleVersion := &domain.ProjectModuleVersion{ | 35 | newProjectModuleVersion := &domain.ProjectModuleVersion{ |
32 | - Version: request.Version, | 36 | + Version: strings.TrimSpace(request.Version), |
33 | Description: request.Description, | 37 | Description: request.Description, |
34 | - Status: request.Status, | 38 | + Status: 0, |
35 | CreateTime: time.Now(), | 39 | CreateTime: time.Now(), |
36 | UpdateTime: time.Now(), | 40 | UpdateTime: time.Now(), |
37 | } | 41 | } |
38 | 42 | ||
39 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) | 43 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) |
40 | - if m, err := ProjectModuleVersionRepository.Save(newProjectModuleVersion); err != nil { | ||
41 | - return nil, err | 44 | + var srcVersion, dstVersion *domain.ProjectModuleVersion |
45 | + var currentPMVersionId int64 | ||
46 | + if srcVersion, err = ProjectModuleVersionRepository.FindOne(map[string]interface{}{"id": request.CurrentProjectModuleVersionId}); err != nil { | ||
47 | + err = protocol.NewCustomMessage(1, fmt.Sprintf("当前版本不存在,请重试")) | ||
48 | + return | ||
49 | + } | ||
50 | + newProjectModuleVersion.ProjectModuleId = srcVersion.ProjectModuleId | ||
51 | + | ||
52 | + if _, e := ProjectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleId": srcVersion.ProjectModuleId, "version": strings.TrimSpace(request.Version)}); e == nil { | ||
53 | + err = protocol.NewCustomMessage(1, fmt.Sprintf("当前版本已存在:"+request.Version)) | ||
54 | + return | ||
55 | + } | ||
56 | + if dstVersion, err = ProjectModuleVersionRepository.Save(newProjectModuleVersion); err != nil { | ||
57 | + return | ||
42 | } else { | 58 | } else { |
43 | - rsp = m | 59 | + currentPMVersionId = dstVersion.Id |
60 | + rsp = dstVersion | ||
61 | + } | ||
62 | + | ||
63 | + var ProjectModuleDao, _ = dao.NewProjectModuleDao(transactionContext) | ||
64 | + if err = ProjectModuleDao.DuplicateVersion(srcVersion.ProjectModuleId, srcVersion.ProjectModuleId, currentPMVersionId); err != nil { | ||
65 | + return | ||
44 | } | 66 | } |
45 | err = transactionContext.CommitTransaction() | 67 | err = transactionContext.CommitTransaction() |
46 | return | 68 | return |
@@ -53,6 +75,7 @@ func (svr *ProjectModuleVersionService) UpdateProjectModuleVersion(header *proto | @@ -53,6 +75,7 @@ func (svr *ProjectModuleVersionService) UpdateProjectModuleVersion(header *proto | ||
53 | rsp = &protocolx.UpdateProjectModuleVersionResponse{} | 75 | rsp = &protocolx.UpdateProjectModuleVersionResponse{} |
54 | if err = request.ValidateCommand(); err != nil { | 76 | if err = request.ValidateCommand(); err != nil { |
55 | err = protocol.NewCustomMessage(2, err.Error()) | 77 | err = protocol.NewCustomMessage(2, err.Error()) |
78 | + return | ||
56 | } | 79 | } |
57 | if err = transactionContext.StartTransaction(); err != nil { | 80 | if err = transactionContext.StartTransaction(); err != nil { |
58 | log.Error(err) | 81 | log.Error(err) |
@@ -64,9 +87,17 @@ func (svr *ProjectModuleVersionService) UpdateProjectModuleVersion(header *proto | @@ -64,9 +87,17 @@ func (svr *ProjectModuleVersionService) UpdateProjectModuleVersion(header *proto | ||
64 | 87 | ||
65 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) | 88 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) |
66 | var projectModuleVersion *domain.ProjectModuleVersion | 89 | var projectModuleVersion *domain.ProjectModuleVersion |
67 | - if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil { | 90 | + if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(map[string]interface{}{"id": request.ProjectModuleVersionId}); err != nil { |
91 | + err = protocol.NewCustomMessage(1, "版本信息不存在") | ||
68 | return | 92 | return |
69 | } | 93 | } |
94 | + // 修改版本号 | ||
95 | + if len(request.Version) > 0 && projectModuleVersion.Version != request.Version { | ||
96 | + if _, err = ProjectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleId": projectModuleVersion.ProjectModuleId, "version": request.Version}); err == nil { | ||
97 | + err = protocol.NewCustomMessage(1, "版本信息已存在:"+request.Version) | ||
98 | + return | ||
99 | + } | ||
100 | + } | ||
70 | if err = projectModuleVersion.Update(common.ObjectToMap(request)); err != nil { | 101 | if err = projectModuleVersion.Update(common.ObjectToMap(request)); err != nil { |
71 | return | 102 | return |
72 | } | 103 | } |
@@ -84,6 +115,7 @@ func (svr *ProjectModuleVersionService) GetProjectModuleVersion(header *protocol | @@ -84,6 +115,7 @@ func (svr *ProjectModuleVersionService) GetProjectModuleVersion(header *protocol | ||
84 | rsp = &protocolx.GetProjectModuleVersionResponse{} | 115 | rsp = &protocolx.GetProjectModuleVersionResponse{} |
85 | if err = request.ValidateCommand(); err != nil { | 116 | if err = request.ValidateCommand(); err != nil { |
86 | err = protocol.NewCustomMessage(2, err.Error()) | 117 | err = protocol.NewCustomMessage(2, err.Error()) |
118 | + return | ||
87 | } | 119 | } |
88 | if err = transactionContext.StartTransaction(); err != nil { | 120 | if err = transactionContext.StartTransaction(); err != nil { |
89 | log.Error(err) | 121 | log.Error(err) |
@@ -96,6 +128,7 @@ func (svr *ProjectModuleVersionService) GetProjectModuleVersion(header *protocol | @@ -96,6 +128,7 @@ func (svr *ProjectModuleVersionService) GetProjectModuleVersion(header *protocol | ||
96 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) | 128 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) |
97 | var projectModuleVersion *domain.ProjectModuleVersion | 129 | var projectModuleVersion *domain.ProjectModuleVersion |
98 | if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil { | 130 | if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil { |
131 | + err = protocol.NewCustomMessage(1, "版本信息不存在") | ||
99 | return | 132 | return |
100 | } | 133 | } |
101 | rsp = projectModuleVersion | 134 | rsp = projectModuleVersion |
@@ -122,9 +155,15 @@ func (svr *ProjectModuleVersionService) DeleteProjectModuleVersion(header *proto | @@ -122,9 +155,15 @@ func (svr *ProjectModuleVersionService) DeleteProjectModuleVersion(header *proto | ||
122 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) | 155 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) |
123 | var projectModuleVersion *domain.ProjectModuleVersion | 156 | var projectModuleVersion *domain.ProjectModuleVersion |
124 | if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil { | 157 | if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil { |
158 | + err = protocol.NewCustomMessage(1, "版本信息不存在") | ||
159 | + return | ||
160 | + } | ||
161 | + if projectModuleVersion.Status == 1 { | ||
162 | + err = protocol.NewCustomMessage(1, "已删除") | ||
125 | return | 163 | return |
126 | } | 164 | } |
127 | - if projectModuleVersion, err = ProjectModuleVersionRepository.Remove(projectModuleVersion); err != nil { | 165 | + projectModuleVersion.SetStatusDelete() |
166 | + if projectModuleVersion, err = ProjectModuleVersionRepository.Save(projectModuleVersion); err != nil { | ||
128 | return | 167 | return |
129 | } | 168 | } |
130 | rsp = projectModuleVersion | 169 | rsp = projectModuleVersion |
@@ -151,7 +190,7 @@ func (svr *ProjectModuleVersionService) ListProjectModuleVersion(header *protoco | @@ -151,7 +190,7 @@ func (svr *ProjectModuleVersionService) ListProjectModuleVersion(header *protoco | ||
151 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) | 190 | var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext) |
152 | var projectModuleVersion []*domain.ProjectModuleVersion | 191 | var projectModuleVersion []*domain.ProjectModuleVersion |
153 | var total int64 | 192 | var total int64 |
154 | - if total, projectModuleVersion, err = ProjectModuleVersionRepository.Find(common.ObjectToMap(request)); err != nil { | 193 | + if total, projectModuleVersion, err = ProjectModuleVersionRepository.Find(map[string]interface{}{"projectModuleId": request.ProjectModuleId, "status": 0}); err != nil { |
155 | return | 194 | return |
156 | } | 195 | } |
157 | rsp = map[string]interface{}{ | 196 | rsp = map[string]interface{}{ |
@@ -35,5 +35,18 @@ func (m *ProjectModuleVersion) Identify() interface{} { | @@ -35,5 +35,18 @@ func (m *ProjectModuleVersion) Identify() interface{} { | ||
35 | } | 35 | } |
36 | 36 | ||
37 | func (m *ProjectModuleVersion) Update(data map[string]interface{}) error { | 37 | func (m *ProjectModuleVersion) Update(data map[string]interface{}) error { |
38 | + if version, ok := data["version"]; ok { | ||
39 | + m.Version = version.(string) | ||
40 | + } | ||
41 | + if description, ok := data["description"]; ok { | ||
42 | + m.Description = description.(string) | ||
43 | + } | ||
44 | + if status, ok := data["status"]; ok { | ||
45 | + m.Status = status.(int) | ||
46 | + } | ||
38 | return nil | 47 | return nil |
39 | } | 48 | } |
49 | + | ||
50 | +func (m *ProjectModuleVersion) SetStatusDelete() { | ||
51 | + m.Status = 1 | ||
52 | +} |
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type ProjectModuleDao struct { | ||
9 | + transactionContext *transaction.TransactionContext | ||
10 | +} | ||
11 | + | ||
12 | +func (dao *ProjectModuleDao) DuplicateVersion(srcProjectId, srcVersionId int64, curVersionId int64) error { | ||
13 | + tx := dao.transactionContext.PgTx | ||
14 | + _, err := tx.Exec(`insert into project_module_files(project_module_id,project_module_version_id,file_type,file_name,file_key,code_block,parent_id,sort,remark,create_time,update_time) | ||
15 | +select ?,?,file_type,file_name,file_key,code_block,parent_id,sort,remark,now(),now() from project_module_files where project_module_id=? and project_module_version_id=?`, | ||
16 | + srcProjectId, curVersionId, srcProjectId, srcVersionId) | ||
17 | + return err | ||
18 | +} | ||
19 | + | ||
20 | +func NewProjectModuleDao(transactionContext *transaction.TransactionContext) (*ProjectModuleDao, error) { | ||
21 | + if transactionContext == nil { | ||
22 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
23 | + } else { | ||
24 | + return &ProjectModuleDao{ | ||
25 | + transactionContext: transactionContext, | ||
26 | + }, nil | ||
27 | + } | ||
28 | +} |
@@ -2,6 +2,7 @@ package repository | @@ -2,6 +2,7 @@ package repository | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/go-pg/pg/v10/orm" | ||
5 | "github.com/tiptok/gocomm/common" | 6 | "github.com/tiptok/gocomm/common" |
6 | . "github.com/tiptok/gocomm/pkg/orm/pgx" | 7 | . "github.com/tiptok/gocomm/pkg/orm/pgx" |
7 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" |
@@ -49,7 +50,10 @@ func (repository *ProjectModuleRepository) Remove(ProjectModule *domain.ProjectM | @@ -49,7 +50,10 @@ func (repository *ProjectModuleRepository) Remove(ProjectModule *domain.ProjectM | ||
49 | func (repository *ProjectModuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModule, error) { | 50 | func (repository *ProjectModuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModule, error) { |
50 | tx := repository.transactionContext.PgTx | 51 | tx := repository.transactionContext.PgTx |
51 | ProjectModuleModel := new(models.ProjectModule) | 52 | ProjectModuleModel := new(models.ProjectModule) |
52 | - query := NewQuery(tx.Model(ProjectModuleModel).Relation("ProjectModuleVersion"), queryOptions) | 53 | + query := NewQuery(tx.Model(ProjectModuleModel).Relation("ProjectModuleVersion", func(q *orm.Query) (*orm.Query, error) { |
54 | + q.Where("status=0") | ||
55 | + return q, nil | ||
56 | + }), queryOptions) | ||
53 | query.SetWhere("id = ?", "id") | 57 | query.SetWhere("id = ?", "id") |
54 | query.SetWhere("project_key = ?", "projectKey") | 58 | query.SetWhere("project_key = ?", "projectKey") |
55 | if err := query.First(); err != nil { | 59 | if err := query.First(); err != nil { |
@@ -65,7 +69,10 @@ func (repository *ProjectModuleRepository) Find(queryOptions map[string]interfac | @@ -65,7 +69,10 @@ func (repository *ProjectModuleRepository) Find(queryOptions map[string]interfac | ||
65 | tx := repository.transactionContext.PgTx | 69 | tx := repository.transactionContext.PgTx |
66 | var ProjectModuleModels []*models.ProjectModule | 70 | var ProjectModuleModels []*models.ProjectModule |
67 | ProjectModules := make([]*domain.ProjectModule, 0) | 71 | ProjectModules := make([]*domain.ProjectModule, 0) |
68 | - query := NewQuery(tx.Model(&ProjectModuleModels).Relation("ProjectModuleVersion"), queryOptions). | 72 | + query := NewQuery(tx.Model(&ProjectModuleModels).Relation("ProjectModuleVersion", func(q *orm.Query) (*orm.Query, error) { |
73 | + q.Where("status=0") | ||
74 | + return q, nil | ||
75 | + }), queryOptions). | ||
69 | SetOrder("create_time", "sortByCreateTime"). | 76 | SetOrder("create_time", "sortByCreateTime"). |
70 | SetOrder("update_time", "sortByUpdateTime") | 77 | SetOrder("update_time", "sortByUpdateTime") |
71 | var err error | 78 | var err error |
@@ -2,13 +2,23 @@ package repository | @@ -2,13 +2,23 @@ package repository | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + //"github.com/tal-tech/go-zero/core/stringx" | ||
5 | "github.com/tiptok/gocomm/common" | 6 | "github.com/tiptok/gocomm/common" |
6 | . "github.com/tiptok/gocomm/pkg/orm/pgx" | 7 | . "github.com/tiptok/gocomm/pkg/orm/pgx" |
7 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain" |
8 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models" | 9 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/models" |
9 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction" | 10 | "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg/transaction" |
11 | + //"github.com/tal-tech/go-zero/tools/goctl/model/sql/builderx" | ||
12 | + //"strings" | ||
10 | ) | 13 | ) |
11 | 14 | ||
15 | +//var ( | ||
16 | +// fieldNames = builderx.FieldNames(&models.ProjectModuleVersion{}) | ||
17 | +// rows = strings.Join(fieldNames, ",") | ||
18 | +// rowsExpectAutoSet = strings.Join(stringx.Remove(fieldNames, "id","create_time", "update_time"), ",") | ||
19 | +// rowsWithPlaceHolder = strings.Join(stringx.Remove(fieldNames, "id","project_module_id","create_time", "update_time"), "=?,") + "=?" | ||
20 | +//) | ||
21 | + | ||
12 | type ProjectModuleVersionRepository struct { | 22 | type ProjectModuleVersionRepository struct { |
13 | transactionContext *transaction.TransactionContext | 23 | transactionContext *transaction.TransactionContext |
14 | } | 24 | } |
@@ -29,7 +39,7 @@ func (repository *ProjectModuleVersionRepository) Save(dm *domain.ProjectModuleV | @@ -29,7 +39,7 @@ func (repository *ProjectModuleVersionRepository) Save(dm *domain.ProjectModuleV | ||
29 | dm.Id = m.Id | 39 | dm.Id = m.Id |
30 | return dm, nil | 40 | return dm, nil |
31 | } | 41 | } |
32 | - if err = tx.Update(m); err != nil { | 42 | + if _, err = tx.Exec(`update project_module_version set version=?,description=?,status=?,update_time=? where id = ?`, m.Version, m.Description, m.Status, m.UpdateTime, m.Id); err != nil { |
33 | return nil, err | 43 | return nil, err |
34 | } | 44 | } |
35 | return dm, nil | 45 | return dm, nil |
@@ -51,6 +61,8 @@ func (repository *ProjectModuleVersionRepository) FindOne(queryOptions map[strin | @@ -51,6 +61,8 @@ func (repository *ProjectModuleVersionRepository) FindOne(queryOptions map[strin | ||
51 | ProjectModuleVersionModel := new(models.ProjectModuleVersion) | 61 | ProjectModuleVersionModel := new(models.ProjectModuleVersion) |
52 | query := NewQuery(tx.Model(ProjectModuleVersionModel), queryOptions) | 62 | query := NewQuery(tx.Model(ProjectModuleVersionModel), queryOptions) |
53 | query.SetWhere("id = ?", "id") | 63 | query.SetWhere("id = ?", "id") |
64 | + query.SetWhere("project_module_id = ?", "projectModuleId") | ||
65 | + query.SetWhere("version = ?", "version") | ||
54 | if err := query.First(); err != nil { | 66 | if err := query.First(); err != nil { |
55 | return nil, fmt.Errorf("query row not found") | 67 | return nil, fmt.Errorf("query row not found") |
56 | } | 68 | } |
@@ -65,6 +77,8 @@ func (repository *ProjectModuleVersionRepository) Find(queryOptions map[string]i | @@ -65,6 +77,8 @@ func (repository *ProjectModuleVersionRepository) Find(queryOptions map[string]i | ||
65 | var ProjectModuleVersionModels []*models.ProjectModuleVersion | 77 | var ProjectModuleVersionModels []*models.ProjectModuleVersion |
66 | ProjectModuleVersions := make([]*domain.ProjectModuleVersion, 0) | 78 | ProjectModuleVersions := make([]*domain.ProjectModuleVersion, 0) |
67 | query := NewQuery(tx.Model(&ProjectModuleVersionModels), queryOptions). | 79 | query := NewQuery(tx.Model(&ProjectModuleVersionModels), queryOptions). |
80 | + SetWhere("status=?", "status"). | ||
81 | + SetWhere("project_module_id=?", "projectModuleId"). | ||
68 | SetOrder("create_time", "sortByCreateTime"). | 82 | SetOrder("create_time", "sortByCreateTime"). |
69 | SetOrder("update_time", "sortByUpdateTime") | 83 | SetOrder("update_time", "sortByUpdateTime") |
70 | var err error | 84 | var err error |
@@ -16,9 +16,10 @@ func init() { | @@ -16,9 +16,10 @@ func init() { | ||
16 | AllowCredentials: true, | 16 | AllowCredentials: true, |
17 | })) | 17 | })) |
18 | 18 | ||
19 | - beego.InsertFilter("/user/*", beego.BeforeExec, middleware.InspectRoleAccess()) | ||
20 | - beego.InsertFilter("/role/*", beego.BeforeExec, middleware.InspectRoleAccess()) | ||
21 | - beego.InsertFilter("/project_module/*", beego.BeforeExec, middleware.CheckAuthorization) | ||
22 | - beego.InsertFilter("/project_module_files/*", beego.BeforeExec, middleware.CheckAuthorization) | ||
23 | - beego.InsertFilter("/rbac/*", beego.BeforeExec, middleware.CheckAuthorization) | 19 | + beego.InsertFilter("/user/*", beego.BeforeExec, middleware.InspectRoleAccess("")) |
20 | + beego.InsertFilter("/role/*", beego.BeforeExec, middleware.InspectRoleAccess("")) | ||
21 | + beego.InsertFilter("/project_module/*", beego.BeforeExec, middleware.InspectRoleAccess("")) | ||
22 | + beego.InsertFilter("/project_module_version/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*")) | ||
23 | + beego.InsertFilter("/project_module_files/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*")) | ||
24 | + beego.InsertFilter("/rbac/*", beego.BeforeExec, middleware.InspectRoleAccess("/role/*")) | ||
24 | } | 25 | } |
@@ -49,6 +49,7 @@ func (this *ProjectModuleVersionController) UpdateProjectModuleVersion() { | @@ -49,6 +49,7 @@ func (this *ProjectModuleVersionController) UpdateProjectModuleVersion() { | ||
49 | msg = protocol.BadRequestParam(1) | 49 | msg = protocol.BadRequestParam(1) |
50 | return | 50 | return |
51 | } | 51 | } |
52 | + request.ProjectModuleVersionId, _ = this.GetInt64(":projectModuleVersionId") | ||
52 | header := this.GetRequestHeader(this.Ctx) | 53 | header := this.GetRequestHeader(this.Ctx) |
53 | data, err := svr.UpdateProjectModuleVersion(header, request) | 54 | data, err := svr.UpdateProjectModuleVersion(header, request) |
54 | if err != nil { | 55 | if err != nil { |
@@ -63,15 +64,12 @@ func (this *ProjectModuleVersionController) GetProjectModuleVersion() { | @@ -63,15 +64,12 @@ func (this *ProjectModuleVersionController) GetProjectModuleVersion() { | ||
63 | var ( | 64 | var ( |
64 | msg *protocol.ResponseMessage | 65 | msg *protocol.ResponseMessage |
65 | svr = project_module_version.NewProjectModuleVersionService(nil) | 66 | svr = project_module_version.NewProjectModuleVersionService(nil) |
66 | - request *protocolx.GetProjectModuleVersionRequest | 67 | + request = &protocolx.GetProjectModuleVersionRequest{} |
67 | ) | 68 | ) |
68 | defer func() { | 69 | defer func() { |
69 | this.Resp(msg) | 70 | this.Resp(msg) |
70 | }() | 71 | }() |
71 | - if err := this.JsonUnmarshal(&request); err != nil { | ||
72 | - msg = protocol.BadRequestParam(1) | ||
73 | - return | ||
74 | - } | 72 | + request.Id, _ = this.GetInt64(":projectModuleVersionId") |
75 | header := this.GetRequestHeader(this.Ctx) | 73 | header := this.GetRequestHeader(this.Ctx) |
76 | data, err := svr.GetProjectModuleVersion(header, request) | 74 | data, err := svr.GetProjectModuleVersion(header, request) |
77 | if err != nil { | 75 | if err != nil { |
@@ -86,15 +84,12 @@ func (this *ProjectModuleVersionController) DeleteProjectModuleVersion() { | @@ -86,15 +84,12 @@ func (this *ProjectModuleVersionController) DeleteProjectModuleVersion() { | ||
86 | var ( | 84 | var ( |
87 | msg *protocol.ResponseMessage | 85 | msg *protocol.ResponseMessage |
88 | svr = project_module_version.NewProjectModuleVersionService(nil) | 86 | svr = project_module_version.NewProjectModuleVersionService(nil) |
89 | - request *protocolx.DeleteProjectModuleVersionRequest | 87 | + request = &protocolx.DeleteProjectModuleVersionRequest{} |
90 | ) | 88 | ) |
91 | defer func() { | 89 | defer func() { |
92 | this.Resp(msg) | 90 | this.Resp(msg) |
93 | }() | 91 | }() |
94 | - if err := this.JsonUnmarshal(&request); err != nil { | ||
95 | - msg = protocol.BadRequestParam(1) | ||
96 | - return | ||
97 | - } | 92 | + request.Id, _ = this.GetInt64(":projectModuleVersionId") |
98 | header := this.GetRequestHeader(this.Ctx) | 93 | header := this.GetRequestHeader(this.Ctx) |
99 | data, err := svr.DeleteProjectModuleVersion(header, request) | 94 | data, err := svr.DeleteProjectModuleVersion(header, request) |
100 | if err != nil { | 95 | if err != nil { |
@@ -109,15 +104,12 @@ func (this *ProjectModuleVersionController) ListProjectModuleVersion() { | @@ -109,15 +104,12 @@ func (this *ProjectModuleVersionController) ListProjectModuleVersion() { | ||
109 | var ( | 104 | var ( |
110 | msg *protocol.ResponseMessage | 105 | msg *protocol.ResponseMessage |
111 | svr = project_module_version.NewProjectModuleVersionService(nil) | 106 | svr = project_module_version.NewProjectModuleVersionService(nil) |
112 | - request *protocolx.ListProjectModuleVersionRequest | 107 | + request = &protocolx.ListProjectModuleVersionRequest{} |
113 | ) | 108 | ) |
114 | defer func() { | 109 | defer func() { |
115 | this.Resp(msg) | 110 | this.Resp(msg) |
116 | }() | 111 | }() |
117 | - if err := this.JsonUnmarshal(&request); err != nil { | ||
118 | - msg = protocol.BadRequestParam(1) | ||
119 | - return | ||
120 | - } | 112 | + request.ProjectModuleId, _ = this.GetInt64("projectModuleId") |
121 | header := this.GetRequestHeader(this.Ctx) | 113 | header := this.GetRequestHeader(this.Ctx) |
122 | data, err := svr.ListProjectModuleVersion(header, request) | 114 | data, err := svr.ListProjectModuleVersion(header, request) |
123 | if err != nil { | 115 | if err != nil { |
@@ -46,7 +46,7 @@ func CheckAuthorization(ctx *context.Context) { | @@ -46,7 +46,7 @@ func CheckAuthorization(ctx *context.Context) { | ||
46 | return | 46 | return |
47 | } | 47 | } |
48 | 48 | ||
49 | -func CheckRoleAccess(ctx *context.Context) { | 49 | +func CheckRoleAccess(ctx *context.Context, object, method string) { |
50 | var ( | 50 | var ( |
51 | msg *protocol.ResponseMessage | 51 | msg *protocol.ResponseMessage |
52 | ) | 52 | ) |
@@ -56,26 +56,39 @@ func CheckRoleAccess(ctx *context.Context) { | @@ -56,26 +56,39 @@ func CheckRoleAccess(ctx *context.Context) { | ||
56 | } | 56 | } |
57 | }() | 57 | }() |
58 | userId := ctx.Input.GetData("x-mmm-id") | 58 | userId := ctx.Input.GetData("x-mmm-id") |
59 | - | 59 | + if userId == nil { |
60 | + msg = protocol.NewResponseMessage(1, errAuthorization.Error()) | ||
61 | + return | ||
62 | + } | ||
60 | validUserRole := cachex.CacheService{} | 63 | validUserRole := cachex.CacheService{} |
61 | - if ok, _ := validUserRole.ValidUserAccess(int64(userId.(int)), ctx.Input.URL(), ctx.Input.Method()); !ok { | 64 | + if ok, _ := validUserRole.ValidUserAccess(int64(userId.(int)), object, method); !ok { |
62 | msg = protocol.NewResponseMessage(1, errAuthorization.Error()) | 65 | msg = protocol.NewResponseMessage(1, errAuthorization.Error()) |
63 | return | 66 | return |
64 | } | 67 | } |
65 | return | 68 | return |
66 | } | 69 | } |
67 | 70 | ||
68 | -func InspectRoleAccess(skipUrl ...string) func(*context.Context) { | 71 | +func InspectRoleAccess(parentObject string, skipUrl ...string) func(*context.Context) { |
69 | return func(c *context.Context) { | 72 | return func(c *context.Context) { |
73 | + var validParentPermision bool | ||
70 | if len(skipUrl) > 0 { | 74 | if len(skipUrl) > 0 { |
71 | requestUrl := c.Input.URL() | 75 | requestUrl := c.Input.URL() |
72 | for _, url := range skipUrl { | 76 | for _, url := range skipUrl { |
73 | - if strings.EqualFold(requestUrl, url) { | ||
74 | - return | 77 | + if cachex.KeyMatch3(requestUrl, url) { |
78 | + validParentPermision = true | ||
79 | + break | ||
75 | } | 80 | } |
76 | } | 81 | } |
77 | } | 82 | } |
83 | + // 跳过这个路由底下所有接口,使用父模块权限验证 | ||
84 | + if len(parentObject) > 0 && len(skipUrl) == 0 { | ||
85 | + validParentPermision = true | ||
86 | + } | ||
78 | CheckAuthorization(c) | 87 | CheckAuthorization(c) |
79 | - CheckRoleAccess(c) | 88 | + if validParentPermision { |
89 | + CheckRoleAccess(c, parentObject, c.Input.Method()) | ||
90 | + return | ||
91 | + } | ||
92 | + CheckRoleAccess(c, c.Input.URL(), c.Input.Method()) | ||
80 | } | 93 | } |
81 | } | 94 | } |
@@ -7,13 +7,11 @@ import ( | @@ -7,13 +7,11 @@ import ( | ||
7 | 7 | ||
8 | type CreateProjectModuleVersionRequest struct { | 8 | type CreateProjectModuleVersionRequest struct { |
9 | // 当前版本编号 | 9 | // 当前版本编号 |
10 | - CurrentVersionId int64 `json:"currentVersionId" valid:"Required"` | 10 | + CurrentProjectModuleVersionId int64 `json:"currentProjectModuleVersionId" valid:"Required"` |
11 | // 版本号 | 11 | // 版本号 |
12 | Version string `json:"version,omitempty" valid:"Required"` | 12 | Version string `json:"version,omitempty" valid:"Required"` |
13 | - // 项目描述信息 | 13 | + // 版本描述 |
14 | Description string `json:"description,omitempty"` | 14 | Description string `json:"description,omitempty"` |
15 | - // 状态 0:正常 1:删除 | ||
16 | - Status int `json:"status,omitempty"` | ||
17 | } | 15 | } |
18 | 16 | ||
19 | func (CreateProjectModuleVersionRequest *CreateProjectModuleVersionRequest) ValidateCommand() error { | 17 | func (CreateProjectModuleVersionRequest *CreateProjectModuleVersionRequest) ValidateCommand() error { |
@@ -6,6 +6,8 @@ import ( | @@ -6,6 +6,8 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | type UpdateProjectModuleVersionRequest struct { | 8 | type UpdateProjectModuleVersionRequest struct { |
9 | + // 项目版本编号 | ||
10 | + ProjectModuleVersionId int64 `json:"projectModuleVersionId" valid:"Required"` | ||
9 | // 版本号 | 11 | // 版本号 |
10 | Version string `json:"version,omitempty"` | 12 | Version string `json:"version,omitempty"` |
11 | // 项目描述信息 | 13 | // 项目描述信息 |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | type ListProjectModuleVersionRequest struct { | 8 | type ListProjectModuleVersionRequest struct { |
9 | + ProjectModuleId int64 `json:"projectModuleId" valid:"Required"` | ||
9 | } | 10 | } |
10 | 11 | ||
11 | func (ListProjectModuleVersionRequest *ListProjectModuleVersionRequest) ValidateCommand() error { | 12 | func (ListProjectModuleVersionRequest *ListProjectModuleVersionRequest) ValidateCommand() error { |
-
请 注册 或 登录 后发表评论