Skip to content

Commit c628858

Browse files
committed
support disabling custom icon uploads for specified users
1 parent ee54fe3 commit c628858

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

conf/ezbookkeeping.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ max_user_avatar_size = 1048576
538538
# 15: OAuth 2.0 Login
539539
# 16: Unlink Third-party Login
540540
# 17: Generate API Token
541+
# 18: Create Transactions from AI Text Recognition
542+
# 18: Upload Custom Icon
541543
default_feature_restrictions =
542544

543545
[data]

pkg/api/user_custom_icons.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type UserCustomIconsApi struct {
2525
ApiUsingConfig
2626
ApiUsingDuplicateChecker
2727
icons *services.UserCustomIconService
28+
users *services.UserService
2829
}
2930

3031
// Initialize a user custom icons api singleton instance
@@ -40,6 +41,7 @@ var (
4041
container: duplicatechecker.Container,
4142
},
4243
icons: services.UserCustomIcons,
44+
users: services.Users,
4345
}
4446
)
4547

@@ -67,6 +69,20 @@ func (a *UserCustomIconsApi) CustomIconListHandler(c *core.WebContext) (any, *er
6769
// CustomIconUploadHandler saves a new custom icon for current user
6870
func (a *UserCustomIconsApi) CustomIconUploadHandler(c *core.WebContext) (any, *errs.Error) {
6971
uid := c.GetCurrentUid()
72+
user, err := a.users.GetUserById(c, uid)
73+
74+
if err != nil {
75+
if !errs.IsCustomError(err) {
76+
log.Errorf(c, "[user_custom_icons.CustomIconUploadHandler] failed to get user, because %s", err.Error())
77+
}
78+
79+
return nil, errs.ErrUserNotFound
80+
}
81+
82+
if user.FeatureRestriction.Contains(core.USER_FEATURE_RESTRICTION_TYPE_UPLOAD_CUSTOM_ICON) {
83+
return nil, errs.ErrNotPermittedToPerformThisAction
84+
}
85+
7086
form, err := c.MultipartForm()
7187

7288
if err != nil {
@@ -260,6 +276,20 @@ func (a *UserCustomIconsApi) CustomIconDeleteHandler(c *core.WebContext) (any, *
260276
}
261277

262278
uid := c.GetCurrentUid()
279+
user, err := a.users.GetUserById(c, uid)
280+
281+
if err != nil {
282+
if !errs.IsCustomError(err) {
283+
log.Errorf(c, "[user_custom_icons.CustomIconDeleteHandler] failed to get user, because %s", err.Error())
284+
}
285+
286+
return nil, errs.ErrUserNotFound
287+
}
288+
289+
if user.FeatureRestriction.Contains(core.USER_FEATURE_RESTRICTION_TYPE_UPLOAD_CUSTOM_ICON) {
290+
return nil, errs.ErrNotPermittedToPerformThisAction
291+
}
292+
263293
err = a.icons.DeleteCustomIcon(c, uid, iconDeleteReq.Id)
264294

265295
if err != nil {

pkg/core/user_feature_restriction.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ const (
9494
USER_FEATURE_RESTRICTION_TYPE_UNLINK_THIRD_PARTY_LOGIN UserFeatureRestrictionType = 16
9595
USER_FEATURE_RESTRICTION_TYPE_GENERATE_API_TOKEN UserFeatureRestrictionType = 17
9696
USER_FEATURE_RESTRICTION_TYPE_CREATE_TRANSACTION_FROM_AI_TEXT_RECOGNITION UserFeatureRestrictionType = 18
97+
USER_FEATURE_RESTRICTION_TYPE_UPLOAD_CUSTOM_ICON UserFeatureRestrictionType = 19
9798
)
9899

99100
const userFeatureRestrictionTypeMinValue UserFeatureRestrictionType = USER_FEATURE_RESTRICTION_TYPE_UPDATE_PASSWORD
100-
const userFeatureRestrictionTypeMaxValue UserFeatureRestrictionType = USER_FEATURE_RESTRICTION_TYPE_CREATE_TRANSACTION_FROM_AI_TEXT_RECOGNITION
101+
const userFeatureRestrictionTypeMaxValue UserFeatureRestrictionType = USER_FEATURE_RESTRICTION_TYPE_UPLOAD_CUSTOM_ICON
101102

102103
// String returns a textual representation of the restriction type of user features
103104
func (t UserFeatureRestrictionType) String() string {
@@ -138,6 +139,8 @@ func (t UserFeatureRestrictionType) String() string {
138139
return "Generate API Token"
139140
case USER_FEATURE_RESTRICTION_TYPE_CREATE_TRANSACTION_FROM_AI_TEXT_RECOGNITION:
140141
return "Create Transaction from AI Text Recognition"
142+
case USER_FEATURE_RESTRICTION_TYPE_UPLOAD_CUSTOM_ICON:
143+
return "Upload Custom Icon"
141144
default:
142145
return fmt.Sprintf("Invalid(%d)", int(t))
143146
}

0 commit comments

Comments
 (0)