コード例 #1
0
        public async Task <IActionResult> SavePresentation([FromBody] BoardPresentation boardPresentation)
        {
            if (!string.IsNullOrEmpty(boardPresentation.Id) && boardPresentation.Credentials.Password == null)
            {
                boardPresentation.Credentials = (await dbClient.GetPresentation(boardPresentation.Id)).Credentials;
            }

            if (ldapClient.CheckCredentials(boardPresentation.Credentials.Username, boardPresentation.Credentials.Password, false))
            {
                if (ModelState.IsValid)
                {
                    await dbClient.SavePresentationsAsync(boardPresentation);
                }
                else
                {
                    return(BadRequest("Invalid user input. Check allowed range for time values."));
                }

                boardPresentation.Credentials = null;
                return(Ok(boardPresentation));
            }
            else
            {
                return(Unauthorized());
            }
        }
コード例 #2
0
        /// <summary>
        /// Helper function to get board names from Jira.
        /// </summary>
        /// <param name="boardPresentationDbModel">An object containing presentation data stored in db, which will be supplemented with board names from Jira.</param>
        /// <returns>An object containing all necessary information about a presentation.</returns>
        public async Task <BoardPresentation> MakeViewable(BoardPresentationDbModel boardPresentationDbModel)
        {
            var boardPresentation = new BoardPresentation
            {
                Id          = boardPresentationDbModel.Id,
                Title       = boardPresentationDbModel.Title,
                Owner       = boardPresentationDbModel.Owner,
                Credentials = boardPresentationDbModel.Credentials,
                Boards      = new FullBoardList
                {
                    Values = new List <Value>()
                }
            };

            foreach (var boardDbModel in boardPresentationDbModel.Boards)
            {
                var boardName = await jiraClient.GetBoardDataAsync <BoardName>("agile/1.0/board/" + boardDbModel.Id, boardPresentation.Credentials);

                boardPresentation.Boards.Values.Add(new Value
                {
                    Id          = boardDbModel.Id,
                    Name        = (boardName == null) ? "<panelis nepieejams>" : boardName.Name,
                    Visibility  = boardDbModel.Visibility,
                    TimeShown   = boardDbModel.TimeShown,
                    RefreshRate = boardDbModel.RefreshRate
                });
            }

            return(boardPresentation);
        }
コード例 #3
0
        /// <summary>
        /// Saves a presentation to database.
        /// </summary>
        /// <param name="entry">An object containing presentation data to be saved.</param>
        /// <returns>The result of the save operation.</returns>
        public async Task <Task> SavePresentationsAsync(BoardPresentation entry)
        {
            if (string.IsNullOrEmpty(entry.Id))
            {
                entry.Id = (await GeneratePresentationId()).ToString();
            }

            var entryDbModel = new BoardPresentationDbModel
            {
                Id          = entry.Id,
                Title       = entry.Title,
                Owner       = entry.Owner,
                Credentials = entry.Credentials,
                Boards      = new List <BoardDbModel>()
            };

            foreach (var board in entry.Boards.Values)
            {
                entryDbModel.Boards.Add(new BoardDbModel
                {
                    Id          = board.Id,
                    Visibility  = board.Visibility,
                    TimeShown   = board.TimeShown,
                    RefreshRate = board.RefreshRate
                });
            }

            if (entryDbModel.Id == null)
            {
                return(presentationCollection.InsertOneAsync(entryDbModel));
            }
            return(presentationCollection.ReplaceOneAsync(i => i.Id == entryDbModel.Id, entryDbModel, new UpdateOptions {
                IsUpsert = true
            }));
        }
コード例 #4
0
        public PresentationsControllerTests()
        {
            jiraClient  = new Mock <IJiraClient>();
            dbClient    = new Mock <IDbClient>();
            ldapClient  = new Mock <ILdapClient>();
            credentials = new Credentials {
                Username = "", Password = ""
            };

            presentation1 = new BoardPresentationDbModel()
            {
                Id          = "1",
                Title       = "first presentation",
                Owner       = "first owner",
                Credentials = new Credentials
                {
                    Username = "******",
                    Password = "******"
                },
                Boards = new List <BoardDbModel>()
                {
                    new BoardDbModel()
                    {
                        Id = "74"
                    },
                    new BoardDbModel()
                    {
                        Id = "75"
                    }
                }
            };

            presentation2 = new BoardPresentationDbModel()
            {
                Id          = "2",
                Title       = "second presentation",
                Owner       = "second owner",
                Credentials = new Credentials
                {
                    Username = "******",
                    Password = "******"
                },
                Boards = new List <BoardDbModel>()
                {
                    new BoardDbModel()
                    {
                        Id = "76"
                    },
                    new BoardDbModel()
                    {
                        Id = "77"
                    }
                }
            };

            boardPresentation = new BoardPresentation
            {
                Id          = "3",
                Title       = "third presentation",
                Owner       = "third owner",
                Credentials = new Credentials
                {
                    Username = "******",
                    Password = "******"
                },
                Boards = new FullBoardList
                {
                    Values = new List <Value>()
                    {
                        new Value()
                        {
                            Id = "74"
                        },
                        new Value()
                        {
                            Id = "75"
                        }
                    }
                }
            };

            presentationList = new List <BoardPresentationDbModel>()
            {
                presentation1,
                presentation2
            };

            boardName1 = new BoardName
            {
                Id   = "74",
                Name = "board1 name"
            };

            boardName2 = new BoardName
            {
                Id   = "75",
                Name = "board2 name"
            };

            controller = new PresentationsController(jiraClient.Object, dbClient.Object, ldapClient.Object);
        }