[PLT-7574] Update and Simplify Compatibility Check and Replace UA Dependency (#7427)
* Add fix to not run browser check on Mobile Browsers or the App * remove non safari and IE checks * Replace useragent checking dependency and update UA tests * change some wording * change dependancy again to one with compatible licence * Fix typos and clarify wording * fix typo and comvert tests to use array
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
6b3c9a480a
Коммит
309594cedf
25
web/web.go
25
web/web.go
@@ -8,12 +8,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/NYTimes/gziphandler"
|
||||
"github.com/avct/uasurfer"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mssola/user_agent"
|
||||
)
|
||||
|
||||
func Init(api3 *api.API) {
|
||||
@@ -65,26 +65,27 @@ func pluginHandler(config model.ConfigFunc, handler http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
var browsersNotSupported string = "MSIE/8;MSIE/9;MSIE/10;Internet Explorer/8;Internet Explorer/9;Internet Explorer/10;Safari/7;Safari/8"
|
||||
// Due to the complexities of UA detection and the ramifications of a misdetection only older Safari and IE browsers throw incompatibility errors.
|
||||
|
||||
func CheckBrowserCompatability(c *api.Context, r *http.Request) bool {
|
||||
ua := user_agent.New(r.UserAgent())
|
||||
bname, bversion := ua.Browser()
|
||||
// Map should be of minimum required browser version.
|
||||
var browserMinimumSupported = map[string]int{
|
||||
"BrowserIE": 11,
|
||||
"BrowserSafari": 9,
|
||||
}
|
||||
|
||||
browsers := strings.Split(browsersNotSupported, ";")
|
||||
for _, browser := range browsers {
|
||||
version := strings.Split(browser, "/")
|
||||
func CheckClientCompatability(agentString string) bool {
|
||||
ua := uasurfer.Parse(agentString)
|
||||
|
||||
if strings.HasPrefix(bname, version[0]) && strings.HasPrefix(bversion, version[1]) {
|
||||
return false
|
||||
}
|
||||
if version, exist := browserMinimumSupported[ua.Browser.Name.String()]; exist && ua.Browser.Version.Major < version {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func root(c *api.Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !CheckBrowserCompatability(c, r) {
|
||||
|
||||
if !CheckClientCompatability(r.UserAgent()) {
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
page := utils.NewHTMLTemplate(c.App.HTMLTemplates(), "unsupported_browser")
|
||||
page.Props["Title"] = c.T("web.error.unsupported_browser.title")
|
||||
|
||||
Ссылка в новой задаче
Block a user