Skip to content

Commit

Permalink
Merge branch 'main' into issue-3509
Browse files Browse the repository at this point in the history
  • Loading branch information
mattermod authored Aug 5, 2022
2 parents 3d17863 + 287a026 commit 3377097
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 16 deletions.
9 changes: 9 additions & 0 deletions mattermost-plugin/webapp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ export default class Plugin {
}
})

let fbPrevTeamID = store.getState().teams.currentId
store.subscribe(() => {
const currentTeamID = store.getState().teams.currentId
if (currentTeamID && currentTeamID !== fbPrevTeamID) {
fbPrevTeamID = currentTeamID
selectTeam(currentTeamID)
}
})

if (this.registry.registerProduct) {
windowAny.frontendBaseURL = subpath + '/boards'

Expand Down
25 changes: 16 additions & 9 deletions server/services/store/mattermostauthlayer/mattermostauthlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,18 @@ func (s *MattermostAuthLayer) SearchBoardsForUser(term, userID string) ([]*model
From(s.tablePrefix + "boards as b").
LeftJoin(s.tablePrefix + "board_members as bm on b.id=bm.board_id").
LeftJoin("TeamMembers as tm on tm.teamid=b.team_id").
LeftJoin("ChannelMembers as cm on cm.channelId=b.channel_id").
Where(sq.Eq{"b.is_template": false}).
Where(sq.Eq{"tm.userID": userID}).
Where(sq.Eq{"tm.deleteAt": 0}).
Where(sq.Or{
sq.Eq{"b.type": model.BoardTypeOpen},
sq.And{
sq.Eq{"b.type": model.BoardTypePrivate},
sq.Eq{"bm.user_id": userID},
sq.Or{
sq.Eq{"bm.user_id": userID},
sq.Eq{"cm.userId": userID},
},
},
})

Expand Down Expand Up @@ -684,21 +688,21 @@ func (s *MattermostAuthLayer) implicitBoardMembershipsFromRows(rows *sql.Rows) (
func (s *MattermostAuthLayer) GetMemberForBoard(boardID, userID string) (*model.BoardMember, error) {
bm, err := s.Store.GetMemberForBoard(boardID, userID)
if model.IsErrNotFound(err) {
b, err := s.Store.GetBoard(boardID)
if err != nil {
return nil, err
b, boardErr := s.Store.GetBoard(boardID)
if boardErr != nil {
return nil, boardErr
}
if b.ChannelID != "" {
_, err := s.servicesAPI.GetChannelMember(b.ChannelID, userID)
if err != nil {
_, memberErr := s.servicesAPI.GetChannelMember(b.ChannelID, userID)
if memberErr != nil {
var appErr *mmModel.AppError
if errors.As(err, &appErr) && appErr.StatusCode == http.StatusNotFound {
if errors.As(memberErr, &appErr) && appErr.StatusCode == http.StatusNotFound {
// Plugin API returns error if channel member doesn't exist.
// We're fine if it doesn't exist, so its not an error for us.
return nil, nil
return nil, model.NewErrNotFound(userID)
}

return nil, err
return nil, memberErr
}

return &model.BoardMember{
Expand All @@ -713,6 +717,9 @@ func (s *MattermostAuthLayer) GetMemberForBoard(boardID, userID string) (*model.
}, nil
}
}
if err != nil {
return nil, err
}
return bm, nil
}

Expand Down
7 changes: 0 additions & 7 deletions webapp/src/components/shareBoard/teamPermissionsRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ const TeamPermissionsRow = (): JSX.Element => {
/>
</button>
<Menu position='left'>
<Menu.Text
id='Admin'
check={board.minimumRole === 'admin'}
icon={board.type === BoardTypeOpen && board.minimumRole === 'admin' ? <CheckIcon/> : null}
name={intl.formatMessage({id: 'BoardMember.schemeAdmin', defaultMessage: 'Admin'})}
onClick={() => updateBoardType(board, BoardTypeOpen, 'admin')}
/>
<Menu.Text
id='Editor'
check={board.minimumRole === '' || board.minimumRole === 'editor' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,133 @@ exports[`components/sidebarCategory sidebar call hideSidebar 2`] = `
</div>
</div>
`;

exports[`components/sidebarCategory sidebar collapsed with active board in it 1`] = `
<div>
<div
class="SidebarCategory"
>
<div
class="octo-sidebar-item category ' collapsed "
>
<div
class="octo-sidebar-title category-title"
title="Category 1"
>
<i
class="CompassIcon icon-chevron-right ChevronRightIcon"
/>
Category 1
</div>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<button
class="IconButton"
type="button"
>
<i
class="CompassIcon icon-dots-horizontal OptionsIcon"
/>
</button>
</div>
</div>
<div
class="SidebarBoardItem subitem active"
>
<div
class="octo-sidebar-icon"
>
i
</div>
<div
class="octo-sidebar-title"
title="board title"
>
board title
</div>
<div
aria-label="menuwrapper"
class="MenuWrapper x"
role="button"
>
<button
class="IconButton"
type="button"
>
<i
class="CompassIcon icon-dots-horizontal OptionsIcon"
/>
</button>
</div>
</div>
<div
class="SidebarBoardItem sidebar-view-item active"
>
<svg
class="BoardIcon Icon"
fill="currentColor"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<g
opacity="0.8"
>
<path
clip-rule="evenodd"
d="M4 4H20V20H4V4ZM2 4C2 2.89543 2.89543 2 4 2H20C21.1046 2 22 2.89543 22 4V20C22 21.1046 21.1046 22 20 22H4C2.89543 22 2 21.1046 2 20V4ZM8 6H6V12H8V6ZM11 6H13V16H11V6ZM18 6H16V9H18V6Z"
fill="currentColor"
fill-rule="evenodd"
/>
</g>
</svg>
<div
class="octo-sidebar-title"
title="view title"
>
view title
</div>
</div>
</div>
</div>
`;

exports[`components/sidebarCategory sidebar collapsed without active board 1`] = `
<div>
<div
class="SidebarCategory"
>
<div
class="octo-sidebar-item category ' collapsed "
>
<div
class="octo-sidebar-title category-title"
title="Category 1"
>
<i
class="CompassIcon icon-chevron-right ChevronRightIcon"
/>
Category 1
</div>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<button
class="IconButton"
type="button"
>
<i
class="CompassIcon icon-dots-horizontal OptionsIcon"
/>
</button>
</div>
</div>
</div>
</div>
`;
49 changes: 49 additions & 0 deletions webapp/src/components/sidebar/sidebarCategory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,53 @@ describe('components/sidebarCategory', () => {
userEvent.click(subItems[0] as Element)
expect(container).toMatchSnapshot()
})

test('sidebar collapsed without active board', () => {
const mockStore = configureStore([])
const store = mockStore(state)

const component = wrapIntl(
<ReduxProvider store={store}>
<Router history={history}>
<SidebarCategory
hideSidebar={() => {}}
categoryBoards={categoryBoards1}
boards={boards}
allCategories={allCategoryBoards}
/>
</Router>
</ReduxProvider>,
)
const {container} = render(component)

const subItems = container.querySelectorAll('.category-title')
expect(subItems).toBeDefined()
userEvent.click(subItems[0] as Element)
expect(container).toMatchSnapshot()
})

test('sidebar collapsed with active board in it', () => {
const mockStore = configureStore([])
const store = mockStore(state)

const component = wrapIntl(
<ReduxProvider store={store}>
<Router history={history}>
<SidebarCategory
hideSidebar={() => {}}
activeBoardID={board1.id}
categoryBoards={categoryBoards1}
boards={boards}
allCategories={allCategoryBoards}
/>
</Router>
</ReduxProvider>,
)
const {container} = render(component)

const subItems = container.querySelectorAll('.category-title')
expect(subItems).toBeDefined()
userEvent.click(subItems[0] as Element)
expect(container).toMatchSnapshot()
})
})
17 changes: 17 additions & 0 deletions webapp/src/components/sidebar/sidebarCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ const SidebarCategory = (props: Props) => {
defaultMessage='No boards inside'
/>
</div>}
{collapsed && props.boards.filter((board: Board) => board.id === props.activeBoardID).map((board: Board) => {
if (!isBoardVisible(board.id)) {
return null
}
return (
<SidebarBoardItem
key={board.id}
board={board}
categoryBoards={props.categoryBoards}
allCategories={props.allCategories}
isActive={board.id === props.activeBoardID}
showBoard={showBoard}
showView={showView}
onDeleteRequest={setDeleteBoard}
/>
)
})}
{!collapsed && props.boards.map((board: Board) => {
if (!isBoardVisible(board.id)) {
return null
Expand Down

0 comments on commit 3377097

Please sign in to comment.