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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manage user permissions #514

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dwradcliffe
Copy link
Contributor

@dwradcliffe dwradcliffe commented Sep 2, 2024

Part of #57

This adds the ability for an admin user to set permissions for each user. This does not allow these permissions to be used, that will be in the next PR.

@AnalogJ
Copy link
Member

AnalogJ commented Oct 3, 2024

Hey @dwradcliffe , just wanted to check in. Did you want me to review your PR, or is it still under development?

@dwradcliffe dwradcliffe marked this pull request as ready for review October 6, 2024 02:23
Comment on lines +216 to +223
user.Permissions = make(map[string]map[string]bool)

for _, acl := range acls {
if _, exists := user.Permissions[acl.TargetUserID.String()]; !exists {
user.Permissions[acl.TargetUserID.String()] = make(map[string]bool)
}
user.Permissions[acl.TargetUserID.String()][string(acl.Permission)] = true
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would be done with GORM Associations -- so we could use a single query.

https://gorm.io/docs/create.html#Create-With-Associations
https://gorm.io/docs/query.html#Joins-Preloading

if result.Error != nil {
return result.Error
}
// Update User Permissions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally this would all be handed by the GORM Association logic & hooks

Picture string `json:"picture"`
Email string `json:"email"`
Role pkg.UserRole `json:"role"`
Permissions map[string]map[string]bool `json:"permissions" gorm:"-:all"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use GORM references for this - https://gorm.io/docs/has_many.html#Override-References

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

Successfully merging this pull request may close these issues.

2 participants