move valet feature switch to DB from config
Этот коммит содержится в:
@@ -25,9 +25,7 @@ func InitCommand(r *mux.Router) {
|
|||||||
l4g.Debug("Initializing command api routes")
|
l4g.Debug("Initializing command api routes")
|
||||||
r.Handle("/command", ApiUserRequired(command)).Methods("POST")
|
r.Handle("/command", ApiUserRequired(command)).Methods("POST")
|
||||||
|
|
||||||
if utils.Cfg.TeamSettings.AllowValet {
|
commands = append(commands, echoCommand)
|
||||||
commands = append(commands, echoCommand)
|
|
||||||
}
|
|
||||||
|
|
||||||
hub.Start()
|
hub.Start()
|
||||||
}
|
}
|
||||||
@@ -59,6 +57,8 @@ func checkCommand(c *Context, command *model.Command) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tchan := Srv.Store.Team().Get(c.Session.TeamId)
|
||||||
|
|
||||||
if len(command.ChannelId) > 0 {
|
if len(command.ChannelId) > 0 {
|
||||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, command.ChannelId, c.Session.UserId)
|
cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, command.ChannelId, c.Session.UserId)
|
||||||
|
|
||||||
@@ -67,7 +67,21 @@ func checkCommand(c *Context, command *model.Command) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allowValet := false
|
||||||
|
if tResult := <-tchan; tResult.Err != nil {
|
||||||
|
c.Err = model.NewAppError("checkCommand", "Could not find the team for this session, team_id="+c.Session.TeamId, "")
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
allowValet = tResult.Data.(*model.Team).AllowValet
|
||||||
|
}
|
||||||
|
|
||||||
|
var ec commandHandler
|
||||||
|
ec = echoCommand
|
||||||
for _, v := range commands {
|
for _, v := range commands {
|
||||||
|
if !allowValet && &v == &ec {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if v(c, command) {
|
if v(c, command) {
|
||||||
return true
|
return true
|
||||||
} else if c.Err != nil {
|
} else if c.Err != nil {
|
||||||
|
|||||||
20
api/post.go
20
api/post.go
@@ -58,11 +58,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createValetPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
func createValetPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
if !utils.Cfg.TeamSettings.AllowValet {
|
tchan := Srv.Store.Team().Get(c.Session.TeamId)
|
||||||
c.Err = model.NewAppError("createValetPost", "The valet feature is currently turned off. Please contact your system administrator for details.", "")
|
|
||||||
c.Err.StatusCode = http.StatusNotImplemented
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
post := model.PostFromJson(r.Body)
|
post := model.PostFromJson(r.Body)
|
||||||
if post == nil {
|
if post == nil {
|
||||||
@@ -70,13 +66,25 @@ func createValetPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any one with access to the team can post as valet to any open channel
|
|
||||||
cchan := Srv.Store.Channel().CheckOpenChannelPermissions(c.Session.TeamId, post.ChannelId)
|
cchan := Srv.Store.Channel().CheckOpenChannelPermissions(c.Session.TeamId, post.ChannelId)
|
||||||
|
|
||||||
|
// Any one with access to the team can post as valet to any open channel
|
||||||
if !c.HasPermissionsToChannel(cchan, "createValetPost") {
|
if !c.HasPermissionsToChannel(cchan, "createValetPost") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure this team has the valet feature enabled
|
||||||
|
if tResult := <-tchan; tResult.Err != nil {
|
||||||
|
c.Err = model.NewAppError("createValetPost", "Could not find the team for this session, team_id="+c.Session.TeamId, "")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if !tResult.Data.(*model.Team).AllowValet {
|
||||||
|
c.Err = model.NewAppError("createValetPost", "The valet feature is currently turned off. Please contact your team administrator for details.", "")
|
||||||
|
c.Err.StatusCode = http.StatusNotImplemented
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if rp, err := CreateValetPost(c, post); err != nil {
|
if rp, err := CreateValetPost(c, post); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ func TestCreateValetPost(t *testing.T) {
|
|||||||
channel2 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
channel2 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
||||||
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
|
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
|
||||||
|
|
||||||
if utils.Cfg.TeamSettings.AllowValet {
|
if utils.Cfg.TeamSettings.AllowValetDefault {
|
||||||
post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a"}
|
post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a"}
|
||||||
rpost1, err := Client.CreateValetPost(post1)
|
rpost1, err := Client.CreateValetPost(post1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
11
api/team.go
11
api/team.go
@@ -136,6 +136,8 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
teamSignup.Team.AllowValet = utils.Cfg.TeamSettings.AllowValetDefault
|
||||||
|
|
||||||
if result := <-Srv.Store.Team().Save(&teamSignup.Team); result.Err != nil {
|
if result := <-Srv.Store.Team().Save(&teamSignup.Team); result.Err != nil {
|
||||||
c.Err = result.Err
|
c.Err = result.Err
|
||||||
return
|
return
|
||||||
@@ -157,7 +159,7 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if utils.Cfg.TeamSettings.AllowValet {
|
if teamSignup.Team.AllowValet {
|
||||||
CreateValet(c, rteam)
|
CreateValet(c, rteam)
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
return
|
return
|
||||||
@@ -200,6 +202,13 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rteam.AllowValet {
|
||||||
|
CreateValet(c, rteam)
|
||||||
|
if c.Err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
w.Write([]byte(rteam.ToJson()))
|
w.Write([]byte(rteam.ToJson()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,10 +145,6 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateValet(c *Context, team *model.Team) *model.User {
|
func CreateValet(c *Context, team *model.Team) *model.User {
|
||||||
if !utils.Cfg.TeamSettings.AllowValet {
|
|
||||||
return &model.User{}
|
|
||||||
}
|
|
||||||
|
|
||||||
valet := &model.User{}
|
valet := &model.User{}
|
||||||
valet.TeamId = team.Id
|
valet.TeamId = team.Id
|
||||||
valet.Email = utils.Cfg.EmailSettings.FeedbackEmail
|
valet.Email = utils.Cfg.EmailSettings.FeedbackEmail
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
"TeamSettings": {
|
"TeamSettings": {
|
||||||
"MaxUsersPerTeam": 150,
|
"MaxUsersPerTeam": 150,
|
||||||
"AllowPublicLink": true,
|
"AllowPublicLink": true,
|
||||||
"AllowValet": false,
|
"AllowValetDefault": false,
|
||||||
"TermsLink": "/static/help/configure_links.html",
|
"TermsLink": "/static/help/configure_links.html",
|
||||||
"PrivacyLink": "/static/help/configure_links.html",
|
"PrivacyLink": "/static/help/configure_links.html",
|
||||||
"AboutLink": "/static/help/configure_links.html",
|
"AboutLink": "/static/help/configure_links.html",
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type Team struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
CompanyName string `json:"company_name"`
|
CompanyName string `json:"company_name"`
|
||||||
AllowedDomains string `json:"allowed_domains"`
|
AllowedDomains string `json:"allowed_domains"`
|
||||||
|
AllowValet bool `json:"allow_valet"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Invites struct {
|
type Invites struct {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
|
"github.com/mattermost/platform/utils"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,6 +30,11 @@ func NewSqlTeamStore(sqlStore *SqlStore) TeamStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) UpgradeSchemaIfNeeded() {
|
func (s SqlTeamStore) UpgradeSchemaIfNeeded() {
|
||||||
|
defaultValue := "0"
|
||||||
|
if utils.Cfg.TeamSettings.AllowValetDefault {
|
||||||
|
defaultValue = "1"
|
||||||
|
}
|
||||||
|
s.CreateColumnIfNotExists("Teams", "AllowValet", "AllowedDomains", "tinyint(1)", defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) CreateIndexesIfNotExists() {
|
func (s SqlTeamStore) CreateIndexesIfNotExists() {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ type PrivacySettings struct {
|
|||||||
type TeamSettings struct {
|
type TeamSettings struct {
|
||||||
MaxUsersPerTeam int
|
MaxUsersPerTeam int
|
||||||
AllowPublicLink bool
|
AllowPublicLink bool
|
||||||
AllowValet bool
|
AllowValetDefault bool
|
||||||
TermsLink string
|
TermsLink string
|
||||||
PrivacyLink string
|
PrivacyLink string
|
||||||
AboutLink string
|
AboutLink string
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user