Remove remote users from the license counting and explicitly dissallow them to log in (#22582)

* Making all the counts aware of Remote users

* Disable login for remote users

* Adding tests for login remote_users error

* Adding tests for the store

* Adding frontend part of not counting remote users in the license

* Addressing PR review comment

* Adding the new ExternaUserId field to users

* Running make migrations-extract

* Running make app-layers and make gen-serialized

* Revert "Adding the new ExternaUserId field to users"

This reverts commit 12e5fd518962a16cdbdb8964179b6cd8e915f230.

* Adding GetUserByRemoteID methods

* Adding needed migration for users

* i18n-extract

* Fixing postgres increase remote user id field size migration up and down

* run make gen-serialized

* Removing migration code

* Not count remote users as part of the cloud pricing

* Add the cloud subscription when a user gets promote from remote to not-remote

* Fixing merge problems

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Jesús Espino
2023-08-14 17:54:10 +02:00
коммит произвёл GitHub
родитель 5a349873f7
Коммит 5f7482e541
19 изменённых файлов: 295 добавлений и 3 удалений

Просмотреть файл

@@ -1174,6 +1174,26 @@ func (us SqlUserStore) GetByEmail(email string) (*model.User, error) {
return &user, nil
}
func (us SqlUserStore) GetByRemoteID(remoteID string) (*model.User, error) {
query := us.usersQuery.Where(sq.Eq{"RemoteId": remoteID})
queryString, args, err := query.ToSql()
if err != nil {
return nil, errors.Wrap(err, "get_by_remote_id_tosql")
}
user := model.User{}
if err := us.GetReplicaX().Get(&user, queryString, args...); err != nil {
if err == sql.ErrNoRows {
return nil, errors.Wrap(store.NewErrNotFound("User", fmt.Sprintf("remoteid=%s", remoteID)), "failed to find User")
}
return nil, errors.Wrapf(err, "failed to get User with RemoteId=%s", remoteID)
}
return &user, nil
}
func (us SqlUserStore) GetByAuth(authData *string, authService string) (*model.User, error) {
if authData == nil || *authData == "" {
return nil, store.NewErrInvalidInput("User", "<authData>", "empty or nil")
@@ -1310,6 +1330,10 @@ func (us SqlUserStore) Count(options model.UserCountOptions) (int64, error) {
query = query.Where("u.DeleteAt = 0")
}
if !options.IncludeRemoteUsers {
query = query.Where(sq.Or{sq.Eq{"u.RemoteId": ""}, sq.Eq{"u.RemoteId": nil}})
}
isPostgreSQL := us.DriverName() == model.DatabaseDriverPostgres
if options.IncludeBotAccounts {
if options.ExcludeRegularUsers {
@@ -1365,8 +1389,17 @@ func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64, options model.User
query = query.Where(sq.Expr("UserId NOT IN (SELECT UserId FROM Bots)"))
}
}
if !options.IncludeRemoteUsers || !options.IncludeDeleted {
query = query.LeftJoin("Users ON s.UserId = Users.Id")
}
if !options.IncludeRemoteUsers {
query = query.Where(sq.Or{sq.Eq{"Users.RemoteId": ""}, sq.Eq{"Users.RemoteId": nil}})
}
if !options.IncludeDeleted {
query = query.LeftJoin("Users ON s.UserId = Users.Id").Where("Users.DeleteAt = 0")
query = query.Where("Users.DeleteAt = 0")
}
queryStr, args, err := query.ToSql()
@@ -1393,8 +1426,16 @@ func (us SqlUserStore) AnalyticsActiveCountForPeriod(startTime int64, endTime in
}
}
if !options.IncludeRemoteUsers || !options.IncludeDeleted {
query = query.LeftJoin("Users ON s.UserId = Users.Id")
}
if !options.IncludeRemoteUsers {
query = query.Where(sq.Or{sq.Eq{"Users.RemoteId": ""}, sq.Eq{"Users.RemoteId": nil}})
}
if !options.IncludeDeleted {
query = query.LeftJoin("Users ON s.UserId = Users.Id").Where("Users.DeleteAt = 0")
query = query.Where("Users.DeleteAt = 0")
}
queryStr, args, err := query.ToSql()