diff --git a/internal/logic/user.go b/internal/logic/user.go index 70bff08..cba09d3 100644 --- a/internal/logic/user.go +++ b/internal/logic/user.go @@ -14,9 +14,10 @@ import ( ) type User struct { - db *gorm.DB - cache cache.Cache - sqlDependency *dbcache.SqlDependency + db *gorm.DB + cache cache.Cache + sqlDependency *dbcache.SqlDependency + roleDependency *dbcache.SqlDependency } // GetPermissions 获取用户权限 @@ -30,7 +31,8 @@ func (u *User) GetPermissions(ctx context.Context, uid string) (permissions []st Error return ss, err }, - dbcache.WithCacheDuration(time.Minute), + dbcache.WithDependency(u.roleDependency), + dbcache.WithCacheDuration(time.Second*20), dbcache.WithDB(u.db), dbcache.WithCache(u.cache), ) @@ -65,8 +67,9 @@ func (u *User) GeUsers(ctx context.Context) (values []*models.User, err error) { func NewUserLogic(db *gorm.DB, ch cache.Cache) *User { return &User{ - db: db, - cache: ch, - sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM `users`"), + db: db, + cache: ch, + roleDependency: dbcache.NewSqlDependency("SELECT COUNT(*) AS count FROM `role_permissions`"), + sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM `users`"), } } diff --git a/migrate/default.go b/migrate/default.go index fccc0c3..1a74b4f 100644 --- a/migrate/default.go +++ b/migrate/default.go @@ -48,6 +48,7 @@ func init() { orgMenu.Name = "Organize" orgMenu.Public = true orgMenu.Uri = "/organize" + orgMenu.Position = 1 profileMenu := &models.Menu{} profileMenu.Label = "个人信息" @@ -64,6 +65,7 @@ func init() { settingMenu.Name = "System" settingMenu.Public = true settingMenu.Uri = "/system" + settingMenu.Position = 999 schemaMenu := &models.Menu{} schemaMenu.Label = "字段设置" diff --git a/models/model.go b/models/model.go index 949a5f3..6d3f089 100644 --- a/models/model.go +++ b/models/model.go @@ -1,9 +1,12 @@ package models import ( + "errors" + "git.nobla.cn/golang/aeus-admin/pb" "git.nobla.cn/golang/aeus-admin/types" restTypes "git.nobla.cn/golang/rest/types" + "gorm.io/gorm" ) type ( @@ -53,7 +56,7 @@ func (m *Login) GetMenu() *types.Menu { } func (m *Login) Scenario() []string { - return []string{restTypes.ScenarioList} + return []string{restTypes.ScenarioList, restTypes.ScenarioExport} } func (m *Menu) GetMenu() *types.Menu { @@ -63,6 +66,17 @@ func (m *Menu) GetMenu() *types.Menu { } } +func (m *Menu) BeforeDelete(tx *gorm.DB) (err error) { + var count int64 + if err = tx.Model(&Menu{}).Where("`parent` = ?", m.Name).Count(&count).Error; err != nil { + return + } + if count > 0 { + err = errors.New("please delete sub menus first") + } + return +} + func (m *Menu) ModelPermissions() map[string]string { return map[string]string{ "organize:permission:list": "权限", @@ -76,6 +90,23 @@ func (m *Department) GetMenu() *types.Menu { } } +func (m *Department) BeforeDelete(tx *gorm.DB) (err error) { + var count int64 + if err = tx.Model(&Department{}).Where("`parent_id` = ?", m.Id).Count(&count).Error; err != nil { + return + } + if count > 0 { + return errors.New("please delete sub department first") + } + if err = tx.Model(&User{}).Where("`dept_id` = ?", m.Id).Count(&count).Error; err != nil { + return + } + if count > 0 { + err = errors.New("please delete user first") + } + return +} + func (m *Role) GetMenu() *types.Menu { return &types.Menu{ Name: "OrganizeRole", @@ -89,6 +120,17 @@ func (m *Role) ModelPermissions() map[string]string { } } +func (m *Role) BeforeDelete(tx *gorm.DB) (err error) { + var count int64 + if err = tx.Model(&User{}).Where("`role` = ?", m.Name).Count(&count).Error; err != nil { + return + } + if count > 0 { + err = errors.New("please delete user first") + } + return +} + func (m *Permission) GetMenu() *types.Menu { return &types.Menu{ Name: "OrganizePermission", @@ -136,7 +178,7 @@ func (m *Activity) GetMenu() *types.Menu { } func (m *Activity) Scenario() []string { - return []string{restTypes.ScenarioList} + return []string{restTypes.ScenarioList, restTypes.ScenarioExport} } func (m *Activity) ModuleName() string { diff --git a/pb/organize.pb.go b/pb/organize.pb.go index 21ef0a1..c50c700 100644 --- a/pb/organize.pb.go +++ b/pb/organize.pb.go @@ -961,27 +961,27 @@ func (x *MenuItem) GetChildren() []*MenuItem { } // 获取菜单的请求 -type GetMenuRequest struct { +type GetUserMenuRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Permission bool `protobuf:"varint,1,opt,name=permission,proto3" json:"permission,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *GetMenuRequest) Reset() { - *x = GetMenuRequest{} +func (x *GetUserMenuRequest) Reset() { + *x = GetUserMenuRequest{} mi := &file_organize_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *GetMenuRequest) String() string { +func (x *GetUserMenuRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*GetMenuRequest) ProtoMessage() {} +func (*GetUserMenuRequest) ProtoMessage() {} -func (x *GetMenuRequest) ProtoReflect() protoreflect.Message { +func (x *GetUserMenuRequest) ProtoReflect() protoreflect.Message { mi := &file_organize_proto_msgTypes[10] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -993,12 +993,12 @@ func (x *GetMenuRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use GetMenuRequest.ProtoReflect.Descriptor instead. -func (*GetMenuRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use GetUserMenuRequest.ProtoReflect.Descriptor instead. +func (*GetUserMenuRequest) Descriptor() ([]byte, []int) { return file_organize_proto_rawDescGZIP(), []int{10} } -func (x *GetMenuRequest) GetPermission() bool { +func (x *GetUserMenuRequest) GetPermission() bool { if x != nil { return x.Permission } @@ -1006,27 +1006,27 @@ func (x *GetMenuRequest) GetPermission() bool { } // 获取菜单的响应 -type GetMenuResponse struct { +type GetUserMenuResponse struct { state protoimpl.MessageState `protogen:"open.v1"` Data []*MenuItem `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *GetMenuResponse) Reset() { - *x = GetMenuResponse{} +func (x *GetUserMenuResponse) Reset() { + *x = GetUserMenuResponse{} mi := &file_organize_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *GetMenuResponse) String() string { +func (x *GetUserMenuResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*GetMenuResponse) ProtoMessage() {} +func (*GetUserMenuResponse) ProtoMessage() {} -func (x *GetMenuResponse) ProtoReflect() protoreflect.Message { +func (x *GetUserMenuResponse) ProtoReflect() protoreflect.Message { mi := &file_organize_proto_msgTypes[11] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -1038,12 +1038,12 @@ func (x *GetMenuResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use GetMenuResponse.ProtoReflect.Descriptor instead. -func (*GetMenuResponse) Descriptor() ([]byte, []int) { +// Deprecated: Use GetUserMenuResponse.ProtoReflect.Descriptor instead. +func (*GetUserMenuResponse) Descriptor() ([]byte, []int) { return file_organize_proto_rawDescGZIP(), []int{11} } -func (x *GetMenuResponse) GetData() []*MenuItem { +func (x *GetUserMenuResponse) GetData() []*MenuItem { if x != nil { return x.Data } @@ -2500,6 +2500,162 @@ func (x *GetMenuLevelLabelsResponse) GetData() []*MenuLevelValue { return nil } +type MenuValue struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Parent string `protobuf:"bytes,2,opt,name=parent,proto3" json:"parent,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` + Label string `protobuf:"bytes,4,opt,name=label,proto3" json:"label,omitempty"` + Children []*MenuValue `protobuf:"bytes,5,rep,name=children,proto3" json:"children,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MenuValue) Reset() { + *x = MenuValue{} + mi := &file_organize_proto_msgTypes[42] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MenuValue) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MenuValue) ProtoMessage() {} + +func (x *MenuValue) ProtoReflect() protoreflect.Message { + mi := &file_organize_proto_msgTypes[42] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MenuValue.ProtoReflect.Descriptor instead. +func (*MenuValue) Descriptor() ([]byte, []int) { + return file_organize_proto_rawDescGZIP(), []int{42} +} + +func (x *MenuValue) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *MenuValue) GetParent() string { + if x != nil { + return x.Parent + } + return "" +} + +func (x *MenuValue) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *MenuValue) GetLabel() string { + if x != nil { + return x.Label + } + return "" +} + +func (x *MenuValue) GetChildren() []*MenuValue { + if x != nil { + return x.Children + } + return nil +} + +type GetMenuRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetMenuRequest) Reset() { + *x = GetMenuRequest{} + mi := &file_organize_proto_msgTypes[43] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetMenuRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMenuRequest) ProtoMessage() {} + +func (x *GetMenuRequest) ProtoReflect() protoreflect.Message { + mi := &file_organize_proto_msgTypes[43] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetMenuRequest.ProtoReflect.Descriptor instead. +func (*GetMenuRequest) Descriptor() ([]byte, []int) { + return file_organize_proto_rawDescGZIP(), []int{43} +} + +type GetMenuResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Data []*MenuValue `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetMenuResponse) Reset() { + *x = GetMenuResponse{} + mi := &file_organize_proto_msgTypes[44] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetMenuResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetMenuResponse) ProtoMessage() {} + +func (x *GetMenuResponse) ProtoReflect() protoreflect.Message { + mi := &file_organize_proto_msgTypes[44] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetMenuResponse.ProtoReflect.Descriptor instead. +func (*GetMenuResponse) Descriptor() ([]byte, []int) { + return file_organize_proto_rawDescGZIP(), []int{44} +} + +func (x *GetMenuResponse) GetData() []*MenuValue { + if x != nil { + return x.Data + } + return nil +} + type LoginRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` @@ -2511,7 +2667,7 @@ type LoginRequest struct { func (x *LoginRequest) Reset() { *x = LoginRequest{} - mi := &file_organize_proto_msgTypes[42] + mi := &file_organize_proto_msgTypes[45] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2523,7 +2679,7 @@ func (x *LoginRequest) String() string { func (*LoginRequest) ProtoMessage() {} func (x *LoginRequest) ProtoReflect() protoreflect.Message { - mi := &file_organize_proto_msgTypes[42] + mi := &file_organize_proto_msgTypes[45] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2536,7 +2692,7 @@ func (x *LoginRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use LoginRequest.ProtoReflect.Descriptor instead. func (*LoginRequest) Descriptor() ([]byte, []int) { - return file_organize_proto_rawDescGZIP(), []int{42} + return file_organize_proto_rawDescGZIP(), []int{45} } func (x *LoginRequest) GetUsername() string { @@ -2572,7 +2728,7 @@ type LoginResponse struct { func (x *LoginResponse) Reset() { *x = LoginResponse{} - mi := &file_organize_proto_msgTypes[43] + mi := &file_organize_proto_msgTypes[46] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2584,7 +2740,7 @@ func (x *LoginResponse) String() string { func (*LoginResponse) ProtoMessage() {} func (x *LoginResponse) ProtoReflect() protoreflect.Message { - mi := &file_organize_proto_msgTypes[43] + mi := &file_organize_proto_msgTypes[46] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2597,7 +2753,7 @@ func (x *LoginResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use LoginResponse.ProtoReflect.Descriptor instead. func (*LoginResponse) Descriptor() ([]byte, []int) { - return file_organize_proto_rawDescGZIP(), []int{43} + return file_organize_proto_rawDescGZIP(), []int{46} } func (x *LoginResponse) GetUid() string { @@ -2637,7 +2793,7 @@ type LogoutRequest struct { func (x *LogoutRequest) Reset() { *x = LogoutRequest{} - mi := &file_organize_proto_msgTypes[44] + mi := &file_organize_proto_msgTypes[47] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2649,7 +2805,7 @@ func (x *LogoutRequest) String() string { func (*LogoutRequest) ProtoMessage() {} func (x *LogoutRequest) ProtoReflect() protoreflect.Message { - mi := &file_organize_proto_msgTypes[44] + mi := &file_organize_proto_msgTypes[47] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2662,7 +2818,7 @@ func (x *LogoutRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use LogoutRequest.ProtoReflect.Descriptor instead. func (*LogoutRequest) Descriptor() ([]byte, []int) { - return file_organize_proto_rawDescGZIP(), []int{44} + return file_organize_proto_rawDescGZIP(), []int{47} } func (x *LogoutRequest) GetToken() string { @@ -2681,7 +2837,7 @@ type LogoutResponse struct { func (x *LogoutResponse) Reset() { *x = LogoutResponse{} - mi := &file_organize_proto_msgTypes[45] + mi := &file_organize_proto_msgTypes[48] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2693,7 +2849,7 @@ func (x *LogoutResponse) String() string { func (*LogoutResponse) ProtoMessage() {} func (x *LogoutResponse) ProtoReflect() protoreflect.Message { - mi := &file_organize_proto_msgTypes[45] + mi := &file_organize_proto_msgTypes[48] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2706,7 +2862,7 @@ func (x *LogoutResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use LogoutResponse.ProtoReflect.Descriptor instead. func (*LogoutResponse) Descriptor() ([]byte, []int) { - return file_organize_proto_rawDescGZIP(), []int{45} + return file_organize_proto_rawDescGZIP(), []int{48} } func (x *LogoutResponse) GetUid() string { @@ -2720,7 +2876,7 @@ var File_organize_proto protoreflect.FileDescriptor const file_organize_proto_rawDesc = "" + "\n" + - "\x0eorganize.proto\x12\borganize\x1a\x0faeus/rest.proto\x1a\x17validate/validate.proto\x1a google/protobuf/descriptor.proto\x1a\x1cgoogle/api/annotations.proto\"\xab\b\n" + + "\x0eorganize.proto\x12\borganize\x1a\x0faeus/rest.proto\x1a\x17validate/validate.proto\x1a google/protobuf/descriptor.proto\x1a\x1cgoogle/api/annotations.proto\"\xc2\b\n" + "\x04Menu\x12*\n" + "\x02id\x18\x01 \x01(\x03B\x1a\xb2\xb9\x19\x16\n" + "\n" + @@ -2729,9 +2885,9 @@ const file_organize_proto_rawDesc = "" + "created_at\x18\x02 \x01(\x03B\x1f\xb2\xb9\x19\x1b\x12\f创建时间\x1a\vview;exportR\tcreatedAt\x12E\n" + "\n" + "updated_at\x18\x03 \x01(\x03B&\xb2\xb9\x19\"\n" + - "\x05index\x12\f更新时间\x1a\vview;exportR\tupdatedAt\x12v\n" + - "\x06parent\x18\x04 \x01(\tB^\xb2\xb9\x19Z\n" + - "\rindex;size:60\x12\f父级菜单*\x04menu2\x0freadonly:updateB$type:dropdown;url:/menu/level-labelsR\x06parent\x12^\n" + + "\x05index\x12\f更新时间\x1a\vview;exportR\tupdatedAt\x12\x91\x01\n" + + "\x06parent\x18\x04 \x01(\tBy\xb2\xb9\x19u\n" + + "\rindex;size:60\x12\f父级菜单\x1a\x19create;update;view;export*\x04menu2\x0freadonly:updateB$type:dropdown;url:/menu/level-labelsR\x06parent\x12^\n" + "\x04name\x18\x05 \x01(\tBJ\xfaB\x04r\x02\x18<\xb2\xb9\x19?\n" + "\rindex;size:60\x12\f组件名称2\x0freadonly:update:\x0funique;requiredR\x04name\x12C\n" + "\x05label\x18\x06 \x01(\tB-\xfaB\x04r\x02\x18x\xb2\xb9\x19\"\n" + @@ -2744,9 +2900,9 @@ const file_organize_proto_rawDesc = "" + "\asize:60\x12\f菜单图标\x1a\x19create;update;view;exportR\x04icon\x12E\n" + "\x06hidden\x18\n" + " \x01(\bB-\xb2\xb9\x19)\x12\f是否隐藏\x1a\x19create;update;view;exportR\x06hidden\x12E\n" + - "\x06public\x18\v \x01(\bB-\xb2\xb9\x19)\x12\f是否公开\x1a\x19create;update;view;exportR\x06public\x12q\n" + - "\vdescription\x18\f \x01(\tBO\xfaB\x05r\x03\x18\x80\b\xb2\xb9\x19C\n" + - "\tsize:1024\x12\f备注说明\x1a\x1ecreate;update;view;export;list*\btextareaR\vdescription\x127\n" + + "\x06public\x18\v \x01(\bB-\xb2\xb9\x19)\x12\f是否公开\x1a\x19create;update;view;exportR\x06public\x12l\n" + + "\vdescription\x18\f \x01(\tBJ\xfaB\x05r\x03\x18\x80\b\xb2\xb9\x19>\n" + + "\tsize:1024\x12\f备注说明\x1a\x19create;update;view;export*\btextareaR\vdescription\x127\n" + "\bposition\x18\r \x01(\x03B\x1b\xb2\xb9\x19\x17\x12\x06排序\x1a\rcreate;updateR\bposition:\v\xba\xb9\x19\a\n" + "\x05menus\"\xd1\x03\n" + "\x04Role\x12*\n" + @@ -2886,12 +3042,12 @@ const file_organize_proto_rawDesc = "" + "\x05route\x18\x06 \x01(\tR\x05route\x12\x12\n" + "\x04view\x18\a \x01(\tR\x04view\x12:\n" + "\vpermissions\x18\b \x03(\v2\x18.organize.PermissionItemR\vpermissions\x12.\n" + - "\bchildren\x18\t \x03(\v2\x12.organize.MenuItemR\bchildren\"0\n" + - "\x0eGetMenuRequest\x12\x1e\n" + + "\bchildren\x18\t \x03(\v2\x12.organize.MenuItemR\bchildren\"4\n" + + "\x12GetUserMenuRequest\x12\x1e\n" + "\n" + "permission\x18\x01 \x01(\bR\n" + - "permission\"9\n" + - "\x0fGetMenuResponse\x12&\n" + + "permission\"=\n" + + "\x13GetUserMenuResponse\x12&\n" + "\x04data\x18\x01 \x03(\v2\x12.organize.MenuItemR\x04data\"%\n" + "\x11GetProfileRequest\x12\x10\n" + "\x03uid\x18\x01 \x01(\tR\x03uid\"\xbc\x01\n" + @@ -2968,7 +3124,16 @@ const file_organize_proto_rawDesc = "" + "\bchildren\x18\x04 \x03(\v2\x18.organize.MenuLevelValueR\bchildren\"\x1b\n" + "\x19GetMenuLevelLabelsRequest\"J\n" + "\x1aGetMenuLevelLabelsResponse\x12,\n" + - "\x04data\x18\x01 \x03(\v2\x18.organize.MenuLevelValueR\x04data\"\\\n" + + "\x04data\x18\x01 \x03(\v2\x18.organize.MenuLevelValueR\x04data\"\x8e\x01\n" + + "\tMenuValue\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06parent\x18\x02 \x01(\tR\x06parent\x12\x12\n" + + "\x04name\x18\x03 \x01(\tR\x04name\x12\x14\n" + + "\x05label\x18\x04 \x01(\tR\x05label\x12/\n" + + "\bchildren\x18\x05 \x03(\v2\x13.organize.MenuValueR\bchildren\"\x10\n" + + "\x0eGetMenuRequest\":\n" + + "\x0fGetMenuResponse\x12'\n" + + "\x04data\x18\x01 \x03(\v2\x13.organize.MenuValueR\x04data\"\\\n" + "\fLoginRequest\x12\x1a\n" + "\busername\x18\x01 \x01(\tR\busername\x12\x1a\n" + "\bpassword\x18\x02 \x01(\tR\bpassword\x12\x14\n" + @@ -2981,9 +3146,9 @@ const file_organize_proto_rawDesc = "" + "\rLogoutRequest\x12\x14\n" + "\x05token\x18\x01 \x01(\tR\x05token\"\"\n" + "\x0eLogoutResponse\x12\x10\n" + - "\x03uid\x18\x01 \x01(\tR\x03uid2\xd4\x05\n" + - "\vUserService\x12T\n" + - "\bGetMenus\x12\x18.organize.GetMenuRequest\x1a\x19.organize.GetMenuResponse\"\x13\x82\xd3\xe4\x93\x02\r\x12\v/user/menus\x12^\n" + + "\x03uid\x18\x01 \x01(\tR\x03uid2\xdc\x05\n" + + "\vUserService\x12\\\n" + + "\bGetMenus\x12\x1c.organize.GetUserMenuRequest\x1a\x1d.organize.GetUserMenuResponse\"\x13\x82\xd3\xe4\x93\x02\r\x12\v/user/menus\x12^\n" + "\n" + "GetProfile\x12\x1b.organize.GetProfileRequest\x1a\x1c.organize.GetProfileResponse\"\x15\x82\xd3\xe4\x93\x02\x0f\x12\r/user/profile\x12j\n" + "\rUpdateProfile\x12\x1e.organize.UpdateProfileRequest\x1a\x1f.organize.UpdateProfileResponse\"\x18\x82\xd3\xe4\x93\x02\x12:\x01*\x1a\r/user/profile\x12q\n" + @@ -2999,8 +3164,10 @@ const file_organize_proto_rawDesc = "" + "\vRoleService\x12d\n" + "\rGetRoleLabels\x12\x1d.organize.GetRoleLabelRequest\x1a\x1e.organize.GetRoleLabelResponse\"\x14\x82\xd3\xe4\x93\x02\x0e\x12\f/role/labels\x12x\n" + "\x12GetRolePermissions\x12\".organize.GetRolePermissionRequest\x1a#.organize.GetRolePermissionResponse\"\x19\x82\xd3\xe4\x93\x02\x13\x12\x11/role/permissions\x12}\n" + - "\x12SaveRolePermission\x12#.organize.SaveRolePermissionRequest\x1a$.organize.SaveRolePermissionResponse\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\"\x11/role/permissions2\x8a\x01\n" + - "\vMenuService\x12{\n" + + "\x12SaveRolePermission\x12#.organize.SaveRolePermissionRequest\x1a$.organize.SaveRolePermissionResponse\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\"\x11/role/permissions2\xdf\x01\n" + + "\vMenuService\x12S\n" + + "\bGetMenus\x12\x18.organize.GetMenuRequest\x1a\x19.organize.GetMenuResponse\"\x12\x82\xd3\xe4\x93\x02\f\x12\n" + + "/menu/list\x12{\n" + "\x12GetMenuLevelLabels\x12#.organize.GetMenuLevelLabelsRequest\x1a$.organize.GetMenuLevelLabelsResponse\"\x1a\x82\xd3\xe4\x93\x02\x14\x12\x12/menu/level-labels2\xbd\x01\n" + "\vAuthService\x12T\n" + "\x05Login\x12\x16.organize.LoginRequest\x1a\x17.organize.LoginResponse\"\x1a\x82\xd3\xe4\x93\x02\x14:\x01*\"\x0f/passport/login\x12X\n" + @@ -3018,7 +3185,7 @@ func file_organize_proto_rawDescGZIP() []byte { return file_organize_proto_rawDescData } -var file_organize_proto_msgTypes = make([]protoimpl.MessageInfo, 46) +var file_organize_proto_msgTypes = make([]protoimpl.MessageInfo, 49) var file_organize_proto_goTypes = []any{ (*Menu)(nil), // 0: organize.Menu (*Role)(nil), // 1: organize.Role @@ -3030,8 +3197,8 @@ var file_organize_proto_goTypes = []any{ (*LabelValue)(nil), // 7: organize.LabelValue (*PermissionItem)(nil), // 8: organize.PermissionItem (*MenuItem)(nil), // 9: organize.MenuItem - (*GetMenuRequest)(nil), // 10: organize.GetMenuRequest - (*GetMenuResponse)(nil), // 11: organize.GetMenuResponse + (*GetUserMenuRequest)(nil), // 10: organize.GetUserMenuRequest + (*GetUserMenuResponse)(nil), // 11: organize.GetUserMenuResponse (*GetProfileRequest)(nil), // 12: organize.GetProfileRequest (*GetProfileResponse)(nil), // 13: organize.GetProfileResponse (*ResetPasswordRequest)(nil), // 14: organize.ResetPasswordRequest @@ -3062,15 +3229,18 @@ var file_organize_proto_goTypes = []any{ (*MenuLevelValue)(nil), // 39: organize.MenuLevelValue (*GetMenuLevelLabelsRequest)(nil), // 40: organize.GetMenuLevelLabelsRequest (*GetMenuLevelLabelsResponse)(nil), // 41: organize.GetMenuLevelLabelsResponse - (*LoginRequest)(nil), // 42: organize.LoginRequest - (*LoginResponse)(nil), // 43: organize.LoginResponse - (*LogoutRequest)(nil), // 44: organize.LogoutRequest - (*LogoutResponse)(nil), // 45: organize.LogoutResponse + (*MenuValue)(nil), // 42: organize.MenuValue + (*GetMenuRequest)(nil), // 43: organize.GetMenuRequest + (*GetMenuResponse)(nil), // 44: organize.GetMenuResponse + (*LoginRequest)(nil), // 45: organize.LoginRequest + (*LoginResponse)(nil), // 46: organize.LoginResponse + (*LogoutRequest)(nil), // 47: organize.LogoutRequest + (*LogoutResponse)(nil), // 48: organize.LogoutResponse } var file_organize_proto_depIdxs = []int32{ 8, // 0: organize.MenuItem.permissions:type_name -> organize.PermissionItem 9, // 1: organize.MenuItem.children:type_name -> organize.MenuItem - 9, // 2: organize.GetMenuResponse.data:type_name -> organize.MenuItem + 9, // 2: organize.GetUserMenuResponse.data:type_name -> organize.MenuItem 7, // 3: organize.GetUserLabelResponse.data:type_name -> organize.LabelValue 7, // 4: organize.GetUserTagResponse.data:type_name -> organize.LabelValue 25, // 5: organize.DepartmentUserValue.children:type_name -> organize.DepartmentUserValue @@ -3081,43 +3251,47 @@ var file_organize_proto_depIdxs = []int32{ 7, // 10: organize.GetRoleLabelResponse.data:type_name -> organize.LabelValue 39, // 11: organize.MenuLevelValue.children:type_name -> organize.MenuLevelValue 39, // 12: organize.GetMenuLevelLabelsResponse.data:type_name -> organize.MenuLevelValue - 10, // 13: organize.UserService.GetMenus:input_type -> organize.GetMenuRequest - 12, // 14: organize.UserService.GetProfile:input_type -> organize.GetProfileRequest - 16, // 15: organize.UserService.UpdateProfile:input_type -> organize.UpdateProfileRequest - 14, // 16: organize.UserService.ResetPassword:input_type -> organize.ResetPasswordRequest - 18, // 17: organize.UserService.GetPermissions:input_type -> organize.GetPermissionRequest - 20, // 18: organize.UserService.GetUserLabels:input_type -> organize.GetUserLabelRequest - 22, // 19: organize.UserService.GetUserTags:input_type -> organize.GetUserTagRequest - 26, // 20: organize.DepartmentService.GetDepartmentLabels:input_type -> organize.GetDepartmentLabelRequest - 28, // 21: organize.DepartmentService.GetDepartmentUsers:input_type -> organize.GetDepartmentUserRequest - 31, // 22: organize.DepartmentService.GetDepartmentLevelLabels:input_type -> organize.GetDepartmentLevelLabelsRequest - 33, // 23: organize.RoleService.GetRoleLabels:input_type -> organize.GetRoleLabelRequest - 35, // 24: organize.RoleService.GetRolePermissions:input_type -> organize.GetRolePermissionRequest - 37, // 25: organize.RoleService.SaveRolePermission:input_type -> organize.SaveRolePermissionRequest - 40, // 26: organize.MenuService.GetMenuLevelLabels:input_type -> organize.GetMenuLevelLabelsRequest - 42, // 27: organize.AuthService.Login:input_type -> organize.LoginRequest - 44, // 28: organize.AuthService.Logout:input_type -> organize.LogoutRequest - 11, // 29: organize.UserService.GetMenus:output_type -> organize.GetMenuResponse - 13, // 30: organize.UserService.GetProfile:output_type -> organize.GetProfileResponse - 17, // 31: organize.UserService.UpdateProfile:output_type -> organize.UpdateProfileResponse - 15, // 32: organize.UserService.ResetPassword:output_type -> organize.ResetPasswordResponse - 19, // 33: organize.UserService.GetPermissions:output_type -> organize.GetPermissionResponse - 21, // 34: organize.UserService.GetUserLabels:output_type -> organize.GetUserLabelResponse - 23, // 35: organize.UserService.GetUserTags:output_type -> organize.GetUserTagResponse - 27, // 36: organize.DepartmentService.GetDepartmentLabels:output_type -> organize.GetDepartmentLabelResponse - 29, // 37: organize.DepartmentService.GetDepartmentUsers:output_type -> organize.GetDepartmentUserResponse - 32, // 38: organize.DepartmentService.GetDepartmentLevelLabels:output_type -> organize.GetDepartmentLevelLabelsResponse - 34, // 39: organize.RoleService.GetRoleLabels:output_type -> organize.GetRoleLabelResponse - 36, // 40: organize.RoleService.GetRolePermissions:output_type -> organize.GetRolePermissionResponse - 38, // 41: organize.RoleService.SaveRolePermission:output_type -> organize.SaveRolePermissionResponse - 41, // 42: organize.MenuService.GetMenuLevelLabels:output_type -> organize.GetMenuLevelLabelsResponse - 43, // 43: organize.AuthService.Login:output_type -> organize.LoginResponse - 45, // 44: organize.AuthService.Logout:output_type -> organize.LogoutResponse - 29, // [29:45] is the sub-list for method output_type - 13, // [13:29] is the sub-list for method input_type - 13, // [13:13] is the sub-list for extension type_name - 13, // [13:13] is the sub-list for extension extendee - 0, // [0:13] is the sub-list for field type_name + 42, // 13: organize.MenuValue.children:type_name -> organize.MenuValue + 42, // 14: organize.GetMenuResponse.data:type_name -> organize.MenuValue + 10, // 15: organize.UserService.GetMenus:input_type -> organize.GetUserMenuRequest + 12, // 16: organize.UserService.GetProfile:input_type -> organize.GetProfileRequest + 16, // 17: organize.UserService.UpdateProfile:input_type -> organize.UpdateProfileRequest + 14, // 18: organize.UserService.ResetPassword:input_type -> organize.ResetPasswordRequest + 18, // 19: organize.UserService.GetPermissions:input_type -> organize.GetPermissionRequest + 20, // 20: organize.UserService.GetUserLabels:input_type -> organize.GetUserLabelRequest + 22, // 21: organize.UserService.GetUserTags:input_type -> organize.GetUserTagRequest + 26, // 22: organize.DepartmentService.GetDepartmentLabels:input_type -> organize.GetDepartmentLabelRequest + 28, // 23: organize.DepartmentService.GetDepartmentUsers:input_type -> organize.GetDepartmentUserRequest + 31, // 24: organize.DepartmentService.GetDepartmentLevelLabels:input_type -> organize.GetDepartmentLevelLabelsRequest + 33, // 25: organize.RoleService.GetRoleLabels:input_type -> organize.GetRoleLabelRequest + 35, // 26: organize.RoleService.GetRolePermissions:input_type -> organize.GetRolePermissionRequest + 37, // 27: organize.RoleService.SaveRolePermission:input_type -> organize.SaveRolePermissionRequest + 43, // 28: organize.MenuService.GetMenus:input_type -> organize.GetMenuRequest + 40, // 29: organize.MenuService.GetMenuLevelLabels:input_type -> organize.GetMenuLevelLabelsRequest + 45, // 30: organize.AuthService.Login:input_type -> organize.LoginRequest + 47, // 31: organize.AuthService.Logout:input_type -> organize.LogoutRequest + 11, // 32: organize.UserService.GetMenus:output_type -> organize.GetUserMenuResponse + 13, // 33: organize.UserService.GetProfile:output_type -> organize.GetProfileResponse + 17, // 34: organize.UserService.UpdateProfile:output_type -> organize.UpdateProfileResponse + 15, // 35: organize.UserService.ResetPassword:output_type -> organize.ResetPasswordResponse + 19, // 36: organize.UserService.GetPermissions:output_type -> organize.GetPermissionResponse + 21, // 37: organize.UserService.GetUserLabels:output_type -> organize.GetUserLabelResponse + 23, // 38: organize.UserService.GetUserTags:output_type -> organize.GetUserTagResponse + 27, // 39: organize.DepartmentService.GetDepartmentLabels:output_type -> organize.GetDepartmentLabelResponse + 29, // 40: organize.DepartmentService.GetDepartmentUsers:output_type -> organize.GetDepartmentUserResponse + 32, // 41: organize.DepartmentService.GetDepartmentLevelLabels:output_type -> organize.GetDepartmentLevelLabelsResponse + 34, // 42: organize.RoleService.GetRoleLabels:output_type -> organize.GetRoleLabelResponse + 36, // 43: organize.RoleService.GetRolePermissions:output_type -> organize.GetRolePermissionResponse + 38, // 44: organize.RoleService.SaveRolePermission:output_type -> organize.SaveRolePermissionResponse + 44, // 45: organize.MenuService.GetMenus:output_type -> organize.GetMenuResponse + 41, // 46: organize.MenuService.GetMenuLevelLabels:output_type -> organize.GetMenuLevelLabelsResponse + 46, // 47: organize.AuthService.Login:output_type -> organize.LoginResponse + 48, // 48: organize.AuthService.Logout:output_type -> organize.LogoutResponse + 32, // [32:49] is the sub-list for method output_type + 15, // [15:32] is the sub-list for method input_type + 15, // [15:15] is the sub-list for extension type_name + 15, // [15:15] is the sub-list for extension extendee + 0, // [0:15] is the sub-list for field type_name } func init() { file_organize_proto_init() } @@ -3131,7 +3305,7 @@ func file_organize_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_organize_proto_rawDesc), len(file_organize_proto_rawDesc)), NumEnums: 0, - NumMessages: 46, + NumMessages: 49, NumExtensions: 0, NumServices: 5, }, diff --git a/pb/organize.pb.validate.go b/pb/organize.pb.validate.go index d69a335..3913185 100644 --- a/pb/organize.pb.validate.go +++ b/pb/organize.pb.validate.go @@ -1445,22 +1445,22 @@ var _ interface { ErrorName() string } = MenuItemValidationError{} -// Validate checks the field values on GetMenuRequest with the rules defined in -// the proto definition for this message. If any rules are violated, the first -// error encountered is returned, or nil if there are no violations. -func (m *GetMenuRequest) Validate() error { +// Validate checks the field values on GetUserMenuRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *GetUserMenuRequest) Validate() error { return m.validate(false) } -// ValidateAll checks the field values on GetMenuRequest with the rules defined -// in the proto definition for this message. If any rules are violated, the -// result is a list of violation errors wrapped in GetMenuRequestMultiError, -// or nil if none found. -func (m *GetMenuRequest) ValidateAll() error { +// ValidateAll checks the field values on GetUserMenuRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// GetUserMenuRequestMultiError, or nil if none found. +func (m *GetUserMenuRequest) ValidateAll() error { return m.validate(true) } -func (m *GetMenuRequest) validate(all bool) error { +func (m *GetUserMenuRequest) validate(all bool) error { if m == nil { return nil } @@ -1470,19 +1470,19 @@ func (m *GetMenuRequest) validate(all bool) error { // no validation rules for Permission if len(errors) > 0 { - return GetMenuRequestMultiError(errors) + return GetUserMenuRequestMultiError(errors) } return nil } -// GetMenuRequestMultiError is an error wrapping multiple validation errors -// returned by GetMenuRequest.ValidateAll() if the designated constraints +// GetUserMenuRequestMultiError is an error wrapping multiple validation errors +// returned by GetUserMenuRequest.ValidateAll() if the designated constraints // aren't met. -type GetMenuRequestMultiError []error +type GetUserMenuRequestMultiError []error // Error returns a concatenation of all the error messages it wraps. -func (m GetMenuRequestMultiError) Error() string { +func (m GetUserMenuRequestMultiError) Error() string { msgs := make([]string, 0, len(m)) for _, err := range m { msgs = append(msgs, err.Error()) @@ -1491,11 +1491,11 @@ func (m GetMenuRequestMultiError) Error() string { } // AllErrors returns a list of validation violation errors. -func (m GetMenuRequestMultiError) AllErrors() []error { return m } +func (m GetUserMenuRequestMultiError) AllErrors() []error { return m } -// GetMenuRequestValidationError is the validation error returned by -// GetMenuRequest.Validate if the designated constraints aren't met. -type GetMenuRequestValidationError struct { +// GetUserMenuRequestValidationError is the validation error returned by +// GetUserMenuRequest.Validate if the designated constraints aren't met. +type GetUserMenuRequestValidationError struct { field string reason string cause error @@ -1503,22 +1503,24 @@ type GetMenuRequestValidationError struct { } // Field function returns field value. -func (e GetMenuRequestValidationError) Field() string { return e.field } +func (e GetUserMenuRequestValidationError) Field() string { return e.field } // Reason function returns reason value. -func (e GetMenuRequestValidationError) Reason() string { return e.reason } +func (e GetUserMenuRequestValidationError) Reason() string { return e.reason } // Cause function returns cause value. -func (e GetMenuRequestValidationError) Cause() error { return e.cause } +func (e GetUserMenuRequestValidationError) Cause() error { return e.cause } // Key function returns key value. -func (e GetMenuRequestValidationError) Key() bool { return e.key } +func (e GetUserMenuRequestValidationError) Key() bool { return e.key } // ErrorName returns error name. -func (e GetMenuRequestValidationError) ErrorName() string { return "GetMenuRequestValidationError" } +func (e GetUserMenuRequestValidationError) ErrorName() string { + return "GetUserMenuRequestValidationError" +} // Error satisfies the builtin error interface -func (e GetMenuRequestValidationError) Error() string { +func (e GetUserMenuRequestValidationError) Error() string { cause := "" if e.cause != nil { cause = fmt.Sprintf(" | caused by: %v", e.cause) @@ -1530,14 +1532,14 @@ func (e GetMenuRequestValidationError) Error() string { } return fmt.Sprintf( - "invalid %sGetMenuRequest.%s: %s%s", + "invalid %sGetUserMenuRequest.%s: %s%s", key, e.field, e.reason, cause) } -var _ error = GetMenuRequestValidationError{} +var _ error = GetUserMenuRequestValidationError{} var _ interface { Field() string @@ -1545,24 +1547,24 @@ var _ interface { Key() bool Cause() error ErrorName() string -} = GetMenuRequestValidationError{} +} = GetUserMenuRequestValidationError{} -// Validate checks the field values on GetMenuResponse with the rules defined -// in the proto definition for this message. If any rules are violated, the -// first error encountered is returned, or nil if there are no violations. -func (m *GetMenuResponse) Validate() error { +// Validate checks the field values on GetUserMenuResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *GetUserMenuResponse) Validate() error { return m.validate(false) } -// ValidateAll checks the field values on GetMenuResponse with the rules +// ValidateAll checks the field values on GetUserMenuResponse with the rules // defined in the proto definition for this message. If any rules are // violated, the result is a list of violation errors wrapped in -// GetMenuResponseMultiError, or nil if none found. -func (m *GetMenuResponse) ValidateAll() error { +// GetUserMenuResponseMultiError, or nil if none found. +func (m *GetUserMenuResponse) ValidateAll() error { return m.validate(true) } -func (m *GetMenuResponse) validate(all bool) error { +func (m *GetUserMenuResponse) validate(all bool) error { if m == nil { return nil } @@ -1576,7 +1578,7 @@ func (m *GetMenuResponse) validate(all bool) error { switch v := interface{}(item).(type) { case interface{ ValidateAll() error }: if err := v.ValidateAll(); err != nil { - errors = append(errors, GetMenuResponseValidationError{ + errors = append(errors, GetUserMenuResponseValidationError{ field: fmt.Sprintf("Data[%v]", idx), reason: "embedded message failed validation", cause: err, @@ -1584,7 +1586,7 @@ func (m *GetMenuResponse) validate(all bool) error { } case interface{ Validate() error }: if err := v.Validate(); err != nil { - errors = append(errors, GetMenuResponseValidationError{ + errors = append(errors, GetUserMenuResponseValidationError{ field: fmt.Sprintf("Data[%v]", idx), reason: "embedded message failed validation", cause: err, @@ -1593,7 +1595,7 @@ func (m *GetMenuResponse) validate(all bool) error { } } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { if err := v.Validate(); err != nil { - return GetMenuResponseValidationError{ + return GetUserMenuResponseValidationError{ field: fmt.Sprintf("Data[%v]", idx), reason: "embedded message failed validation", cause: err, @@ -1604,19 +1606,19 @@ func (m *GetMenuResponse) validate(all bool) error { } if len(errors) > 0 { - return GetMenuResponseMultiError(errors) + return GetUserMenuResponseMultiError(errors) } return nil } -// GetMenuResponseMultiError is an error wrapping multiple validation errors -// returned by GetMenuResponse.ValidateAll() if the designated constraints -// aren't met. -type GetMenuResponseMultiError []error +// GetUserMenuResponseMultiError is an error wrapping multiple validation +// errors returned by GetUserMenuResponse.ValidateAll() if the designated +// constraints aren't met. +type GetUserMenuResponseMultiError []error // Error returns a concatenation of all the error messages it wraps. -func (m GetMenuResponseMultiError) Error() string { +func (m GetUserMenuResponseMultiError) Error() string { msgs := make([]string, 0, len(m)) for _, err := range m { msgs = append(msgs, err.Error()) @@ -1625,11 +1627,11 @@ func (m GetMenuResponseMultiError) Error() string { } // AllErrors returns a list of validation violation errors. -func (m GetMenuResponseMultiError) AllErrors() []error { return m } +func (m GetUserMenuResponseMultiError) AllErrors() []error { return m } -// GetMenuResponseValidationError is the validation error returned by -// GetMenuResponse.Validate if the designated constraints aren't met. -type GetMenuResponseValidationError struct { +// GetUserMenuResponseValidationError is the validation error returned by +// GetUserMenuResponse.Validate if the designated constraints aren't met. +type GetUserMenuResponseValidationError struct { field string reason string cause error @@ -1637,22 +1639,24 @@ type GetMenuResponseValidationError struct { } // Field function returns field value. -func (e GetMenuResponseValidationError) Field() string { return e.field } +func (e GetUserMenuResponseValidationError) Field() string { return e.field } // Reason function returns reason value. -func (e GetMenuResponseValidationError) Reason() string { return e.reason } +func (e GetUserMenuResponseValidationError) Reason() string { return e.reason } // Cause function returns cause value. -func (e GetMenuResponseValidationError) Cause() error { return e.cause } +func (e GetUserMenuResponseValidationError) Cause() error { return e.cause } // Key function returns key value. -func (e GetMenuResponseValidationError) Key() bool { return e.key } +func (e GetUserMenuResponseValidationError) Key() bool { return e.key } // ErrorName returns error name. -func (e GetMenuResponseValidationError) ErrorName() string { return "GetMenuResponseValidationError" } +func (e GetUserMenuResponseValidationError) ErrorName() string { + return "GetUserMenuResponseValidationError" +} // Error satisfies the builtin error interface -func (e GetMenuResponseValidationError) Error() string { +func (e GetUserMenuResponseValidationError) Error() string { cause := "" if e.cause != nil { cause = fmt.Sprintf(" | caused by: %v", e.cause) @@ -1664,14 +1668,14 @@ func (e GetMenuResponseValidationError) Error() string { } return fmt.Sprintf( - "invalid %sGetMenuResponse.%s: %s%s", + "invalid %sGetUserMenuResponse.%s: %s%s", key, e.field, e.reason, cause) } -var _ error = GetMenuResponseValidationError{} +var _ error = GetUserMenuResponseValidationError{} var _ interface { Field() string @@ -1679,7 +1683,7 @@ var _ interface { Key() bool Cause() error ErrorName() string -} = GetMenuResponseValidationError{} +} = GetUserMenuResponseValidationError{} // Validate checks the field values on GetProfileRequest with the rules defined // in the proto definition for this message. If any rules are violated, the @@ -5149,6 +5153,381 @@ var _ interface { ErrorName() string } = GetMenuLevelLabelsResponseValidationError{} +// Validate checks the field values on MenuValue with the rules defined in the +// proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *MenuValue) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on MenuValue with the rules defined in +// the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in MenuValueMultiError, or nil +// if none found. +func (m *MenuValue) ValidateAll() error { + return m.validate(true) +} + +func (m *MenuValue) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + // no validation rules for Id + + // no validation rules for Parent + + // no validation rules for Name + + // no validation rules for Label + + for idx, item := range m.GetChildren() { + _, _ = idx, item + + if all { + switch v := interface{}(item).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, MenuValueValidationError{ + field: fmt.Sprintf("Children[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, MenuValueValidationError{ + field: fmt.Sprintf("Children[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return MenuValueValidationError{ + field: fmt.Sprintf("Children[%v]", idx), + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if len(errors) > 0 { + return MenuValueMultiError(errors) + } + + return nil +} + +// MenuValueMultiError is an error wrapping multiple validation errors returned +// by MenuValue.ValidateAll() if the designated constraints aren't met. +type MenuValueMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m MenuValueMultiError) Error() string { + msgs := make([]string, 0, len(m)) + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m MenuValueMultiError) AllErrors() []error { return m } + +// MenuValueValidationError is the validation error returned by +// MenuValue.Validate if the designated constraints aren't met. +type MenuValueValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e MenuValueValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e MenuValueValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e MenuValueValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e MenuValueValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e MenuValueValidationError) ErrorName() string { return "MenuValueValidationError" } + +// Error satisfies the builtin error interface +func (e MenuValueValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sMenuValue.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = MenuValueValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = MenuValueValidationError{} + +// Validate checks the field values on GetMenuRequest with the rules defined in +// the proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *GetMenuRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on GetMenuRequest with the rules defined +// in the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in GetMenuRequestMultiError, +// or nil if none found. +func (m *GetMenuRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *GetMenuRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if len(errors) > 0 { + return GetMenuRequestMultiError(errors) + } + + return nil +} + +// GetMenuRequestMultiError is an error wrapping multiple validation errors +// returned by GetMenuRequest.ValidateAll() if the designated constraints +// aren't met. +type GetMenuRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m GetMenuRequestMultiError) Error() string { + msgs := make([]string, 0, len(m)) + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m GetMenuRequestMultiError) AllErrors() []error { return m } + +// GetMenuRequestValidationError is the validation error returned by +// GetMenuRequest.Validate if the designated constraints aren't met. +type GetMenuRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e GetMenuRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e GetMenuRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e GetMenuRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e GetMenuRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e GetMenuRequestValidationError) ErrorName() string { return "GetMenuRequestValidationError" } + +// Error satisfies the builtin error interface +func (e GetMenuRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sGetMenuRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = GetMenuRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = GetMenuRequestValidationError{} + +// Validate checks the field values on GetMenuResponse with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *GetMenuResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on GetMenuResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// GetMenuResponseMultiError, or nil if none found. +func (m *GetMenuResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *GetMenuResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + for idx, item := range m.GetData() { + _, _ = idx, item + + if all { + switch v := interface{}(item).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, GetMenuResponseValidationError{ + field: fmt.Sprintf("Data[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, GetMenuResponseValidationError{ + field: fmt.Sprintf("Data[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return GetMenuResponseValidationError{ + field: fmt.Sprintf("Data[%v]", idx), + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if len(errors) > 0 { + return GetMenuResponseMultiError(errors) + } + + return nil +} + +// GetMenuResponseMultiError is an error wrapping multiple validation errors +// returned by GetMenuResponse.ValidateAll() if the designated constraints +// aren't met. +type GetMenuResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m GetMenuResponseMultiError) Error() string { + msgs := make([]string, 0, len(m)) + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m GetMenuResponseMultiError) AllErrors() []error { return m } + +// GetMenuResponseValidationError is the validation error returned by +// GetMenuResponse.Validate if the designated constraints aren't met. +type GetMenuResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e GetMenuResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e GetMenuResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e GetMenuResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e GetMenuResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e GetMenuResponseValidationError) ErrorName() string { return "GetMenuResponseValidationError" } + +// Error satisfies the builtin error interface +func (e GetMenuResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sGetMenuResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = GetMenuResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = GetMenuResponseValidationError{} + // Validate checks the field values on LoginRequest with the rules defined in // the proto definition for this message. If any rules are violated, the first // error encountered is returned, or nil if there are no violations. diff --git a/pb/organize.proto b/pb/organize.proto index 7cde9b4..21281a5 100644 --- a/pb/organize.proto +++ b/pb/organize.proto @@ -17,7 +17,7 @@ message Menu { int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment:"菜单ID"}]; int64 created_at = 2 [(aeus.field)={scenarios:"view;export",comment:"创建时间"}]; int64 updated_at = 3 [(aeus.field)={gorm:"index",scenarios:"view;export",comment:"更新时间"}]; - string parent = 4 [(aeus.field)={gorm:"index;size:60",props:"readonly:update",live:"type:dropdown;url:/menu/level-labels",format:"menu",comment:"父级菜单"}]; + string parent = 4 [(aeus.field)={gorm:"index;size:60",scenarios:"create;update;view;export",props:"readonly:update",live:"type:dropdown;url:/menu/level-labels",format:"menu",comment:"父级菜单"}]; string name = 5 [(aeus.field)={gorm:"index;size:60",props:"readonly:update",rule:"unique;required",comment: "组件名称"},(validate.rules).string = {max_len: 60}]; string label = 6 [(aeus.field)={gorm:"size:120",rule:"required",comment: "菜单标题"},(validate.rules).string = {max_len: 120}]; string uri = 7 [(aeus.field)={gorm:"size:512",rule:"required",scenarios:"create;update;view;export",comment: "菜单链接"},(validate.rules).string = {max_len: 512}]; @@ -25,7 +25,7 @@ message Menu { string icon = 9 [(aeus.field)={gorm:"size:60",scenarios:"create;update;view;export",comment: "菜单图标"},(validate.rules).string = {max_len: 60}]; bool hidden = 10 [(aeus.field)={scenarios:"create;update;view;export",comment:"是否隐藏"}]; bool public = 11 [(aeus.field)={scenarios:"create;update;view;export",comment:"是否公开"}]; - string description = 12 [(aeus.field)={gorm:"size:1024",scenarios:"create;update;view;export;list",format:"textarea",comment: "备注说明"},(validate.rules).string = {max_len: 1024}]; + string description = 12 [(aeus.field)={gorm:"size:1024",scenarios:"create;update;view;export",format:"textarea",comment: "备注说明"},(validate.rules).string = {max_len: 1024}]; int64 position = 13 [(aeus.field)={comment:"排序",scenarios:"create;update"}]; } @@ -139,12 +139,12 @@ message MenuItem { } // 获取菜单的请求 -message GetMenuRequest { +message GetUserMenuRequest { bool permission = 1; } // 获取菜单的响应 -message GetMenuResponse { +message GetUserMenuResponse { repeated MenuItem data = 1; } @@ -213,7 +213,7 @@ message GetUserTagResponse { // 用户服务 service UserService { // 获取用户菜单 - rpc GetMenus(GetMenuRequest) returns (GetMenuResponse) { + rpc GetMenus(GetUserMenuRequest) returns (GetUserMenuResponse) { option (google.api.http) = { get: "/user/menus" }; @@ -377,7 +377,28 @@ message GetMenuLevelLabelsResponse { repeated MenuLevelValue data = 1; } +message MenuValue { + int64 id = 1; + string parent = 2; + string name = 3; + string label = 4; + repeated MenuValue children = 5; +} + +message GetMenuRequest{ + +} + +message GetMenuResponse{ + repeated MenuValue data = 1; +} + service MenuService { + rpc GetMenus(GetMenuRequest) returns (GetMenuResponse) { + option (google.api.http) = { + get: "/menu/list" + }; + } rpc GetMenuLevelLabels(GetMenuLevelLabelsRequest) returns (GetMenuLevelLabelsResponse) { option (google.api.http) = { get: "/menu/level-labels" diff --git a/pb/organize_grpc.pb.go b/pb/organize_grpc.pb.go index e7c2531..dcd1232 100644 --- a/pb/organize_grpc.pb.go +++ b/pb/organize_grpc.pb.go @@ -35,7 +35,7 @@ const ( // 用户服务 type UserServiceClient interface { // 获取用户菜单 - GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error) + GetMenus(ctx context.Context, in *GetUserMenuRequest, opts ...grpc.CallOption) (*GetUserMenuResponse, error) // 获取用户信息 GetProfile(ctx context.Context, in *GetProfileRequest, opts ...grpc.CallOption) (*GetProfileResponse, error) // 更新用户信息 @@ -58,9 +58,9 @@ func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient { return &userServiceClient{cc} } -func (c *userServiceClient) GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error) { +func (c *userServiceClient) GetMenus(ctx context.Context, in *GetUserMenuRequest, opts ...grpc.CallOption) (*GetUserMenuResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(GetMenuResponse) + out := new(GetUserMenuResponse) err := c.cc.Invoke(ctx, UserService_GetMenus_FullMethodName, in, out, cOpts...) if err != nil { return nil, err @@ -135,7 +135,7 @@ func (c *userServiceClient) GetUserTags(ctx context.Context, in *GetUserTagReque // 用户服务 type UserServiceServer interface { // 获取用户菜单 - GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error) + GetMenus(context.Context, *GetUserMenuRequest) (*GetUserMenuResponse, error) // 获取用户信息 GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error) // 更新用户信息 @@ -158,7 +158,7 @@ type UserServiceServer interface { // pointer dereference when methods are called. type UnimplementedUserServiceServer struct{} -func (UnimplementedUserServiceServer) GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error) { +func (UnimplementedUserServiceServer) GetMenus(context.Context, *GetUserMenuRequest) (*GetUserMenuResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetMenus not implemented") } func (UnimplementedUserServiceServer) GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error) { @@ -201,7 +201,7 @@ func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer) { } func _UserService_GetMenus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetMenuRequest) + in := new(GetUserMenuRequest) if err := dec(in); err != nil { return nil, err } @@ -213,7 +213,7 @@ func _UserService_GetMenus_Handler(srv interface{}, ctx context.Context, dec fun FullMethod: UserService_GetMenus_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(UserServiceServer).GetMenus(ctx, req.(*GetMenuRequest)) + return srv.(UserServiceServer).GetMenus(ctx, req.(*GetUserMenuRequest)) } return interceptor(ctx, in, info, handler) } @@ -729,6 +729,7 @@ var RoleService_ServiceDesc = grpc.ServiceDesc{ } const ( + MenuService_GetMenus_FullMethodName = "/organize.MenuService/GetMenus" MenuService_GetMenuLevelLabels_FullMethodName = "/organize.MenuService/GetMenuLevelLabels" ) @@ -736,6 +737,7 @@ const ( // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type MenuServiceClient interface { + GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error) GetMenuLevelLabels(ctx context.Context, in *GetMenuLevelLabelsRequest, opts ...grpc.CallOption) (*GetMenuLevelLabelsResponse, error) } @@ -747,6 +749,16 @@ func NewMenuServiceClient(cc grpc.ClientConnInterface) MenuServiceClient { return &menuServiceClient{cc} } +func (c *menuServiceClient) GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetMenuResponse) + err := c.cc.Invoke(ctx, MenuService_GetMenus_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *menuServiceClient) GetMenuLevelLabels(ctx context.Context, in *GetMenuLevelLabelsRequest, opts ...grpc.CallOption) (*GetMenuLevelLabelsResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(GetMenuLevelLabelsResponse) @@ -761,6 +773,7 @@ func (c *menuServiceClient) GetMenuLevelLabels(ctx context.Context, in *GetMenuL // All implementations must embed UnimplementedMenuServiceServer // for forward compatibility. type MenuServiceServer interface { + GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error) GetMenuLevelLabels(context.Context, *GetMenuLevelLabelsRequest) (*GetMenuLevelLabelsResponse, error) mustEmbedUnimplementedMenuServiceServer() } @@ -772,6 +785,9 @@ type MenuServiceServer interface { // pointer dereference when methods are called. type UnimplementedMenuServiceServer struct{} +func (UnimplementedMenuServiceServer) GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetMenus not implemented") +} func (UnimplementedMenuServiceServer) GetMenuLevelLabels(context.Context, *GetMenuLevelLabelsRequest) (*GetMenuLevelLabelsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetMenuLevelLabels not implemented") } @@ -796,6 +812,24 @@ func RegisterMenuServiceServer(s grpc.ServiceRegistrar, srv MenuServiceServer) { s.RegisterService(&MenuService_ServiceDesc, srv) } +func _MenuService_GetMenus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetMenuRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MenuServiceServer).GetMenus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: MenuService_GetMenus_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MenuServiceServer).GetMenus(ctx, req.(*GetMenuRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _MenuService_GetMenuLevelLabels_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(GetMenuLevelLabelsRequest) if err := dec(in); err != nil { @@ -821,6 +855,10 @@ var MenuService_ServiceDesc = grpc.ServiceDesc{ ServiceName: "organize.MenuService", HandlerType: (*MenuServiceServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "GetMenus", + Handler: _MenuService_GetMenus_Handler, + }, { MethodName: "GetMenuLevelLabels", Handler: _MenuService_GetMenuLevelLabels_Handler, diff --git a/pb/organize_http.pb.go b/pb/organize_http.pb.go index 4130cc2..24c0db2 100644 --- a/pb/organize_http.pb.go +++ b/pb/organize_http.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-aeus. DO NOT EDIT. // source: organize.proto -// date: 2025-06-19 11:06:34 +// date: 2025-06-22 11:09:05 package pb @@ -11,57 +11,69 @@ import ( ) type UserServiceHttpServer interface { - GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error) - GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error) + // 获取用户菜单 + GetMenus(ctx context.Context, req *GetUserMenuRequest) (res *GetUserMenuResponse, err error) - UpdateProfile(context.Context, *UpdateProfileRequest) (*UpdateProfileResponse, error) + // 获取用户信息 + GetProfile(ctx context.Context, req *GetProfileRequest) (res *GetProfileResponse, err error) - ResetPassword(context.Context, *ResetPasswordRequest) (*ResetPasswordResponse, error) + // 更新用户信息 + UpdateProfile(ctx context.Context, req *UpdateProfileRequest) (res *UpdateProfileResponse, err error) - GetPermissions(context.Context, *GetPermissionRequest) (*GetPermissionResponse, error) + // 重置用户密码 + ResetPassword(ctx context.Context, req *ResetPasswordRequest) (res *ResetPasswordResponse, err error) - GetUserLabels(context.Context, *GetUserLabelRequest) (*GetUserLabelResponse, error) + // 获取用户权限 + GetPermissions(ctx context.Context, req *GetPermissionRequest) (res *GetPermissionResponse, err error) - GetUserTags(context.Context, *GetUserTagRequest) (*GetUserTagResponse, error) + // 获取用户标签 + GetUserLabels(ctx context.Context, req *GetUserLabelRequest) (res *GetUserLabelResponse, err error) + + // 获取用户标签 + GetUserTags(ctx context.Context, req *GetUserTagRequest) (res *GetUserTagResponse, err error) } type DepartmentServiceHttpServer interface { - GetDepartmentLabels(context.Context, *GetDepartmentLabelRequest) (*GetDepartmentLabelResponse, error) - GetDepartmentUsers(context.Context, *GetDepartmentUserRequest) (*GetDepartmentUserResponse, error) + // 获取部门标签 + GetDepartmentLabels(ctx context.Context, req *GetDepartmentLabelRequest) (res *GetDepartmentLabelResponse, err error) - GetDepartmentLevelLabels(context.Context, *GetDepartmentLevelLabelsRequest) (*GetDepartmentLevelLabelsResponse, error) + GetDepartmentUsers(ctx context.Context, req *GetDepartmentUserRequest) (res *GetDepartmentUserResponse, err error) + + GetDepartmentLevelLabels(ctx context.Context, req *GetDepartmentLevelLabelsRequest) (res *GetDepartmentLevelLabelsResponse, err error) } type RoleServiceHttpServer interface { - GetRoleLabels(context.Context, *GetRoleLabelRequest) (*GetRoleLabelResponse, error) - GetRolePermissions(context.Context, *GetRolePermissionRequest) (*GetRolePermissionResponse, error) + // 获取角色标签 + GetRoleLabels(ctx context.Context, req *GetRoleLabelRequest) (res *GetRoleLabelResponse, err error) - SaveRolePermission(context.Context, *SaveRolePermissionRequest) (*SaveRolePermissionResponse, error) + // 获取角色权限 + GetRolePermissions(ctx context.Context, req *GetRolePermissionRequest) (res *GetRolePermissionResponse, err error) + + SaveRolePermission(ctx context.Context, req *SaveRolePermissionRequest) (res *SaveRolePermissionResponse, err error) } type MenuServiceHttpServer interface { - GetMenuLevelLabels(context.Context, *GetMenuLevelLabelsRequest) (*GetMenuLevelLabelsResponse, error) + GetMenus(ctx context.Context, req *GetMenuRequest) (res *GetMenuResponse, err error) + + GetMenuLevelLabels(ctx context.Context, req *GetMenuLevelLabelsRequest) (res *GetMenuLevelLabelsResponse, err error) } type AuthServiceHttpServer interface { - Login(context.Context, *LoginRequest) (*LoginResponse, error) + Login(ctx context.Context, req *LoginRequest) (res *LoginResponse, err error) - Logout(context.Context, *LogoutRequest) (*LogoutResponse, error) + Logout(ctx context.Context, req *LogoutRequest) (res *LogoutResponse, err error) } // 获取用户菜单 - func handleUserServiceGetMenus(s UserServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { - req := &GetMenuRequest{} - + req := &GetUserMenuRequest{} if err := ctx.Bind(req); err != nil { return ctx.Error(errors.Invalid, err.Error()) } - if res, err := s.GetMenus(ctx.Context(), req); err != nil { if er, ok := err.(*errors.Error); ok { return ctx.Error(er.Code, er.Message) @@ -75,15 +87,12 @@ func handleUserServiceGetMenus(s UserServiceHttpServer) http.HandleFunc { } // 获取用户信息 - func handleUserServiceGetProfile(s UserServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &GetProfileRequest{} - if err := ctx.Bind(req); err != nil { return ctx.Error(errors.Invalid, err.Error()) } - if res, err := s.GetProfile(ctx.Context(), req); err != nil { if er, ok := err.(*errors.Error); ok { return ctx.Error(er.Code, er.Message) @@ -97,15 +106,12 @@ func handleUserServiceGetProfile(s UserServiceHttpServer) http.HandleFunc { } // 更新用户信息 - func handleUserServiceUpdateProfile(s UserServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &UpdateProfileRequest{} - if err := ctx.Bind(req); err != nil { return ctx.Error(errors.Invalid, err.Error()) } - if res, err := s.UpdateProfile(ctx.Context(), req); err != nil { if er, ok := err.(*errors.Error); ok { return ctx.Error(er.Code, er.Message) @@ -119,15 +125,12 @@ func handleUserServiceUpdateProfile(s UserServiceHttpServer) http.HandleFunc { } // 重置用户密码 - func handleUserServiceResetPassword(s UserServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &ResetPasswordRequest{} - if err := ctx.Bind(req); err != nil { return ctx.Error(errors.Invalid, err.Error()) } - if res, err := s.ResetPassword(ctx.Context(), req); err != nil { if er, ok := err.(*errors.Error); ok { return ctx.Error(er.Code, er.Message) @@ -141,15 +144,12 @@ func handleUserServiceResetPassword(s UserServiceHttpServer) http.HandleFunc { } // 获取用户权限 - func handleUserServiceGetPermissions(s UserServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &GetPermissionRequest{} - if err := ctx.Bind(req); err != nil { return ctx.Error(errors.Invalid, err.Error()) } - if res, err := s.GetPermissions(ctx.Context(), req); err != nil { if er, ok := err.(*errors.Error); ok { return ctx.Error(er.Code, er.Message) @@ -163,7 +163,6 @@ func handleUserServiceGetPermissions(s UserServiceHttpServer) http.HandleFunc { } // 获取用户标签 - func handleUserServiceGetUserLabels(s UserServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &GetUserLabelRequest{} @@ -181,7 +180,6 @@ func handleUserServiceGetUserLabels(s UserServiceHttpServer) http.HandleFunc { } // 获取用户标签 - func handleUserServiceGetUserTags(s UserServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &GetUserTagRequest{} @@ -199,7 +197,6 @@ func handleUserServiceGetUserTags(s UserServiceHttpServer) http.HandleFunc { } // 获取部门标签 - func handleDepartmentServiceGetDepartmentLabels(s DepartmentServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &GetDepartmentLabelRequest{} @@ -249,7 +246,6 @@ func handleDepartmentServiceGetDepartmentLevelLabels(s DepartmentServiceHttpServ } // 获取角色标签 - func handleRoleServiceGetRoleLabels(s RoleServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &GetRoleLabelRequest{} @@ -267,15 +263,12 @@ func handleRoleServiceGetRoleLabels(s RoleServiceHttpServer) http.HandleFunc { } // 获取角色权限 - func handleRoleServiceGetRolePermissions(s RoleServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &GetRolePermissionRequest{} - if err := ctx.Bind(req); err != nil { return ctx.Error(errors.Invalid, err.Error()) } - if res, err := s.GetRolePermissions(ctx.Context(), req); err != nil { if er, ok := err.(*errors.Error); ok { return ctx.Error(er.Code, er.Message) @@ -291,11 +284,9 @@ func handleRoleServiceGetRolePermissions(s RoleServiceHttpServer) http.HandleFun func handleRoleServiceSaveRolePermission(s RoleServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &SaveRolePermissionRequest{} - if err := ctx.Bind(req); err != nil { return ctx.Error(errors.Invalid, err.Error()) } - if res, err := s.SaveRolePermission(ctx.Context(), req); err != nil { if er, ok := err.(*errors.Error); ok { return ctx.Error(er.Code, er.Message) @@ -308,6 +299,22 @@ func handleRoleServiceSaveRolePermission(s RoleServiceHttpServer) http.HandleFun } } +func handleMenuServiceGetMenus(s MenuServiceHttpServer) http.HandleFunc { + return func(ctx *http.Context) (err error) { + req := &GetMenuRequest{} + + if res, err := s.GetMenus(ctx.Context(), req); err != nil { + if er, ok := err.(*errors.Error); ok { + return ctx.Error(er.Code, er.Message) + } else { + return ctx.Error(errors.Unavailable, err.Error()) + } + } else { + return ctx.Success(res) + } + } +} + func handleMenuServiceGetMenuLevelLabels(s MenuServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &GetMenuLevelLabelsRequest{} @@ -327,11 +334,9 @@ func handleMenuServiceGetMenuLevelLabels(s MenuServiceHttpServer) http.HandleFun func handleAuthServiceLogin(s AuthServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &LoginRequest{} - if err := ctx.Bind(req); err != nil { return ctx.Error(errors.Invalid, err.Error()) } - if res, err := s.Login(ctx.Context(), req); err != nil { if er, ok := err.(*errors.Error); ok { return ctx.Error(er.Code, er.Message) @@ -347,11 +352,9 @@ func handleAuthServiceLogin(s AuthServiceHttpServer) http.HandleFunc { func handleAuthServiceLogout(s AuthServiceHttpServer) http.HandleFunc { return func(ctx *http.Context) (err error) { req := &LogoutRequest{} - if err := ctx.Bind(req); err != nil { return ctx.Error(errors.Invalid, err.Error()) } - if res, err := s.Logout(ctx.Context(), req); err != nil { if er, ok := err.(*errors.Error); ok { return ctx.Error(er.Code, er.Message) @@ -417,6 +420,9 @@ func RegisterRoleServiceRouter(hs *http.Server, s RoleServiceHttpServer) { func RegisterMenuServiceRouter(hs *http.Server, s MenuServiceHttpServer) { + // Register handle GetMenus route + hs.GET("/menu/list", handleMenuServiceGetMenus(s)) + // Register handle GetMenuLevelLabels route hs.GET("/menu/level-labels", handleMenuServiceGetMenuLevelLabels(s)) diff --git a/pb/organize_model.pb.go b/pb/organize_model.pb.go index f316d2a..1a6e05d 100644 --- a/pb/organize_model.pb.go +++ b/pb/organize_model.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-aeus. DO NOT EDIT. // source: organize.proto -// date: 2025-06-19 11:06:34 +// date: 2025-06-22 11:09:05 package pb @@ -12,7 +12,7 @@ type MenuModel struct { Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey;column:id" comment:"菜单ID"` CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" gorm:"column:created_at" comment:"创建时间" scenarios:"view;export"` UpdatedAt int64 `json:"updated_at" yaml:"updatedAt" xml:"updatedAt" gorm:"index;column:updated_at" comment:"更新时间" scenarios:"view;export"` - Parent string `json:"parent" yaml:"parent" xml:"parent" gorm:"index;size:60;column:parent" comment:"父级菜单" format:"menu" props:"readonly:update" live:"type:dropdown;url:/menu/level-labels"` + Parent string `json:"parent" yaml:"parent" xml:"parent" gorm:"index;size:60;column:parent" comment:"父级菜单" scenarios:"create;update;view;export" format:"menu" props:"readonly:update" live:"type:dropdown;url:/menu/level-labels"` Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60;column:name" comment:"组件名称" props:"readonly:update" rule:"unique;required"` Label string `json:"label" yaml:"label" xml:"label" gorm:"size:120;column:label" comment:"菜单标题" rule:"required"` Uri string `json:"uri" yaml:"uri" xml:"uri" gorm:"size:512;column:uri" comment:"菜单链接" scenarios:"create;update;view;export" rule:"required"` @@ -20,7 +20,7 @@ type MenuModel struct { Icon string `json:"icon" yaml:"icon" xml:"icon" gorm:"size:60;column:icon" comment:"菜单图标" scenarios:"create;update;view;export"` Hidden bool `json:"hidden" yaml:"hidden" xml:"hidden" gorm:"column:hidden" comment:"是否隐藏" scenarios:"create;update;view;export"` Public bool `json:"public" yaml:"public" xml:"public" gorm:"column:public" comment:"是否公开" scenarios:"create;update;view;export"` - Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024;column:description" comment:"备注说明" scenarios:"create;update;view;export;list" format:"textarea"` + Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024;column:description" comment:"备注说明" scenarios:"create;update;view;export" format:"textarea"` Position int64 `json:"position" yaml:"position" xml:"position" gorm:"column:position" comment:"排序" scenarios:"create;update"` } diff --git a/pb/system_http.pb.go b/pb/system_http.pb.go index 3a75ef5..169bde5 100644 --- a/pb/system_http.pb.go +++ b/pb/system_http.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-aeus. DO NOT EDIT. // source: system.proto -// date: 2025-06-19 11:06:34 +// date: 2025-06-22 11:09:05 package pb @@ -11,7 +11,7 @@ import ( ) type SettingServiceHttpServer interface { - GetSetting(context.Context, *GetSettingRequest) (*GetSettingResponse, error) + GetSetting(ctx context.Context, req *GetSettingRequest) (res *GetSettingResponse, err error) } func handleSettingServiceGetSetting(s SettingServiceHttpServer) http.HandleFunc { diff --git a/pb/system_model.pb.go b/pb/system_model.pb.go index 40d0004..21594fd 100644 --- a/pb/system_model.pb.go +++ b/pb/system_model.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-aeus. DO NOT EDIT. // source: system.proto -// date: 2025-06-19 11:06:34 +// date: 2025-06-22 11:09:05 package pb diff --git a/permission.go b/permission.go index 568abe6..fccb28d 100644 --- a/permission.go +++ b/permission.go @@ -5,6 +5,8 @@ import ( "slices" "git.nobla.cn/golang/aeus-admin/internal/logic" + "git.nobla.cn/golang/aeus-admin/models" + "git.nobla.cn/golang/aeus-admin/types" "git.nobla.cn/golang/aeus/middleware/auth" "git.nobla.cn/golang/aeus/pkg/cache" "git.nobla.cn/golang/aeus/pkg/errors" @@ -12,8 +14,9 @@ import ( ) type PermissionChecker struct { - db *gorm.DB - logic *logic.User + db *gorm.DB + user *logic.User + role *logic.Role } func (p *PermissionChecker) CheckPermission(ctx context.Context, permission string) (err error) { @@ -21,14 +24,30 @@ func (p *PermissionChecker) CheckPermission(ctx context.Context, permission stri uid string ps []string ) - if claims, ok := auth.FromContext(ctx); !ok { + claims, ok := auth.FromContext(ctx) + if !ok { return errors.ErrAccessDenied - } else { - if uid, err = claims.GetSubject(); err != nil { + } + if cl, ok := claims.(*types.Claims); ok { + if cl.Admin { return + } else { + var pms []*models.Permission + if pms, err = p.role.GetPermissions(ctx, cl.Role); err == nil { + for _, pm := range pms { + if pm.Permission == permission { + return + } + } + } else { + return errors.ErrPermissionDenied + } } } - if ps, err = p.logic.GetPermissions(ctx, uid); err != nil { + if uid, err = claims.GetSubject(); err != nil { + return + } + if ps, err = p.user.GetPermissions(ctx, uid); err != nil { return } if !slices.Contains(ps, permission) { @@ -39,7 +58,8 @@ func (p *PermissionChecker) CheckPermission(ctx context.Context, permission stri func NewPermissionChecker(db *gorm.DB, ch cache.Cache) *PermissionChecker { return &PermissionChecker{ - db: db, - logic: logic.NewUserLogic(db, ch), + db: db, + user: logic.NewUserLogic(db, ch), + role: logic.NewRoleLogic(db, ch), } } diff --git a/pkg/dbcache/cache.go b/pkg/dbcache/cache.go index b53c30c..731c813 100644 --- a/pkg/dbcache/cache.go +++ b/pkg/dbcache/cache.go @@ -23,9 +23,9 @@ type ( CacheOption func(o *CacheOptions) cacheEntry[T any] struct { - Value T - CompareValue string - CreatedAt int64 + Value T `json:"v"` + CompareValue string `json:"d"` + CreatedAt int64 `json:"t"` } ) diff --git a/server.go b/server.go index 06172fc..82a3141 100644 --- a/server.go +++ b/server.go @@ -250,23 +250,6 @@ func initModels(ctx context.Context, o *options) (err error) { return } -// AutoMigrate 自动生成一个模型的schema和权限的定义 -func AutoMigrate(ctx context.Context, db *gorm.DB, model any, cbs ...Option) (err error) { - var ( - mv *rest.Model - ) - opts := newOptions(cbs...) - if mm, ok := model.(adminTypes.ModuleModel); ok { - moduleName := mm.ModuleName() - opts.restOpts = append(opts.restOpts, rest.WithModuleName(moduleName)) - } - if mv, err = rest.AutoMigrate(ctx, model, opts.restOpts...); err != nil { - return - } - err = checkModel(opts, mv) - return -} - func registerRESTRoute(domain string, db *gorm.DB, hs *http.Server) { handleListSchemas := func(ctx *http.Context) (err error) { var ( @@ -357,6 +340,32 @@ func registerRESTRoute(domain string, db *gorm.DB, hs *http.Server) { } +// AutoMigrate 自动生成一个模型的schema和权限的定义 +func AutoMigrate(ctx context.Context, db *gorm.DB, model any, cbs ...Option) (err error) { + var ( + mv *rest.Model + ) + opts := newOptions(cbs...) + if mm, ok := model.(adminTypes.ModuleModel); ok { + moduleName := mm.ModuleName() + opts.restOpts = append(opts.restOpts, rest.WithModuleName(moduleName)) + } + if err = db.AutoMigrate(model); err != nil { + return + } + if mv, err = rest.AutoMigrate(ctx, model, opts.restOpts...); err != nil { + return + } + if err = checkModel(opts, mv); err == nil { + if opts.vuePath != "" { + if err = generateVueFile(opts.vuePath, opts.apiPrefix, mv); err != nil { + return + } + } + } + return +} + // Init 初始化模块 func Init(ctx context.Context, cbs ...Option) (err error) { opts := newOptions(cbs...) diff --git a/service/auth.go b/service/auth.go index 4bf0b13..913f9ea 100644 --- a/service/auth.go +++ b/service/auth.go @@ -148,6 +148,7 @@ func (s *AuthService) Login(ctx context.Context, req *pb.LoginRequest) (res *pb. claims := types.Claims{ Uid: model.Uid, Role: model.Role, + Admin: model.Admin, IssuedAt: time.Now().Unix(), ExpirationAt: time.Now().Add(time.Second * time.Duration(s.opts.ttl)).Unix(), } diff --git a/service/menu.go b/service/menu.go index 3bcef87..98ae305 100644 --- a/service/menu.go +++ b/service/menu.go @@ -35,6 +35,24 @@ func WithMenuDB(db *gorm.DB) MenuOption { } } +func (s *MenuService) recursiveMenuValue(parent string, items []*models.Menu) []*pb.MenuValue { + values := make([]*pb.MenuValue, 0, len(items)) + for _, row := range items { + if row.Parent == parent { + item := &pb.MenuValue{ + Id: row.Id, + Parent: row.Parent, + Name: row.Name, + Label: row.Label, + Children: make([]*pb.MenuValue, 0), + } + item.Children = append(item.Children, s.recursiveMenuValue(row.Name, items)...) + values = append(values, item) + } + } + return values +} + func (s *MenuService) recursiveMenuLevel(parent string, items []*models.Menu) []*pb.MenuLevelValue { values := make([]*pb.MenuLevelValue, 0, len(items)) for _, row := range items { @@ -51,6 +69,19 @@ func (s *MenuService) recursiveMenuLevel(parent string, items []*models.Menu) [] return values } +func (s *MenuService) GetMenus(ctx context.Context, req *pb.GetMenuRequest) (res *pb.GetMenuResponse, err error) { + var ( + items []*models.Menu + ) + if items, err = s.logic.GetMenus(ctx); err != nil { + return + } + res = &pb.GetMenuResponse{ + Data: s.recursiveMenuValue("", items), + } + return +} + func (s *MenuService) GetMenuLevelLabels(ctx context.Context, req *pb.GetMenuLevelLabelsRequest) (res *pb.GetMenuLevelLabelsResponse, err error) { var ( items []*models.Menu diff --git a/service/user.go b/service/user.go index d2af537..6315301 100644 --- a/service/user.go +++ b/service/user.go @@ -102,7 +102,7 @@ func (s *UserService) recursiveNestedMenu(ctx context.Context, parent string, pe return values } -func (s *UserService) GetMenus(ctx context.Context, req *pb.GetMenuRequest) (res *pb.GetMenuResponse, err error) { +func (s *UserService) GetMenus(ctx context.Context, req *pb.GetUserMenuRequest) (res *pb.GetUserMenuResponse, err error) { var ( uid string permissions []*models.Permission @@ -110,14 +110,14 @@ func (s *UserService) GetMenus(ctx context.Context, req *pb.GetMenuRequest) (res if uid, err = s.getUidFromContext(ctx); err != nil { return } - res = &pb.GetMenuResponse{} + res = &pb.GetUserMenuResponse{} res.Data, err = dbcache.TryCache(ctx, fmt.Sprintf("user:menu:%s:%v", uid, req.Permission), func(tx *gorm.DB) ([]*pb.MenuItem, error) { var ( userModel *models.User menus []*models.Menu ) userModel = &models.User{} - if err = tx.Where("uid=?", uid).First(userModel).Error; err != nil { + if err = tx.Where("`uid`=?", uid).First(userModel).Error; err != nil { return nil, err } if menus, err = s.menu.GetMenus(ctx); err != nil { diff --git a/types/claims.go b/types/claims.go index d7b45f7..fdbff03 100644 --- a/types/claims.go +++ b/types/claims.go @@ -9,6 +9,7 @@ import ( type Claims struct { Uid string `json:"uid"` Role string `json:"uro"` + Admin bool `json:"uab"` Issuer string `json:"iss"` IssuedAt int64 `json:"iat"` ExpirationAt int64 `json:"exp"`