Removed getDefaultTemplates functin as no longer needed

This commit is contained in:
Harshil Sharma 2022-03-29 11:16:16 +05:30
parent beaa47f63e
commit 761e7cd463
9 changed files with 12 additions and 59 deletions

View file

@ -53,10 +53,6 @@ func (a *App) GetTemplateBoards(teamID, userID string) ([]*model.Board, error) {
return a.store.GetTemplateBoards(teamID, userID)
}
func (a *App) GetDefaultTemplates() ([]*model.Board, error) {
return a.store.GetDefaultTemplates()
}
func (a *App) CreateBoard(board *model.Board, userID string, addMember bool) (*model.Board, error) {
if board.ID != "" {
return nil, ErrNewBoardCannotHaveID

View file

@ -46,14 +46,14 @@ func (a *App) PrepareOnboardingTour(userID string, teamID string) (string, strin
}
func (a *App) getOnboardingBoardID() (string, error) {
boards, err := a.store.GetDefaultTemplates()
boards, err := a.store.GetTemplateBoards("0", "")
if err != nil {
return "", err
}
var onboardingBoardID string
for _, block := range boards {
if block.Title == WelcomeBoardTitle {
if block.Title == WelcomeBoardTitle && block.TeamID == "0" {
onboardingBoardID = block.ID
break
}

View file

@ -25,7 +25,7 @@ func TestPrepareOnboardingTour(t *testing.T) {
IsTemplate: true,
}
th.Store.EXPECT().GetDefaultTemplates().Return([]*model.Board{&welcomeBoard}, nil)
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
th.Store.EXPECT().DuplicateBoard(welcomeBoard.ID, userID, teamID, false).Return(&model.BoardsAndBlocks{Boards: []*model.Board{&welcomeBoard}},
nil, nil)
th.Store.EXPECT().GetMembersForBoard(welcomeBoard.ID).Return([]*model.BoardMember{}, nil)
@ -60,7 +60,7 @@ func TestCreateWelcomeBoard(t *testing.T) {
TeamID: "0",
IsTemplate: true,
}
th.Store.EXPECT().GetDefaultTemplates().Return([]*model.Board{&welcomeBoard}, nil)
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
th.Store.EXPECT().DuplicateBoard(welcomeBoard.ID, userID, teamID, false).
Return(&model.BoardsAndBlocks{Boards: []*model.Board{&welcomeBoard}}, nil, nil)
th.Store.EXPECT().GetMembersForBoard(welcomeBoard.ID).Return([]*model.BoardMember{}, nil)
@ -72,7 +72,7 @@ func TestCreateWelcomeBoard(t *testing.T) {
t.Run("template doesn't contain a board", func(t *testing.T) {
teamID := testTeamID
th.Store.EXPECT().GetDefaultTemplates().Return([]*model.Board{}, nil)
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{}, nil)
boardID, err := th.App.createWelcomeBoard("user_id_1", teamID)
assert.Error(t, err)
assert.Empty(t, boardID)
@ -86,7 +86,7 @@ func TestCreateWelcomeBoard(t *testing.T) {
TeamID: teamID,
IsTemplate: true,
}
th.Store.EXPECT().GetDefaultTemplates().Return([]*model.Board{&welcomeBoard}, nil)
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
boardID, err := th.App.createWelcomeBoard("user_id_1", "workspace_id_1")
assert.Error(t, err)
assert.Empty(t, boardID)
@ -104,7 +104,7 @@ func TestGetOnboardingBoardID(t *testing.T) {
TeamID: "0",
IsTemplate: true,
}
th.Store.EXPECT().GetDefaultTemplates().Return([]*model.Board{&welcomeBoard}, nil)
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
onboardingBoardID, err := th.App.getOnboardingBoardID()
assert.NoError(t, err)
@ -112,7 +112,7 @@ func TestGetOnboardingBoardID(t *testing.T) {
})
t.Run("no blocks found", func(t *testing.T) {
th.Store.EXPECT().GetDefaultTemplates().Return([]*model.Board{}, nil)
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{}, nil)
onboardingBoardID, err := th.App.getOnboardingBoardID()
assert.Error(t, err)
@ -126,7 +126,7 @@ func TestGetOnboardingBoardID(t *testing.T) {
TeamID: "0",
IsTemplate: true,
}
th.Store.EXPECT().GetDefaultTemplates().Return([]*model.Board{&welcomeBoard}, nil)
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
onboardingBoardID, err := th.App.getOnboardingBoardID()
assert.Error(t, err)

View file

@ -26,7 +26,7 @@ func (a *App) InitTemplates() error {
// initializeTemplates imports default templates if the boards table is empty.
func (a *App) initializeTemplates() error {
boards, err := a.store.GetDefaultTemplates()
boards, err := a.store.GetTemplateBoards(globalTeamID, "")
if err != nil {
return fmt.Errorf("cannot initialize templates: %w", err)
}

View file

@ -42,7 +42,7 @@ func setupTestHelper(t *testing.T) *TestHelper {
newAuth := New(&cfg, mockStore, localpermissions.New(mockPermissions, logger))
// called during default template setup for every test
mockStore.EXPECT().GetDefaultTemplates().AnyTimes()
mockStore.EXPECT().GetTemplateBoards("0", "").AnyTimes()
mockStore.EXPECT().RemoveDefaultTemplates(gomock.Any()).AnyTimes()
mockStore.EXPECT().InsertBlock(gomock.Any(), gomock.Any()).AnyTimes()

View file

@ -535,21 +535,6 @@ func (mr *MockStoreMockRecorder) GetCategory(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCategory", reflect.TypeOf((*MockStore)(nil).GetCategory), arg0)
}
// GetDefaultTemplates mocks base method.
func (m *MockStore) GetDefaultTemplates() ([]*model.Board, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetDefaultTemplates")
ret0, _ := ret[0].([]*model.Board)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetDefaultTemplates indicates an expected call of GetDefaultTemplates.
func (mr *MockStoreMockRecorder) GetDefaultTemplates() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDefaultTemplates", reflect.TypeOf((*MockStore)(nil).GetDefaultTemplates))
}
// GetMemberForBoard mocks base method.
func (m *MockStore) GetMemberForBoard(arg0, arg1 string) (*model.BoardMember, error) {
m.ctrl.T.Helper()

View file

@ -319,11 +319,6 @@ func (s *SQLStore) GetCategory(id string) (*model.Category, error) {
}
func (s *SQLStore) GetDefaultTemplates() ([]*model.Board, error) {
return s.getDefaultTemplates(s.db)
}
func (s *SQLStore) GetMemberForBoard(boardID string, userID string) (*model.BoardMember, error) {
return s.getMemberForBoard(s.db, boardID, userID)

View file

@ -54,25 +54,7 @@ func (s *SQLStore) removeDefaultTemplates(db sq.BaseRunner, boards []*model.Boar
return nil
}
// getDefaultTemplateBoards fetches all template blocks .
func (s *SQLStore) getDefaultTemplates(db sq.BaseRunner) ([]*model.Board, error) {
query := s.getQueryBuilder(db).
Select(boardFields("")...).
From(s.tablePrefix + "boards").
Where(sq.Eq{"team_id": "0"}).
Where(sq.Eq{"is_template": true})
rows, err := query.Query()
if err != nil {
s.logger.Error(`getTemplateBoards ERROR`, mlog.Err(err))
return nil, err
}
defer s.CloseRows(rows)
return s.boardsFromRows(rows)
}
// getDefaultTemplateBoards fetches all template blocks .
// getTemplateBoards fetches all template boards .
func (s *SQLStore) getTemplateBoards(db sq.BaseRunner, teamID, userID string) ([]*model.Board, error) {
query := s.getQueryBuilder(db).
Select(boardFields("")...).
@ -91,10 +73,6 @@ func (s *SQLStore) getTemplateBoards(db sq.BaseRunner, teamID, userID string) ([
},
})
ss, pp, _ := query.ToSql()
s.logger.Error(ss)
s.logger.Error(fmt.Sprintf("%v", pp))
rows, err := query.Query()
if err != nil {
s.logger.Error(`getTemplateBoards ERROR`, mlog.Err(err))

View file

@ -124,7 +124,6 @@ type Store interface {
GetNotificationHint(blockID string) (*model.NotificationHint, error)
GetNextNotificationHint(remove bool) (*model.NotificationHint, error)
GetDefaultTemplates() ([]*model.Board, error)
RemoveDefaultTemplates(boards []*model.Board) error
GetTemplateBoards(teamID, userID string) ([]*model.Board, error)