Migrate functions to app package (#5106)
* Refactor and move session logic into app package * Refactor email functions into the app package * Refactor password update into app package * Migrate user functions to app package * Move team functions into app package * Migrate channel functions into app package * Pass SiteURL through to app functions * Update based on feedback
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
61b7226533
Коммит
d3a285e64d
@@ -5,7 +5,6 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/mattermost/platform/api"
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
@@ -166,7 +165,7 @@ func removeUserFromChannel(channel *model.Channel, user *model.User, userArg str
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := api.RemoveUserFromChannel(user.Id, "", channel); err != nil {
|
||||
if err := app.RemoveUserFromChannel(user.Id, "", channel); err != nil {
|
||||
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,8 +319,7 @@ func cmdInviteUser() {
|
||||
}
|
||||
|
||||
invites := []string{flagEmail}
|
||||
c := getMockContext()
|
||||
api.InviteMembers(team, user.GetDisplayName(), invites, c.GetSiteURL())
|
||||
app.SendInviteEmails(team, user.GetDisplayName(), invites, *utils.Cfg.ServiceSettings.SiteURL)
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -369,7 +368,7 @@ func cmdAssignRole() {
|
||||
}
|
||||
|
||||
if !user.IsInRole(flagRole) {
|
||||
api.UpdateUserRoles(user, flagRole)
|
||||
app.UpdateUserRoles(user.Id, flagRole)
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
@@ -547,7 +546,7 @@ func cmdLeaveChannel() {
|
||||
channel = result.Data.(*model.Channel)
|
||||
}
|
||||
|
||||
err := api.RemoveUserFromChannel(user.Id, user.Id, channel)
|
||||
err := app.RemoveUserFromChannel(user.Id, user.Id, channel)
|
||||
if err != nil {
|
||||
l4g.Error("%v", err)
|
||||
flushLogAndExit(1)
|
||||
@@ -712,7 +711,7 @@ func cmdLeaveTeam() {
|
||||
user = result.Data.(*model.User)
|
||||
}
|
||||
|
||||
err := api.LeaveTeam(team, user)
|
||||
err := app.LeaveTeam(team, user)
|
||||
|
||||
if err != nil {
|
||||
l4g.Error("%v", err)
|
||||
@@ -823,7 +822,7 @@ func cmdPermDeleteUser() {
|
||||
flushLogAndExit(1)
|
||||
}
|
||||
|
||||
if err := api.PermanentDeleteUser(user); err != nil {
|
||||
if err := app.PermanentDeleteUser(user); err != nil {
|
||||
l4g.Error("%v", err)
|
||||
flushLogAndExit(1)
|
||||
} else {
|
||||
@@ -866,7 +865,7 @@ func cmdPermDeleteTeam() {
|
||||
flushLogAndExit(1)
|
||||
}
|
||||
|
||||
if err := api.PermanentDeleteTeam(team); err != nil {
|
||||
if err := app.PermanentDeleteTeam(team); err != nil {
|
||||
l4g.Error("%v", err)
|
||||
flushLogAndExit(1)
|
||||
} else {
|
||||
@@ -896,7 +895,7 @@ func cmdPermDeleteAllUsers() {
|
||||
flushLogAndExit(1)
|
||||
}
|
||||
|
||||
if err := api.PermanentDeleteAllUsers(); err != nil {
|
||||
if err := app.PermanentDeleteAllUsers(); err != nil {
|
||||
l4g.Error("%v", err)
|
||||
flushLogAndExit(1)
|
||||
} else {
|
||||
@@ -1033,7 +1032,7 @@ func cmdActivateUser() {
|
||||
l4g.Error("%v", utils.T("api.user.update_active.no_deactivate_ldap.app_error"))
|
||||
}
|
||||
|
||||
if _, err := api.UpdateActive(user, !flagUserSetInactive); err != nil {
|
||||
if _, err := app.UpdateActive(user, !flagUserSetInactive); err != nil {
|
||||
l4g.Error("%v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/mattermost/platform/api"
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -49,7 +49,7 @@ func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if _, err := api.UpdateUserRoles(user, "system_admin system_user"); err != nil {
|
||||
if _, err := app.UpdateUserRoles(user.Id, "system_admin system_user"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func makeMemberCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if _, err := api.UpdateUserRoles(user, "system_user"); err != nil {
|
||||
if _, err := app.UpdateUserRoles(user.Id, "system_user"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/platform/api"
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -125,7 +124,7 @@ func removeUserFromTeam(team *model.Team, user *model.User, userArg string) {
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := api.LeaveTeam(team, user); err != nil {
|
||||
if err := app.LeaveTeam(team, user); err != nil {
|
||||
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + team.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
@@ -200,5 +199,5 @@ func deleteTeamsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteTeam(team *model.Team) *model.AppError {
|
||||
return api.PermanentDeleteTeam(team)
|
||||
return app.PermanentDeleteTeam(team)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/platform/api"
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
@@ -175,7 +174,7 @@ func changeUserActiveStatus(user *model.User, userArg string, activate bool) {
|
||||
CommandPrintErrorln(utils.T("api.user.update_active.no_deactivate_ldap.app_error"))
|
||||
return
|
||||
}
|
||||
if _, err := api.UpdateActive(user, activate); err != nil {
|
||||
if _, err := app.UpdateActive(user, activate); err != nil {
|
||||
CommandPrintErrorln("Unable to change activation status of user: " + userArg)
|
||||
}
|
||||
}
|
||||
@@ -227,7 +226,7 @@ func userCreateCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if system_admin {
|
||||
api.UpdateUserRoles(ruser, "system_user system_admin")
|
||||
app.UpdateUserRoles(ruser.Id, "system_user system_admin")
|
||||
}
|
||||
|
||||
CommandPrettyPrintln("Created User")
|
||||
@@ -262,7 +261,7 @@ func inviteUser(email string, team *model.Team, teamArg string) {
|
||||
CommandPrintErrorln("Can't find team '" + teamArg + "'")
|
||||
return
|
||||
}
|
||||
api.InviteMembers(team, "Administrator", invites, *utils.Cfg.ServiceSettings.SiteURL)
|
||||
app.SendInviteEmails(team, "Administrator", invites, *utils.Cfg.ServiceSettings.SiteURL)
|
||||
CommandPrettyPrintln("Invites may or may not have been sent.")
|
||||
}
|
||||
|
||||
@@ -335,7 +334,7 @@ func deleteUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if err := api.PermanentDeleteUser(user); err != nil {
|
||||
if err := app.PermanentDeleteUser(user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -365,7 +364,7 @@ func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := api.PermanentDeleteAllUsers(); err != nil {
|
||||
if err := app.PermanentDeleteAllUsers(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
CommandPrettyPrintln("Sucsessfull. All users deleted.")
|
||||
|
||||
Ссылка в новой задаче
Block a user