Unverified Commit 378dab63 authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Add storageList caller id param (#1083)

parent 31c380b1
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -6,16 +6,13 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
## [Unreleased]
### Changed
- Use Steam partner API instead of public API for Steam profiles and friends requests.

### Fixed
- Fix linter-found test issue.
- Fix storage index listing results sometimes being returned with incorrect order.

### Changed
- Add create_time and update_time to returned storage engine writes acks.
- Add storage index create flag to read only from the index.
- Add caller id param to storage listing and storage index listing runtime APIs.

### Fixed
- Fix linter-found test issue.
- Fix storage index listing results sometimes being returned with incorrect order.
- Fixes calculation of leaderboard and tournament times for rare types of CRON expressions that don't execute at a fixed interval.
- Improved how start and end times are calculated for tournaments occuring in the future.

+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ require (
	github.com/gorilla/mux v1.8.0
	github.com/gorilla/websocket v1.5.0
	github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0
	github.com/heroiclabs/nakama-common v1.28.2-0.20231010141902-2a5051b58ac5
	github.com/heroiclabs/nakama-common v1.28.2-0.20231010150216-b178843845fa
	github.com/jackc/pgconn v1.14.0
	github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
	github.com/jackc/pgtype v1.14.0
+2 −2
+35 −9
Original line number Diff line number Diff line
@@ -1867,6 +1867,7 @@ func (n *RuntimeGoNakamaModule) WalletLedgerList(ctx context.Context, userID str
// @group storage
// @summary List records in a collection and page through results. The records returned can be filtered to those owned by the user or "" for public records.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param callerId(type=string) User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permissions are bypassed.
// @param userId(type=string) User ID to list records for or "" (empty string) for public records.
// @param collection(type=string) Collection to list data from.
// @param limit(type=int, optional=true, default=100) Limit number of records retrieved.
@@ -1874,7 +1875,16 @@ func (n *RuntimeGoNakamaModule) WalletLedgerList(ctx context.Context, userID str
// @return objects([]*api.StorageObject) A list of storage objects.
// @return cursor(string) Pagination cursor. Will be set to "" or nil when fetching last available page.
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeGoNakamaModule) StorageList(ctx context.Context, userID, collection string, limit int, cursor string) ([]*api.StorageObject, string, error) {
func (n *RuntimeGoNakamaModule) StorageList(ctx context.Context, callerID, userID, collection string, limit int, cursor string) ([]*api.StorageObject, string, error) {
	cid := uuid.Nil
	if callerID != "" {
		u, err := uuid.FromString(callerID)
		if err != nil {
			return nil, "", errors.New("expects an empty or valid caller id")
		}
		cid = u
	}

	var uid *uuid.UUID
	if userID != "" {
		u, err := uuid.FromString(userID)
@@ -1888,7 +1898,7 @@ func (n *RuntimeGoNakamaModule) StorageList(ctx context.Context, userID, collect
		return nil, "", errors.New("limit must not be negative")
	}

	objectList, _, err := StorageListObjects(ctx, n.logger, n.db, uuid.Nil, uid, collection, limit, cursor)
	objectList, _, err := StorageListObjects(ctx, n.logger, n.db, cid, uid, collection, limit, cursor)
	if err != nil {
		return nil, "", err
	}
@@ -2047,19 +2057,30 @@ func (n *RuntimeGoNakamaModule) StorageDelete(ctx context.Context, deletes []*ru
// @group storage
// @summary List storage index entries
// @param indexName(type=string) Name of the index to list entries from.
// @param callerId(type=string) User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permissions are bypassed.
// @param queryString(type=string) Query to filter index entries.
// @param limit(type=int) Maximum number of results to be returned.
// @return objects(*api..StorageObjectList) A list of storage objects.
// @return error(error) An optional error value if an error occurred.
func (n *RuntimeGoNakamaModule) StorageIndexList(ctx context.Context, indexName, query string, limit int) (*api.StorageObjects, error) {
func (n *RuntimeGoNakamaModule) StorageIndexList(ctx context.Context, callerID, indexName, query string, limit int) (*api.StorageObjects, error) {
	cid := uuid.Nil
	if callerID != "" {
		id, err := uuid.FromString(callerID)
		if err != nil {
			return nil, errors.New("expects caller id to be empty or a valid user id")
		}
		cid = id
	}

	if indexName == "" {
		return nil, errors.New("expects a non-empty indexName")
	}

	if limit < 1 || limit > 100 {
		return nil, errors.New("limit must be 1-100")
	}

	return n.storageIndex.List(ctx, indexName, query, limit)
	return n.storageIndex.List(ctx, cid, indexName, query, limit)
}

// @group users
@@ -3297,6 +3318,7 @@ func (n *RuntimeGoNakamaModule) GroupUserLeave(ctx context.Context, groupID, use
// @group groups
// @summary Add users to a group.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param callerId(type=string) User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permissions are bypassed.
// @param groupId(type=string) The ID of the group to add users to.
// @param userIds(type=[]string) Table array of user IDs to add to this group.
// @return error(error) An optional error value if an error occurred.
@@ -3305,7 +3327,7 @@ func (n *RuntimeGoNakamaModule) GroupUsersAdd(ctx context.Context, callerID, gro
	if callerID != "" {
		var err error
		if caller, err = uuid.FromString(callerID); err != nil {
			return errors.New("expects caller ID to be a valid identifier")
			return errors.New("expects caller ID to be empty or a valid identifier")
		}
	}

@@ -3336,6 +3358,7 @@ func (n *RuntimeGoNakamaModule) GroupUsersAdd(ctx context.Context, callerID, gro
// @group groups
// @summary Ban users from a group.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param callerId(type=string) User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permissions are bypassed.
// @param groupId(type=string) The ID of the group to ban users from.
// @param userIds(type=[]string) Table array of user IDs to ban from this group.
// @return error(error) An optional error value if an error occurred.
@@ -3344,7 +3367,7 @@ func (n *RuntimeGoNakamaModule) GroupUsersBan(ctx context.Context, callerID, gro
	if callerID != "" {
		var err error
		if caller, err = uuid.FromString(callerID); err != nil {
			return errors.New("expects caller ID to be a valid identifier")
			return errors.New("expects caller ID to be empty or a valid identifier")
		}
	}

@@ -3375,6 +3398,7 @@ func (n *RuntimeGoNakamaModule) GroupUsersBan(ctx context.Context, callerID, gro
// @group groups
// @summary Kick users from a group.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param callerId(type=string) User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permissions are bypassed.
// @param groupId(type=string) The ID of the group to kick users from.
// @param userIds(type=[]string) Table array of user IDs to kick.
// @return error(error) An optional error value if an error occurred.
@@ -3383,7 +3407,7 @@ func (n *RuntimeGoNakamaModule) GroupUsersKick(ctx context.Context, callerID, gr
	if callerID != "" {
		var err error
		if caller, err = uuid.FromString(callerID); err != nil {
			return errors.New("expects caller ID to be a valid identifier")
			return errors.New("expects caller ID to be empty or a valid identifier")
		}
	}

@@ -3414,6 +3438,7 @@ func (n *RuntimeGoNakamaModule) GroupUsersKick(ctx context.Context, callerID, gr
// @group groups
// @summary Promote users in a group.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param callerId(type=string) User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permissions are bypassed.
// @param groupId(type=string) The ID of the group whose members are being promoted.
// @param userIds(type=[]string) Table array of user IDs to promote.
// @return error(error) An optional error value if an error occurred.
@@ -3422,7 +3447,7 @@ func (n *RuntimeGoNakamaModule) GroupUsersPromote(ctx context.Context, callerID,
	if callerID != "" {
		var err error
		if caller, err = uuid.FromString(callerID); err != nil {
			return errors.New("expects caller ID to be a valid identifier")
			return errors.New("expects caller ID to be empty or a valid identifier")
		}
	}

@@ -3453,6 +3478,7 @@ func (n *RuntimeGoNakamaModule) GroupUsersPromote(ctx context.Context, callerID,
// @group groups
// @summary Demote users in a group.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param callerId(type=string) User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permissions are bypassed.
// @param groupId(type=string) The ID of the group whose members are being demoted.
// @param userIds(type=[]string) Table array of user IDs to demote.
// @return error(error) An optional error value if an error occurred.
@@ -3461,7 +3487,7 @@ func (n *RuntimeGoNakamaModule) GroupUsersDemote(ctx context.Context, callerID,
	if callerID != "" {
		var err error
		if caller, err = uuid.FromString(callerID); err != nil {
			return errors.New("expects caller ID to be a valid identifier")
			return errors.New("expects caller ID to be empty or a valid identifier")
		}
	}

+27 −2
Original line number Diff line number Diff line
@@ -345,6 +345,7 @@ func (n *runtimeJavascriptNakamaModule) stringToBinary(r *goja.Runtime) func(goj
// @param indexName(type=string) Name of the index to list entries from.
// @param queryString(type=string) Query to filter index entries.
// @param limit(type=int) Maximum number of results to be returned.
// @param callerId(type=string) Optional User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed.
// @return objects(nkruntime.StorageObjectList) A list of storage objects.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) storageIndexList(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
@@ -358,8 +359,17 @@ func (n *runtimeJavascriptNakamaModule) storageIndexList(r *goja.Runtime) func(g
				panic(r.NewTypeError("limit must be 1-100"))
			}
		}
		callerID := uuid.Nil
		if !goja.IsUndefined(f.Argument(3)) && !goja.IsNull(f.Argument(3)) {
			callerIdStr := getJsString(r, f.Argument(3))
			cid, err := uuid.FromString(callerIdStr)
			if err != nil {
				panic(r.NewTypeError("expects caller id to be valid identifier"))
			}
			callerID = cid
		}

		objectList, err := n.storageIndex.List(n.ctx, idxName, queryString, int(limit))
		objectList, err := n.storageIndex.List(n.ctx, callerID, idxName, queryString, int(limit))
		if err != nil {
			panic(r.NewGoError(fmt.Errorf("failed to lookup storage index: %s", err.Error())))
		}
@@ -4248,7 +4258,17 @@ func (n *runtimeJavascriptNakamaModule) storageList(r *goja.Runtime) func(goja.F
			cursor = getJsString(r, f.Argument(3))
		}

		objectList, _, err := StorageListObjects(n.ctx, n.logger, n.db, uuid.Nil, uid, collection, limit, cursor)
		callerID := uuid.Nil
		if !goja.IsUndefined(f.Argument(4)) && !goja.IsNull(f.Argument(4)) {
			callerIdStr := getJsString(r, f.Argument(4))
			cid, err := uuid.FromString(callerIdStr)
			if err != nil {
				panic(r.NewTypeError("expects caller id to be valid identifier"))
			}
			callerID = cid
		}

		objectList, _, err := StorageListObjects(n.ctx, n.logger, n.db, callerID, uid, collection, limit, cursor)
		if err != nil {
			panic(r.NewGoError(fmt.Errorf("failed to list storage objects: %s", err.Error())))
		}
@@ -6771,6 +6791,7 @@ func (n *runtimeJavascriptNakamaModule) groupDelete(r *goja.Runtime) func(goja.F
// @summary Kick users from a group.
// @param groupId(type=string) The ID of the group to kick users from.
// @param userIds(type=string[]) Table array of user IDs to kick.
// @param callerId(type=string) Optional User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) groupUsersKick(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -7446,6 +7467,7 @@ func (n *runtimeJavascriptNakamaModule) groupUserLeave(r *goja.Runtime) func(goj
// @summary Add users to a group.
// @param groupId(type=string) The ID of the group to add users to.
// @param userIds(type=string[]) Table array of user IDs to add to this group.
// @param callerId(type=string) Optional User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) groupUsersAdd(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -7508,6 +7530,7 @@ func (n *runtimeJavascriptNakamaModule) groupUsersAdd(r *goja.Runtime) func(goja
// @summary Ban users from a group.
// @param groupId(string) The ID of the group to ban users from.
// @param userIds(string[]) Table array of user IDs to ban from this group.
// @param callerId(type=string) Optional User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) groupUsersBan(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -7570,6 +7593,7 @@ func (n *runtimeJavascriptNakamaModule) groupUsersBan(r *goja.Runtime) func(goja
// @summary Promote users in a group.
// @param groupId(type=string) The ID of the group whose members are being promoted.
// @param userIds(type=string[]) Table array of user IDs to promote.
// @param callerId(type=string) Optional User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) groupUsersPromote(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
@@ -7632,6 +7656,7 @@ func (n *runtimeJavascriptNakamaModule) groupUsersPromote(r *goja.Runtime) func(
// @summary Demote users in a group.
// @param groupId(type=string) The ID of the group whose members are being demoted.
// @param userIds(type=string[]) Table array of user IDs to demote.
// @param callerId(type=string) Optional User ID of the caller, will apply permissions checks of the user. If empty defaults to system user and permission checks are bypassed.
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) groupUsersDemote(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
Loading