Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 Feature Request: Hide relations and fields to not expose private and sensitive data #5746

Closed
acidjazz opened this issue Oct 9, 2022 · 3 comments
Assignees
Labels
type:feature_request feature request

Comments

@acidjazz
Copy link

acidjazz commented Oct 9, 2022

Describe the feature

Ability to hide fields and relations at runtime

Motivation

  • I want to expose an array of users as an endpoint but hide the Password field
  • I want to expose an array of a users auth sessions as an endpoint but hide the User relation

Currently I found the way to hide my User relation to my Session model involved doing something like:

type Session struct {
	models.Session
	User *models.User `json:"User,omitempty"`
}

func Token(c *fiber.Ctx) error {
	user := auth.User(c)
	var sessions []Session
	database.Db.Find(&sessions, "user_id = ?", user.ID)
	return render.Render(c, sessions)
}

I'm not sure how it'd be possible (still new to go) but I'd love to see something like one of these:

database.Db.Find(&sessions, "user_id = ?", user.ID).HideRelation("User")
database.Db.Find(&sessions, "user_id = ?", user.ID).HideRelation(models.User)

database.Db.Find(&users, "id = ?", user.ID).HideField("Password")
@github-actions github-actions bot added the type:feature_request feature request label Oct 9, 2022
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

@acidjazz
Copy link
Author

acidjazz commented Oct 5, 2023

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

馃憖

@a631807682
Copy link
Member

Hide the results that do not belong to gorm.

https://pkg.go.dev/encoding/json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature_request feature request
Projects
None yet
Development

No branches or pull requests

3 participants