Beispiel #1
0
        public void IsOwnerOrAdmin_WhenOwner_ReturnTrue()
        {
            // Arrange
            _optionsMock.Setup(s => s.Value).Returns(new BotOptions()
            {
                AdminRoleId = 1
            });

            _sut = new AuthorizationService(_optionsMock.Object);

            var member = new AppDiscordMember()
            {
                Id = 1
            };

            var discordApplication = new AppDiscordApplication()
            {
                Owners = new List <AppDiscordUser>()
                {
                    new AppDiscordUser()
                    {
                        Id = 1
                    }
                }
            };

            // Act
            var result = _sut.IsOwnerOrAdmin(member, discordApplication);

            // Assert
            Assert.IsTrue(result);
        }
Beispiel #2
0
        public static AppDiscordMember Map(DiscordMember discordMember)
        {
            var appDiscordMember = new AppDiscordMember();

            appDiscordMember.Id    = discordMember.Id;
            appDiscordMember.Roles = discordMember.Roles.Select(DiscordRoleMapper.Map);

            return(appDiscordMember);
        }
Beispiel #3
0
        public bool IsOwnerOrAdmin(AppDiscordMember member, AppDiscordApplication discordApplication)
        {
            var adminRoleId = _options.AdminRoleId;

            var currentMember = member;

            var botApp = discordApplication;

            var isBotOwner = botApp.Owners.Any(x => x.Id == currentMember.Id);

            if (isBotOwner)
            {
                return(true);
            }

            var currentUserIsAdmin = currentMember.Roles.Select(r => r.Id).Contains(adminRoleId);

            return(currentUserIsAdmin);
        }