Skip to content

Commit

Permalink
Merge pull request #16 from 7Cav/15-discordid-and-keycloakid-return-j…
Browse files Browse the repository at this point in the history
…unk-data-if-an-invalid-id-is-passed

15 discordid and keycloakid return junk data if an invalid id is passed
  • Loading branch information
SyniRon authored Jan 6, 2025
2 parents 24dcc03 + 7d58a0a commit 7c9fe8b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
18 changes: 16 additions & 2 deletions datastores/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,19 @@ func (ds Mysql) FindProfileByKeycloakID(keycloakId string) (*proto.Profile, erro

query := map[string]interface{}{"xf_user_connected_account.provider_key": keycloakId, "xf_user_connected_account.provider": "keycloak"}

ds.Db.Preload(clause.Associations).
result := ds.Db.Preload(clause.Associations).
Preload("AwardRecords.Award").
Joins(xenforo.ConnectedAccountJoin).
Where(query).
First(&profile)

if result.Error != nil {
if result.Error == gorm.ErrRecordNotFound {
return nil, fmt.Errorf("no profile found for KeycloakID: %s", keycloakId)
}
return nil, result.Error
}

milpac, err := ds.generateProtoProfile(profile)

if err != nil {
Expand All @@ -127,12 +134,19 @@ func (ds Mysql) FindProfileByDiscordID(discordId string) (*proto.Profile, error)

query := map[string]interface{}{"xf_user_connected_account.provider_key": discordId, "xf_user_connected_account.provider": "nfDiscord"}

ds.Db.Preload(clause.Associations).
result := ds.Db.Preload(clause.Associations).
Preload("AwardRecords.Award").
Joins(xenforo.ConnectedAccountJoin).
Where(query).
First(&profile)

if result.Error != nil {
if result.Error == gorm.ErrRecordNotFound {
return nil, fmt.Errorf("no profile found for discordID: %s", discordId)
}
return nil, result.Error
}

milpac, err := ds.generateProtoProfile(profile)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion proto/milpacs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/milpacs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import "protoc-gen-openapiv2/options/annotations.proto";
// These annotations are used when generating the OpenAPI file.
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {
version: "1.1.1";
version: "1.1.2";
};
external_docs: {
url: "https://github.com/7cav/api";
Expand Down
6 changes: 3 additions & 3 deletions servers/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (server *MilpacsService) GetRoster(ctx context.Context, request *proto.Rost
roster, err := server.Datastore.FindRosterByType(request.Roster)

if err != nil {
return &proto.Roster{}, status.Errorf(codes.NotFound, "no roster found for %", request.Roster)
return &proto.Roster{}, status.Errorf(codes.NotFound, "no roster found for %s", request.Roster)
}

return roster, nil
Expand All @@ -86,7 +86,7 @@ func (server *MilpacsService) GetUserViaKeycloakId(ctx context.Context, request
profile, err := server.Datastore.FindProfileByKeycloakID(request.GetKeycloakId())

if err != nil {
return &proto.Profile{}, status.Errorf(codes.NotFound, "no user found for %", request.GetKeycloakId())
return &proto.Profile{}, status.Errorf(codes.NotFound, "no user found for keycloakid: %s", request.GetKeycloakId())
}

return profile, nil
Expand All @@ -101,7 +101,7 @@ func (server *MilpacsService) GetUserViaDiscordId(ctx context.Context, request *
profile, err := server.Datastore.FindProfileByDiscordID(request.GetDiscordId())

if err != nil {
return &proto.Profile{}, status.Errorf(codes.NotFound, "no user found for %", request.GetDiscordId())
return &proto.Profile{}, status.Errorf(codes.NotFound, "no user found for discordid: %s", request.GetDiscordId())
}

return profile, nil
Expand Down
2 changes: 1 addition & 1 deletion third_party/OpenAPI/milpacs.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"swagger": "2.0",
"info": {
"title": "milpacs.proto",
"version": "1.1.1"
"version": "1.1.2"
},
"tags": [
{
Expand Down

0 comments on commit 7c9fe8b

Please sign in to comment.