Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/src/api/boards.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (s *Server) joinBoard(w http.ResponseWriter, r *http.Request) {
}

if b.AccessPolicy == boards.Public {
_, err := s.sessions.Create(ctx, board, user)
_, err := s.sessions.Create(ctx, sessions.BoardSessionCreateRequest{Board: board, User: user, Role: common.ParticipantRole})
if err != nil {
span.SetStatus(codes.Error, "failed to create session")
span.RecordError(err)
Expand Down Expand Up @@ -251,7 +251,7 @@ func (s *Server) joinBoard(w http.ResponseWriter, r *http.Request) {
}
encodedPassphrase := common.Sha512BySalt(body.Passphrase, *b.Salt)
if encodedPassphrase == *b.Passphrase {
_, err := s.sessions.Create(ctx, board, user)
_, err := s.sessions.Create(ctx, sessions.BoardSessionCreateRequest{Board: board, User: user, Role: common.ParticipantRole})
if err != nil {
span.SetStatus(codes.Error, "failed to create session")
span.RecordError(err)
Expand Down
3 changes: 2 additions & 1 deletion server/src/api/boards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ func (suite *BoardTestSuite) TestJoinBoard() {
}
} else {
if !te.sessionExists {
sessionMock.EXPECT().Create(mock.Anything, boardID, userID).Return(new(sessions.BoardSession), te.err)
sessionMock.EXPECT().Create(mock.Anything, sessions.BoardSessionCreateRequest{Board: boardID, User: userID, Role: common.ParticipantRole}).
Return(new(sessions.BoardSession), te.err)
}

}
Expand Down
2 changes: 1 addition & 1 deletion server/src/sessionrequests/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (service *BoardSessionRequestService) Update(ctx context.Context, body Boar
}

if request.Status == RequestAccepted {
_, err := service.sessionService.Create(ctx, request.Board, request.User)
_, err := service.sessionService.Create(ctx, sessions.BoardSessionCreateRequest{Board: request.Board, User: request.User, Role: common.ParticipantRole})
if err != nil {
span.SetStatus(codes.Error, "failed to create board session")
span.RecordError(err)
Expand Down
6 changes: 4 additions & 2 deletions server/src/sessionrequests/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"scrumlr.io/server/common"
"scrumlr.io/server/sessions"

"github.com/google/uuid"
Expand Down Expand Up @@ -264,6 +265,7 @@ func TestCreateSessionRequest_DBError(t *testing.T) {
func TestUpdatesessionRequest(t *testing.T) {
boardId := uuid.New()
userId := uuid.New()
role := common.ParticipantRole

user := sessions.User{
ID: userId,
Expand All @@ -273,8 +275,8 @@ func TestUpdatesessionRequest(t *testing.T) {
Return(DatabaseBoardSessionRequest{Board: boardId, User: userId, Status: RequestAccepted}, nil)

mockSessionService := sessions.NewMockSessionService(t)
mockSessionService.EXPECT().Create(mock.Anything, boardId, userId).
Return(&sessions.BoardSession{Board: boardId, User: user}, nil)
mockSessionService.EXPECT().Create(mock.Anything, sessions.BoardSessionCreateRequest{Board: boardId, User: userId, Role: role}).
Return(&sessions.BoardSession{Board: boardId, User: user, Role: role}, nil)

mockBroker := realtime.NewMockClient(t)
mockBroker.EXPECT().Publish(mock.Anything, mock.AnythingOfType("string"), mock.Anything).Return(nil)
Expand Down
2 changes: 1 addition & 1 deletion server/src/sessions/api_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type SessionService interface {
Create(ctx context.Context, boardID, userID uuid.UUID) (*BoardSession, error)
Create(ctx context.Context, body BoardSessionCreateRequest) (*BoardSession, error)
Update(ctx context.Context, body BoardSessionUpdateRequest) (*BoardSession, error)
UpdateAll(ctx context.Context, body BoardSessionsUpdateRequest) ([]*BoardSession, error)
UpdateUserBoards(ctx context.Context, body BoardSessionUpdateRequest) ([]*BoardSession, error)
Expand Down
15 changes: 0 additions & 15 deletions server/src/sessions/database_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sessions
import (
"context"
"database/sql"
"errors"
"log"
"testing"

Expand Down Expand Up @@ -82,20 +81,6 @@ func (suite *DatabaseSessionTestSuite) Test_Database_CreateSession_Moderator() {
assert.NotNil(t, dbSession.CreatedAt)
}

func (suite *DatabaseSessionTestSuite) Test_Database_CreateSession_Owner() {
t := suite.T()
database := NewSessionDatabase(suite.db)

userId := suite.users["Luke"].id
boardId := suite.boards["Write"].id

dbSession, err := database.Create(context.Background(), DatabaseBoardSessionInsert{User: userId, Board: boardId, Role: common.OwnerRole})

assert.NotNil(t, err)
assert.Equal(t, err, errors.New("not allowed to create board session with owner role"))
assert.Equal(t, DatabaseBoardSession{}, dbSession)
}

func (suite *DatabaseSessionTestSuite) Test_Database_CreateSession_Duplicate() {
t := suite.T()
database := NewSessionDatabase(suite.db)
Expand Down
5 changes: 0 additions & 5 deletions server/src/sessions/database_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sessions

import (
"context"
"errors"

"github.com/google/uuid"
"github.com/uptrace/bun"
Expand All @@ -22,10 +21,6 @@ func NewSessionDatabase(database *bun.DB) SessionDatabase {
}

func (database *SessionDB) Create(ctx context.Context, boardSession DatabaseBoardSessionInsert) (DatabaseBoardSession, error) {
if boardSession.Role == common.OwnerRole {
return DatabaseBoardSession{}, errors.New("not allowed to create board session with owner role")
}

var session DatabaseBoardSession
insertQuery := database.db.NewInsert().
Model(&boardSession).
Expand Down
6 changes: 6 additions & 0 deletions server/src/sessions/dto_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ type BoardSession struct {
Board uuid.UUID `json:"-"`
}

type BoardSessionCreateRequest struct {
Board uuid.UUID
User uuid.UUID
Role common.SessionRole
}

// BoardSessionUpdateRequest represents the request to update a single participant.
type BoardSessionUpdateRequest struct {

Expand Down
36 changes: 15 additions & 21 deletions server/src/sessions/mock_SessionService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions server/src/sessions/service_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,31 @@ func NewSessionService(db SessionDatabase, rt *realtime.Broker, columnService co
return service
}

func (service *BoardSessionService) Create(ctx context.Context, boardID, userID uuid.UUID) (*BoardSession, error) {
func (service *BoardSessionService) Create(ctx context.Context, body BoardSessionCreateRequest) (*BoardSession, error) {
log := logger.FromContext(ctx)
ctx, span := tracer.Start(ctx, "scrumlr.sessions.service.create")
defer span.End()

span.SetAttributes(
attribute.String("scrumlr.sessions.service.create.board", boardID.String()),
attribute.String("scrumlr.sessions.service.create.user", userID.String()),
attribute.String("scrumlr.sessions.service.create.board", body.Board.String()),
attribute.String("scrumlr.sessions.service.create.user", body.User.String()),
attribute.String("scrumlr.sessions.service.create.role", string(body.Role)),
)

session, err := service.database.Create(ctx, DatabaseBoardSessionInsert{
Board: boardID,
User: userID,
Role: common.ParticipantRole,
Board: body.Board,
User: body.User,
Role: body.Role,
})

if err != nil {
span.SetStatus(codes.Error, "failed to create board session")
span.RecordError(err)
log.Errorw("unable to create board session", "board", boardID, "user", userID, "error", err)
log.Errorw("unable to create board session", "board", body.Board, "user", body.User, "error", err)
return nil, err
}

service.createdSession(ctx, boardID, session)
service.createdSession(ctx, body.Board, session)

sessionCreatedCounter.Add(ctx, 1)
return new(BoardSession).From(session), err
Expand Down Expand Up @@ -201,7 +202,7 @@ func (service *BoardSessionService) UpdateUserBoards(ctx context.Context, body B

connectedBoards, err := service.database.GetUserConnectedBoards(ctx, body.User)
if err != nil {
span.SetStatus(codes.Error, "failed to update all sessions")
span.SetStatus(codes.Error, "failed to get connected boards")
span.RecordError(err)
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions server/src/sessions/service_sessions_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (suite *SessionServiceIntegrationTestSuite) Test_Create() {

boardId := suite.boards["Write"].id
userId := suite.users["Luke"].ID
role := common.ParticipantRole

broker, err := realtime.NewNats(suite.natsConnectionString)
if err != nil {
Expand All @@ -74,19 +75,19 @@ func (suite *SessionServiceIntegrationTestSuite) Test_Create() {
sessionDatabase := NewSessionDatabase(suite.db)
sessionService := NewSessionService(sessionDatabase, broker, columnService, noteService)

session, err := sessionService.Create(ctx, boardId, userId)
session, err := sessionService.Create(ctx, BoardSessionCreateRequest{Board: boardId, User: userId, Role: role})

assert.Nil(t, err)
assert.Equal(t, boardId, session.Board)
assert.Equal(t, userId, session.User.ID)
assert.Equal(t, common.ParticipantRole, session.Role)
assert.Equal(t, role, session.Role)

msg := <-events
assert.Equal(t, realtime.BoardEventParticipantCreated, msg.Type)
sessionData, err := technical_helper.Unmarshal[BoardSession](msg.Data)
assert.Nil(t, err)
assert.Equal(t, userId, sessionData.User.ID)
assert.Equal(t, common.ParticipantRole, sessionData.Role)
assert.Equal(t, role, sessionData.Role)
}

func (suite *SessionServiceIntegrationTestSuite) Test_Update() {
Expand Down
Loading
Loading