[MM-16798] Add a Guest Accounts feature flag (#13231)
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
7a6c0f607b
Коммит
c3c250cd91
@@ -96,7 +96,7 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.License() == nil && patch.Permissions != nil {
|
||||
if (c.App.License() == nil || !*c.App.License().Features.GuestAccounts) && patch.Permissions != nil {
|
||||
if oldRole.Name == "system_guest" || oldRole.Name == "team_guest" || oldRole.Name == "channel_guest" {
|
||||
c.Err = model.NewAppError("Api4.PatchRoles", "api.roles.patch_roles.license.error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
@@ -129,7 +129,7 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if c.App.License() != nil && (oldRole.Name == "system_guest" || oldRole.Name == "team_guest" || oldRole.Name == "channel_guest") && !*c.App.License().Features.GuestAccountsPermissions {
|
||||
if c.App.License() != nil && *c.App.License().Features.GuestAccounts && (oldRole.Name == "system_guest" || oldRole.Name == "team_guest" || oldRole.Name == "channel_guest") && !*c.App.License().Features.GuestAccountsPermissions {
|
||||
c.Err = model.NewAppError("Api4.PatchRoles", "api.roles.patch_roles.license.error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -968,7 +968,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if c.App.License() == nil {
|
||||
if c.App.License() == nil || !*c.App.License().Features.GuestAccounts {
|
||||
c.Err = model.NewAppError("Api4.InviteGuestsToChannels", "api.team.invate_guests_to_channels.license.error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if token.Type == app.TOKEN_TYPE_GUEST_INVITATION {
|
||||
if c.App.License() == nil {
|
||||
if c.App.License() == nil || !*c.App.License().Features.GuestAccounts {
|
||||
c.Err = model.NewAppError("CreateUserWithToken", "api.user.create_user.guest_accounts.license.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -1387,7 +1387,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if user.IsGuest() {
|
||||
if c.App.License() == nil {
|
||||
if c.App.License() == nil || !*c.App.License().Features.GuestAccounts {
|
||||
c.Err = model.NewAppError("login", "api.user.login.guest_accounts.license.error", nil, "", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
@@ -1971,7 +1971,7 @@ func promoteGuestToUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.License() == nil {
|
||||
if c.App.License() == nil || !*c.App.License().Features.GuestAccounts {
|
||||
c.Err = model.NewAppError("Api4.promoteGuestToUser", "api.team.promote_guest_to_user.license.error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
@@ -2011,7 +2011,7 @@ func demoteUserToGuest(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.License() == nil {
|
||||
if c.App.License() == nil || !*c.App.License().Features.GuestAccounts {
|
||||
c.Err = model.NewAppError("Api4.demoteUserToGuest", "api.team.demote_user_to_guest.license.error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ type Features struct {
|
||||
MessageExport *bool `json:"message_export"`
|
||||
CustomPermissionsSchemes *bool `json:"custom_permissions_schemes"`
|
||||
CustomTermsOfService *bool `json:"custom_terms_of_service"`
|
||||
GuestAccounts *bool `json:"guest_accounts"`
|
||||
GuestAccountsPermissions *bool `json:"guest_accounts_permissions"`
|
||||
IDLoadedPushNotifications *bool `json:"id_loaded"`
|
||||
LockTeammateNameDisplay *bool `json:"lock_teammate_name_display"`
|
||||
@@ -84,6 +85,7 @@ func (f *Features) ToMap() map[string]interface{} {
|
||||
"data_retention": *f.DataRetention,
|
||||
"message_export": *f.MessageExport,
|
||||
"custom_permissions_schemes": *f.CustomPermissionsSchemes,
|
||||
"guest_accounts": *f.GuestAccounts,
|
||||
"guest_accounts_permissions": *f.GuestAccountsPermissions,
|
||||
"id_loaded": *f.IDLoadedPushNotifications,
|
||||
"lock_teammate_name_display": *f.LockTeammateNameDisplay,
|
||||
@@ -168,6 +170,10 @@ func (f *Features) SetDefaults() {
|
||||
f.CustomPermissionsSchemes = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.GuestAccounts == nil {
|
||||
f.GuestAccounts = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
if f.GuestAccountsPermissions == nil {
|
||||
f.GuestAccountsPermissions = NewBool(*f.FutureFeatures)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
||||
*f.DataRetention = true
|
||||
*f.MessageExport = true
|
||||
*f.CustomPermissionsSchemes = true
|
||||
*f.GuestAccounts = true
|
||||
*f.GuestAccountsPermissions = true
|
||||
*f.EmailNotificationContents = true
|
||||
*f.IDLoadedPushNotifications = true
|
||||
@@ -100,6 +101,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
||||
CheckTrue(t, *f.DataRetention)
|
||||
CheckTrue(t, *f.MessageExport)
|
||||
CheckTrue(t, *f.CustomPermissionsSchemes)
|
||||
CheckTrue(t, *f.GuestAccounts)
|
||||
CheckTrue(t, *f.GuestAccountsPermissions)
|
||||
CheckTrue(t, *f.IDLoadedPushNotifications)
|
||||
CheckFalse(t, *f.FutureFeatures)
|
||||
@@ -176,6 +178,7 @@ func TestLicenseToFromJson(t *testing.T) {
|
||||
CheckBool(t, *f1.DataRetention, *f.DataRetention)
|
||||
CheckBool(t, *f1.MessageExport, *f.MessageExport)
|
||||
CheckBool(t, *f1.CustomPermissionsSchemes, *f.CustomPermissionsSchemes)
|
||||
CheckBool(t, *f1.GuestAccounts, *f.GuestAccounts)
|
||||
CheckBool(t, *f1.GuestAccountsPermissions, *f.GuestAccountsPermissions)
|
||||
CheckBool(t, *f1.IDLoadedPushNotifications, *f.IDLoadedPushNotifications)
|
||||
CheckBool(t, *f1.FutureFeatures, *f.FutureFeatures)
|
||||
|
||||
@@ -155,6 +155,7 @@ func GetClientLicense(l *model.License) map[string]string {
|
||||
props["EmailNotificationContents"] = strconv.FormatBool(*l.Features.EmailNotificationContents)
|
||||
props["MessageExport"] = strconv.FormatBool(*l.Features.MessageExport)
|
||||
props["CustomPermissionsSchemes"] = strconv.FormatBool(*l.Features.CustomPermissionsSchemes)
|
||||
props["GuestAccounts"] = strconv.FormatBool(*l.Features.GuestAccounts)
|
||||
props["GuestAccountsPermissions"] = strconv.FormatBool(*l.Features.GuestAccountsPermissions)
|
||||
props["CustomTermsOfService"] = strconv.FormatBool(*l.Features.CustomTermsOfService)
|
||||
props["LockTeammateNameDisplay"] = strconv.FormatBool(*l.Features.LockTeammateNameDisplay)
|
||||
|
||||
Ссылка в новой задаче
Block a user