Documentation
¶
Index ¶
- Constants
- type BSON
- func (b BSON) GetAppID() string
- func (b BSON) GetCreatedAt() time.Time
- func (b BSON) GetCreator() string
- func (b BSON) GetFileID() string
- func (b BSON) GetID() string
- func (b BSON) GetRole() pb.Role
- func (b BSON) GetUpdatedAt() time.Time
- func (b BSON) GetUserID() string
- func (b BSON) MarshalProto(permission *pb.PermissionObject) error
- func (b *BSON) SetAppID(appID string) error
- func (b *BSON) SetCreator(creator string) error
- func (b *BSON) SetFileID(fileID string) error
- func (b *BSON) SetID(id string) error
- func (b *BSON) SetRole(role pb.Role) error
- func (b *BSON) SetUserID(userID string) error
- type Controller
- func (c Controller) CreatePermission(ctx context.Context, fileID string, userID string, role pb.Role, ...) (service.Permission, error)
- func (c Controller) DeleteFilePermissions(ctx context.Context, fileID string) ([]*pb.PermissionObject, error)
- func (c Controller) DeletePermission(ctx context.Context, fileID string, userID string) (service.Permission, error)
- func (c Controller) GetByFileAndUser(ctx context.Context, fileID string, userID string) (service.Permission, error)
- func (c Controller) GetFilePermissions(ctx context.Context, fileID string) ([]*pb.GetFilePermissionsResponse_UserRole, error)
- func (c Controller) GetPermissionByMongoID(ctx context.Context, mongoID string) (service.Permission, error)
- func (c Controller) GetUserPermissions(ctx context.Context, userID string, pageNum int64, pageSize int64, ...) (*pb.GetUserPermissionsResponse, error)
- func (c Controller) HealthCheck(ctx context.Context) (bool, error)
- type MongoStore
- func (s MongoStore) Create(ctx context.Context, permission service.Permission, override bool) (service.Permission, error)
- func (s MongoStore) Delete(ctx context.Context, filter interface{}) (service.Permission, error)
- func (s MongoStore) Get(ctx context.Context, filter interface{}) (service.Permission, error)
- func (s MongoStore) GetAll(ctx context.Context, filter interface{}) ([]service.Permission, error)
- func (s MongoStore) GetUserPermissionsByPage(ctx context.Context, pn int64, ps int64, sortBy bson.D, filter interface{}) (*PagingRes, error)
- func (s MongoStore) HealthCheck(ctx context.Context) (bool, error)
- type PagingRes
Constants ¶
const ( // MongoObjectIDField is the default mongodb unique key. MongoObjectIDField = "_id" // PermissionCollectionName is the name of the permissions collection. PermissionCollectionName = "permissions" // PermissionBSONFileIDField is the name of the fileID field in BSON. PermissionBSONFileIDField = "fileID" // PermissionBSONUserIDField is the name of the userID field in BSON. PermissionBSONUserIDField = "userID" // PermissionBSONRoleField is the name of the role field in BSON. PermissionBSONRoleField = "role" // PermissionBSONCreatorField is the name of the creator field in BSON. PermissionBSONCreatorField = "creator" // PermissionBSONAppIDField is the name of the appID field in BSON. PermissionBSONAppIDField = "appID" // PermissionBSONCreatedAtField is the name of the createdAt field in BSON. PermissionBSONCreatedAtField = "createdAt" // PermissionBSONUpdatedAtField is the name of the updatedAt field in BSON. PermissionBSONUpdatedAtField = "updatedAt" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BSON ¶
type BSON struct { ID primitive.ObjectID `bson:"_id,omitempty"` FileID string `bson:"fileID,omitempty"` UserID string `bson:"userID,omitempty"` Role pb.Role `bson:"role"` Creator string `bson:"creator"` AppID string `bson:"appID"` CreatedAt time.Time `bson:"createdAt" json:"createdAt,omitempty"` UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt,omitempty"` }
BSON is the structure that represents a permission as it's stored.
func (BSON) MarshalProto ¶
func (b BSON) MarshalProto(permission *pb.PermissionObject) error
MarshalProto marshals b into a permission.
func (*BSON) SetCreator ¶
SetCreator sets b.Creator to creator.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller is the permissions service business logic implementation using MongoStore.
func NewMongoController ¶
func NewMongoController(db *mongo.Database) (Controller, error)
NewMongoController returns a new controller.
func (Controller) CreatePermission ¶
func (c Controller) CreatePermission( ctx context.Context, fileID string, userID string, role pb.Role, creator string, override bool, appID string) (service.Permission, error)
CreatePermission creates a Permission in store and returns its unique ID.
func (Controller) DeleteFilePermissions ¶
func (c Controller) DeleteFilePermissions(ctx context.Context, fileID string) ([]*pb.PermissionObject, error)
DeleteFilePermissions deletes all permissions that exist for fileID and returns a slice of Permissions that were deleted.
func (Controller) DeletePermission ¶
func (c Controller) DeletePermission( ctx context.Context, fileID string, userID string, ) (service.Permission, error)
DeletePermission deletes the permission in store that matches fileID and userID and returns the deleted permission.
func (Controller) GetByFileAndUser ¶
func (c Controller) GetByFileAndUser( ctx context.Context, fileID string, userID string) (service.Permission, error)
GetByFileAndUser retrieves the permissoin that matches fileID and userID, and any error if occurred.
func (Controller) GetFilePermissions ¶
func (c Controller) GetFilePermissions(ctx context.Context, fileID string) ([]*pb.GetFilePermissionsResponse_UserRole, error)
GetFilePermissions returns a slice of UserRole, otherwise returns nil and any error if occurred.
func (Controller) GetPermissionByMongoID ¶
func (c Controller) GetPermissionByMongoID( ctx context.Context, mongoID string) (service.Permission, error)
GetPermissionByMongoID retrieves the permissoin by the recived mongo id.
func (Controller) GetUserPermissions ¶
func (c Controller) GetUserPermissions( ctx context.Context, userID string, pageNum int64, pageSize int64, isShared bool, appID string) (*pb.GetUserPermissionsResponse, error)
GetUserPermissions returns a slice of FileRole, otherwise returns nil and any error if occurred.
func (Controller) HealthCheck ¶
func (c Controller) HealthCheck(ctx context.Context) (bool, error)
HealthCheck runs store's healthcheck and returns true if healthy, otherwise returns false and any error if occurred.
type MongoStore ¶
MongoStore holds the mongodb database and implements Store interface.
func (MongoStore) Create ¶
func (s MongoStore) Create( ctx context.Context, permission service.Permission, override bool, ) (service.Permission, error)
Create creates a permission of a file to a user, If permission already exists then it's updated to have permission values, If successful returns the permission and a nil error, Override indicates whether to update the permission if already exists, or not and return error. otherwise returns empty string and non-nil error if any occurred.
func (MongoStore) Delete ¶
func (s MongoStore) Delete(ctx context.Context, filter interface{}) (service.Permission, error)
Delete finds the first permission that matches filter and deletes it, if successful returns the deleted permission, otherwise returns nil, and non-nil error if any occurred.
func (MongoStore) Get ¶
func (s MongoStore) Get(ctx context.Context, filter interface{}) (service.Permission, error)
Get finds one permission that matches filter, if successful returns the permission, and a nil error, if the permission is not found it would return nil and NotFound error, otherwise returns nil and non-nil error if any occurred.
func (MongoStore) GetAll ¶
func (s MongoStore) GetAll(ctx context.Context, filter interface{}) ([]service.Permission, error)
GetAll finds all permissions that matches filter, if successful returns the permissions, and a nil error, otherwise returns nil and non-nil error if any occurred.
func (MongoStore) GetUserPermissionsByPage ¶
func (s MongoStore) GetUserPermissionsByPage(ctx context.Context, pn int64, ps int64, sortBy bson.D, filter interface{}) (*PagingRes, error)
GetUserPermissionsByPage returns a slice of the permissions requested by the filter, in the page they belong to by page number and page size. sortBy is the field by which the sorting of the permissions will be committed, defaulting to reverse mongoID.
func (MongoStore) HealthCheck ¶
func (s MongoStore) HealthCheck(ctx context.Context) (bool, error)
HealthCheck checks the health of the service, returns true if healthy, or false otherwise.