示例#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);
        }
        public static AppDiscordApplication Map(DiscordApplication discordApplication)
        {
            var appDiscordApplication = new AppDiscordApplication();

            appDiscordApplication.Owners = discordApplication.Owners.Select(DiscordUserMapper.Map);

            return(appDiscordApplication);
        }
示例#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);
        }