From ae10e121875982d6956d6bff453544cc59a75616 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Tue, 12 Sep 2023 18:37:30 +0200 Subject: feat: Add admin control Now only admins can access settings. --- pkg/database/sql/user.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'pkg/database') diff --git a/pkg/database/sql/user.go b/pkg/database/sql/user.go index 2ec8622..0c503c2 100644 --- a/pkg/database/sql/user.go +++ b/pkg/database/sql/user.go @@ -158,20 +158,16 @@ func (self *UserRepository) Create(ctx context.Context, createUser *repository.C } func (self *UserRepository) Update(ctx context.Context, id uint, update *repository.UpdateUser) error { - user := &User{ - Model: gorm.Model{ - ID: id, - }, - Username: update.Username, - Name: update.Name, - IsAdmin: update.IsAdmin, - Path: update.Path, - } - result := self.db. WithContext(ctx). + Model(&User{}). Omit("password"). - Updates(user) + Where("id = ?", id). + Update("username", update.Username). + Update("name", update.Name). + Update("is_admin", update.IsAdmin). + Update("path", update.Path) + if result.Error != nil { return wrapError(result.Error) } -- cgit v1.2.3