ctxhelper.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package ctxhelper
  2. import (
  3. "context"
  4. "math"
  5. "perms-system-server/internal/consts"
  6. "perms-system-server/internal/loaders"
  7. "perms-system-server/internal/middleware"
  8. )
  9. func SuperAdminCtx() context.Context {
  10. return middleware.WithUserDetails(context.Background(), &loaders.UserDetails{
  11. UserId: 1,
  12. Username: "superadmin",
  13. IsSuperAdmin: true,
  14. MemberType: consts.MemberTypeSuperAdmin,
  15. Status: consts.StatusEnabled,
  16. ProductCode: "test_product",
  17. MinPermsLevel: math.MaxInt64,
  18. })
  19. }
  20. func SuperAdminCtxWithUserId(userId int64) context.Context {
  21. return middleware.WithUserDetails(context.Background(), &loaders.UserDetails{
  22. UserId: userId,
  23. Username: "superadmin",
  24. IsSuperAdmin: true,
  25. MemberType: consts.MemberTypeSuperAdmin,
  26. Status: consts.StatusEnabled,
  27. ProductCode: "test_product",
  28. MinPermsLevel: math.MaxInt64,
  29. })
  30. }
  31. func AdminCtx(productCode string) context.Context {
  32. return middleware.WithUserDetails(context.Background(), &loaders.UserDetails{
  33. UserId: 2,
  34. Username: "admin",
  35. IsSuperAdmin: false,
  36. MemberType: consts.MemberTypeAdmin,
  37. Status: consts.StatusEnabled,
  38. ProductCode: productCode,
  39. DeptId: 1,
  40. DeptPath: "/1/",
  41. MinPermsLevel: math.MaxInt64,
  42. })
  43. }
  44. func DeveloperCtx(productCode string) context.Context {
  45. return middleware.WithUserDetails(context.Background(), &loaders.UserDetails{
  46. UserId: 3,
  47. Username: "developer",
  48. IsSuperAdmin: false,
  49. MemberType: consts.MemberTypeDeveloper,
  50. Status: consts.StatusEnabled,
  51. ProductCode: productCode,
  52. DeptId: 1,
  53. DeptPath: "/1/",
  54. MinPermsLevel: math.MaxInt64,
  55. })
  56. }
  57. func MemberCtx(productCode string) context.Context {
  58. return middleware.WithUserDetails(context.Background(), &loaders.UserDetails{
  59. UserId: 4,
  60. Username: "member",
  61. IsSuperAdmin: false,
  62. MemberType: consts.MemberTypeMember,
  63. Status: consts.StatusEnabled,
  64. ProductCode: productCode,
  65. DeptId: 1,
  66. DeptPath: "/1/",
  67. MinPermsLevel: 100,
  68. })
  69. }
  70. func CustomCtx(ud *loaders.UserDetails) context.Context {
  71. return middleware.WithUserDetails(context.Background(), ud)
  72. }