mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 00:34:28 +08:00
support modifying user feature restriction by cli
This commit is contained in:
@@ -238,6 +238,57 @@ func (l *UserDataCli) DisableUser(c *core.CliContext, username string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUserFeatureRestrictions sets user feature restrictions according to the specified user name
|
||||
func (l *UserDataCli) SetUserFeatureRestrictions(c *core.CliContext, username string, featureRestriction core.UserFeatureRestrictions) error {
|
||||
if username == "" {
|
||||
log.CliErrorf(c, "[user_data.SetUserFeatureRestrictions] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
err := l.users.UpdateUserFeatureRestriction(c, username, featureRestriction)
|
||||
|
||||
if err != nil {
|
||||
log.CliErrorf(c, "[user_data.SetUserFeatureRestrictions] failed to set user feature restrictions by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddUserFeatureRestrictions adds user feature restrictions according to the specified user name
|
||||
func (l *UserDataCli) AddUserFeatureRestrictions(c *core.CliContext, username string, featureRestriction core.UserFeatureRestrictions) error {
|
||||
if username == "" {
|
||||
log.CliErrorf(c, "[user_data.AddUserFeatureRestrictions] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
err := l.users.AddUserFeatureRestriction(c, username, featureRestriction)
|
||||
|
||||
if err != nil {
|
||||
log.CliErrorf(c, "[user_data.AddUserFeatureRestrictions] failed to add user feature restrictions by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveUserFeatureRestrictions removes user feature restrictions according to the specified user name
|
||||
func (l *UserDataCli) RemoveUserFeatureRestrictions(c *core.CliContext, username string, featureRestriction core.UserFeatureRestrictions) error {
|
||||
if username == "" {
|
||||
log.CliErrorf(c, "[user_data.RemoveUserFeatureRestrictions] user name is empty")
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
err := l.users.RemoveUserFeatureRestriction(c, username, featureRestriction)
|
||||
|
||||
if err != nil {
|
||||
log.CliErrorf(c, "[user_data.RemoveUserFeatureRestrictions] failed to remove user feature restrictions by user name \"%s\", because %s", username, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResendVerifyEmail resends an email with account activation link
|
||||
func (l *UserDataCli) ResendVerifyEmail(c *core.CliContext, username string) error {
|
||||
if !l.CurrentConfig().EnableUserVerifyEmail {
|
||||
|
||||
@@ -471,6 +471,75 @@ func (s *UserService) DisableUser(c core.Context, username string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateUserFeatureRestriction sets user user feature restrictions
|
||||
func (s *UserService) UpdateUserFeatureRestriction(c core.Context, username string, featureRestriction core.UserFeatureRestrictions) error {
|
||||
if username == "" {
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
|
||||
updateModel := &models.User{
|
||||
FeatureRestriction: featureRestriction,
|
||||
UpdatedUnixTime: now,
|
||||
}
|
||||
|
||||
updatedRows, err := s.UserDB().NewSession(c).Cols("feature_restriction", "updated_unix_time").Where("username=? AND deleted=?", username, false).Update(updateModel)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if updatedRows < 1 {
|
||||
return errs.ErrUserNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddUserFeatureRestriction adds user user feature restrictions
|
||||
func (s *UserService) AddUserFeatureRestriction(c core.Context, username string, featureRestriction core.UserFeatureRestrictions) error {
|
||||
if username == "" {
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
|
||||
updateModel := &models.User{
|
||||
FeatureRestriction: featureRestriction,
|
||||
UpdatedUnixTime: now,
|
||||
}
|
||||
|
||||
updatedRows, err := s.UserDB().NewSession(c).SetExpr("feature_restriction", fmt.Sprintf("feature_restriction|(%d)", updateModel.FeatureRestriction)).Cols("updated_unix_time").Where("username=? AND deleted=?", username, false).Update(updateModel)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if updatedRows < 1 {
|
||||
return errs.ErrUserNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveUserFeatureRestriction removes user user feature restrictions
|
||||
func (s *UserService) RemoveUserFeatureRestriction(c core.Context, username string, featureRestriction core.UserFeatureRestrictions) error {
|
||||
if username == "" {
|
||||
return errs.ErrUsernameIsEmpty
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
|
||||
updateModel := &models.User{
|
||||
FeatureRestriction: ^featureRestriction,
|
||||
UpdatedUnixTime: now,
|
||||
}
|
||||
|
||||
updatedRows, err := s.UserDB().NewSession(c).SetExpr("feature_restriction", fmt.Sprintf("feature_restriction&(%d)", updateModel.FeatureRestriction)).Cols("updated_unix_time").Where("username=? AND deleted=?", username, false).Update(updateModel)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if updatedRows < 1 {
|
||||
return errs.ErrUserNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUserEmailVerified sets user email address verified
|
||||
func (s *UserService) SetUserEmailVerified(c core.Context, username string) error {
|
||||
if username == "" {
|
||||
|
||||
Reference in New Issue
Block a user