-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_terms_of_service.go
52 lines (44 loc) · 1.68 KB
/
user_terms_of_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"errors"
"net/http"
"github.com/zgordan-vv/zacmm-server/model"
"github.com/zgordan-vv/zacmm-server/store"
)
func (a *App) GetUserTermsOfService(userId string) (*model.UserTermsOfService, *model.AppError) {
u, err := a.Srv().Store.UserTermsOfService().GetByUser(userId)
if err != nil {
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("GetUserTermsOfService", "app.user_terms_of_service.get_by_user.no_rows.app_error", nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("GetUserTermsOfService", "app.user_terms_of_service.get_by_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
return u, nil
}
func (a *App) SaveUserTermsOfService(userId, termsOfServiceId string, accepted bool) *model.AppError {
if accepted {
userTermsOfService := &model.UserTermsOfService{
UserId: userId,
TermsOfServiceId: termsOfServiceId,
}
if _, err := a.Srv().Store.UserTermsOfService().Save(userTermsOfService); err != nil {
var appErr *model.AppError
switch {
case errors.As(err, &appErr):
return appErr
default:
return model.NewAppError("SaveUserTermsOfService", "app.user_terms_of_service.save.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
} else {
if err := a.Srv().Store.UserTermsOfService().Delete(userId, termsOfServiceId); err != nil {
return model.NewAppError("SaveUserTermsOfService", "app.user_terms_of_service.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
return nil
}