Sidebar V2 Phase 2 (#14967)
* parent 48256721c4 (#14358)
author Eli Yukelzon <reflog@gmail.com> 1585814774 +0300
committer Eli Yukelzon <reflog@gmail.com> 1589111022 +0300
Sidebar caregories implemented
Apply suggestions from code review
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Update store/sqlstore/channel_store.go
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Update store/sqlstore/channel_store.go
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
code review suggestions
status messages
edge case
bugs...
timeout reverse
* MM-25126 Add a separate default sorting method for categories (#14575)
* MM-25158 Add user to initial sidebar categories when joining team (#14570)
* MM-25281 Place new categories in the correct position (#14609)
* MM-25277 Return channels that aren't in a category as part of the Channels/Direct Messages categories (#14601)
* MM-25276 Remove categories when leaving a team (#14600)
* Remove categories when leaving a team
* layers
* corrected cleanup function
* lint
* .
* corrected errors in postgres
* .
* MM-25280 Ensure that the "update category order" API call only contains real category IDs and isn't missing any IDs (#14626)
* Ensure that the "update category order" API call only contains real category IDs and isn't missing any IDs
* tests
* correct status code
* MM-25278 Change "update category" API to return 400 when changing unsupported fields (#14599)
* MM-25279 Change category migration to only populate channels in Favorites (#14627)
* MM-25157 Add API to delete custom categories (#14574)
* MM-25157 Add API to delete custom categories
* get categories fix
* maxorder fix
* Use correct websocket event when deleting category
* Fix tests and remove debug code
* Actually use the right websocket event this time
* test cleanup
* Update test for new category order
Co-authored-by: Eli Yukelzon <reflog@gmail.com>
* MM-24914 Various fixes for sidebar channel handling (#14756)
* Fix checking for channel membership when reordering channels
* Remove unique constraint on SidebarCategories
* Set column sizes for SidebarCategories and SidebarChannels tables
* Allow changing the sorting method for non-DM categories
* Fix nil pointers in error handling
* Fix orphaned channels from other team being returned in Channels category
* Fix non-orphaned channels being duplicated in the Channels category
* Remove unique constraint on SidebarChannels
* Fix category/name of favorites preferences
* Fix testSidebarChannelsMigration
* Rename err to nErr and appErr to err
* Fix channel order returned by GetSidebarCategories on MySQL
* Fix adding/removing favorites preferences
* Remove leftover TODO
* Change SidebarCategoryType enums to use full names (#14786)
* Change SidebarCategoryType enums to use full names
* Fix Channels constant
* Remove leftover debug code
* MM-24914 Fix updateCategory endpoint returning the wrong type (#14795)
* MM-24914 Make some changes to UpdateSidebarCategories (#14806)
* Fix orphaned DMs not always being returned
* MM-24914 Make some changes to UpdateSidebarCategories
* Run updateSidebarCategoryOrderT in a transaction
* Fix deleting SidebarChannels based on order of arguments to UpdateSidebarCategories
* bump for api testing
* bump for api testing
* Change CreateInitialSidebarCategories to return a plain error
* Change MigrateSidebarCategories to return a plain error
* Remove usage of UpdateColumns when updating sidebar categories (#14843)
* Remove usage of UpdateColumns when changing category order
* Add a random test case
* Remove usage of UpdateColumns when updating sidebar categories (#14843)
* Remove usage of UpdateColumns when changing category order
* Add a random test case
* Remove usage of UpdateColumns when updating sidebar categories (#14843)
* Remove usage of UpdateColumns when changing category order
* Add a random test case
* MM-26343 Make CreateInitialSidebarCategories idempotent (#14870)
* Fix bad merge
* Fix another bad merge
* Fix unintentionally removed i18n string
Co-authored-by: Eli Yukelzon <reflog@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
83a80a2422
Коммит
de6a57cdc3
@@ -32,6 +32,7 @@ func init() {
|
||||
func MakeMigrationsList() []string {
|
||||
return []string{
|
||||
model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2,
|
||||
model.MIGRATION_KEY_SIDEBAR_CATEGORIES_PHASE_2,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
128
migrations/sidebar_categories_phase_2.go
Обычный файл
128
migrations/sidebar_categories_phase_2.go
Обычный файл
@@ -0,0 +1,128 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
type ProgressStep string
|
||||
|
||||
const (
|
||||
StepCategories ProgressStep = "populateSidebarCategories"
|
||||
StepFavorites ProgressStep = "migrateFavoriteChannelToSidebarChannels"
|
||||
StepEnd ProgressStep = "endMigration"
|
||||
)
|
||||
|
||||
type Progress struct {
|
||||
CurrentStep ProgressStep `json:"current_state"`
|
||||
LastTeamId string `json:"last_team_id"`
|
||||
LastChannelId string `json:"last_channel_id"`
|
||||
LastUserId string `json:"last_user"`
|
||||
LastSortOrder int64 `json:"last_sort_order"`
|
||||
}
|
||||
|
||||
func (p *Progress) ToJson() string {
|
||||
b, _ := json.Marshal(p)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ProgressFromJson(data io.Reader) *Progress {
|
||||
var o *Progress
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
|
||||
func (p *Progress) IsValid() bool {
|
||||
if len(p.LastChannelId) != 26 {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(p.LastTeamId) != 26 {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(p.LastUserId) != 26 {
|
||||
return false
|
||||
}
|
||||
|
||||
switch p.CurrentStep {
|
||||
case StepCategories, StepFavorites:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func newProgress(step ProgressStep) *Progress {
|
||||
progress := new(Progress)
|
||||
progress.CurrentStep = step
|
||||
progress.LastChannelId = strings.Repeat("0", 26)
|
||||
progress.LastTeamId = strings.Repeat("0", 26)
|
||||
progress.LastUserId = strings.Repeat("0", 26)
|
||||
progress.LastSortOrder = 0
|
||||
return progress
|
||||
}
|
||||
|
||||
func (worker *Worker) runSidebarCategoriesPhase2Migration(lastDone string) (bool, string, *model.AppError) {
|
||||
var progress *Progress
|
||||
if len(lastDone) == 0 {
|
||||
progress = newProgress(StepCategories)
|
||||
} else {
|
||||
progress = ProgressFromJson(strings.NewReader(lastDone))
|
||||
if !progress.IsValid() {
|
||||
return false, "", model.NewAppError("MigrationsWorker.runSidebarCategoriesPhase2Migration", "migrations.worker.run_sidebar_categories_phase_2_migration.invalid_progress", map[string]interface{}{"progress": progress.ToJson()}, "", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
var result map[string]interface{}
|
||||
var nErr error
|
||||
var nextStep ProgressStep
|
||||
switch progress.CurrentStep {
|
||||
case StepCategories:
|
||||
result, nErr = worker.srv.Store.Channel().MigrateSidebarCategories(progress.LastTeamId, progress.LastUserId)
|
||||
nextStep = StepFavorites
|
||||
case StepFavorites:
|
||||
result, nErr = worker.srv.Store.Channel().MigrateFavoritesToSidebarChannels(progress.LastUserId, progress.LastSortOrder)
|
||||
nextStep = StepEnd
|
||||
default:
|
||||
return false, "", model.NewAppError("MigrationsWorker.runSidebarCategoriesPhase2Migration", "migrations.worker.run_sidebar_categories_phase_2_migration.invalid_progress", map[string]interface{}{"progress": progress.ToJson()}, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if nErr != nil {
|
||||
return false, progress.ToJson(), model.NewAppError("MigrationsWorker.runSidebarCategoriesPhase2Migration", "migrations.worker.run_sidebar_categories_phase_2_migration.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if result == nil {
|
||||
// We haven't progressed. That means that we've reached the end of this stage of the migration, and should now advance to the next stage or stop
|
||||
if nextStep != StepEnd {
|
||||
progress = newProgress(nextStep)
|
||||
return false, progress.ToJson(), nil
|
||||
}
|
||||
return true, progress.ToJson(), nil
|
||||
}
|
||||
|
||||
progress.LastChannelId = strings.Repeat("0", 26)
|
||||
progress.LastTeamId = strings.Repeat("0", 26)
|
||||
progress.LastUserId = strings.Repeat("0", 26)
|
||||
progress.LastSortOrder = 0
|
||||
if val, ok := result["UserId"].(string); ok {
|
||||
progress.LastUserId = val
|
||||
}
|
||||
if val, ok := result["TeamId"].(string); ok {
|
||||
progress.LastTeamId = val
|
||||
}
|
||||
if val, ok := result["ChannelId"].(string); ok {
|
||||
progress.LastChannelId = val
|
||||
}
|
||||
if val, ok := result["SortOrder"].(int64); ok {
|
||||
progress.LastSortOrder = val
|
||||
}
|
||||
return false, progress.ToJson(), nil
|
||||
}
|
||||
@@ -150,6 +150,8 @@ func (worker *Worker) runMigration(key string, lastDone string) (bool, string, *
|
||||
var err *model.AppError
|
||||
|
||||
switch key {
|
||||
case model.MIGRATION_KEY_SIDEBAR_CATEGORIES_PHASE_2:
|
||||
done, progress, err = worker.runSidebarCategoriesPhase2Migration(lastDone)
|
||||
case model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2:
|
||||
done, progress, err = worker.runAdvancedPermissionsPhase2Migration(lastDone)
|
||||
default:
|
||||
|
||||
Ссылка в новой задаче
Block a user