Esempio n. 1
0
        public void MultipleUserTypeClaimsShouldMatchAllTypes()
        {
            var principal = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(AllReady.Security.ClaimTypes.UserType, "SiteAdmin"),
                new Claim(AllReady.Security.ClaimTypes.UserType, "OrgAdmin"),
                new Claim(AllReady.Security.ClaimTypes.UserType, "BasicUser")
            }));

            Assert.True(principal.IsUserType(UserType.SiteAdmin));
            Assert.True(principal.IsUserType(UserType.OrgAdmin));
            Assert.True(principal.IsUserType(UserType.BasicUser));
        }
Esempio n. 2
0
        public void MultipleUserTypeClaimsShouldMatchAllTypes()
        {
            ClaimsPrincipal principal = new ClaimsPrincipal(
                new ClaimsIdentity(
                        new[]
                        {
                            new Claim(AllReady.Security.ClaimTypes.UserType, "SiteAdmin"),
                            new Claim(AllReady.Security.ClaimTypes.UserType, "TenantAdmin"),
                        }
                    ));

            Assert.True(principal.IsUserType(UserType.SiteAdmin));
            Assert.True(principal.IsUserType(UserType.TenantAdmin));
        }
        public IEnumerable<SelectListItem> GetOrganizations(ClaimsPrincipal user)
        {
            // Default to authorizing the return of no organizations
            var listOfOrganizations = new List<SelectListItem>();

            if (user.IsUserType(UserType.SiteAdmin))
            {
                listOfOrganizations = GetOrganizationsForSiteAdmin();
            }
            else if (user.IsUserType(UserType.OrgAdmin))
            {
                listOfOrganizations = GetOrganizationForOrgAdmin(user);
            }

            return listOfOrganizations;
        }
Esempio n. 4
0
        public void OrganizationAdminUserShouldNotMatchSiteAdmin()
        {
            ClaimsPrincipal principal = new ClaimsPrincipal(
                new ClaimsIdentity(
                        new[]
                        {
                            new Claim(AllReady.Security.ClaimTypes.UserType, "OrgAdmin")
                        }
                    ));

            Assert.False(principal.IsUserType(UserType.SiteAdmin));
        }
Esempio n. 5
0
 public void SiteAdminUserShouldMatchSiteAdmin()
 {
     ClaimsPrincipal principal = new ClaimsPrincipal(
         new ClaimsIdentity(
                 new[] 
                 {
                     new Claim(AllReady.Security.ClaimTypes.UserType, "SiteAdmin")
                 }
             ));
    
     Assert.True(principal.IsUserType(UserType.SiteAdmin));
 }
Esempio n. 6
0
        public bool For(ClaimsPrincipal user, AllReadyTask task, UserManager<ApplicationUser> userManager)
        {
            var userId = userManager.GetUserId(user);

            if (user.IsUserType(UserType.SiteAdmin))
            {
                return true;
            }

            if (user.IsUserType(UserType.OrgAdmin))
            {
                //TODO: Modify to check that user is organization admin for organization of task
                return true;
            }

            if (task.Event?.Organizer != null && task.Event.Organizer.Id == userId)
            {
                return true;
            }

            if (task.Event?.Campaign?.Organizer != null && task.Event.Campaign.Organizer.Id == userId)
            {
                return true;
            }

            return false;
        }
Esempio n. 7
0
        public void OrganizationAdminUserShouldMatchOrganizationAdmin()
        {
            var principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(AllReady.Security.ClaimTypes.UserType, "OrgAdmin") }));

            Assert.True(principal.IsUserType(UserType.OrgAdmin));
        }
Esempio n. 8
0
 public void UserWithNoUserTypeClaimShouldNotMatchSiteAdmin()
 {
     var principal = new ClaimsPrincipal();
     Assert.False(principal.IsUserType(UserType.SiteAdmin));
 }