Exemplo n.º 1
0
        /// <summary>
        /// Returns true if the user is currently in the role of PP Admin and acts on behalf of specific place.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="userRepository"></param>
        /// <param name="placeProviderRepository"></param>
        /// <param name="placeRepository"></param>
        /// <param name="placeId"></param>
        /// <returns></returns>
        public static async Task <bool> IsPlaceAdmin(
            this ClaimsPrincipal user,
            IUserRepository userRepository,
            IPlaceProviderRepository placeProviderRepository,
            IPlaceRepository placeRepository,
            string placeId
            )
        {
            var place = await placeRepository.GetPlace(placeId);

            if (place == null)
            {
                return(false);
            }
            if (user.IsAdmin(userRepository))
            {
                return(true);
            }
            var pp = GetPlaceProvider(user);

            if (pp != place.PlaceProviderId)
            {
                return(false);
            }
            return(await placeProviderRepository.InAnyGroup(user.GetEmail(), pp, new string[] { Groups.PPAdmin }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns true if the user is currently in the role of PP Admin.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="userRepository"></param>
        /// <param name="placeProviderRepository"></param>
        /// <returns></returns>
        public static async Task <bool> IsPlaceProviderAdmin(this ClaimsPrincipal user, IUserRepository userRepository, IPlaceProviderRepository placeProviderRepository)
        {
            if (user.IsAdmin(userRepository))
            {
                return(true);
            }
            var pp = GetPlaceProvider(user);

            return(await placeProviderRepository.InAnyGroup(user.GetEmail(), pp, new string[] { Groups.PPAdmin }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Log in as company
        /// </summary>
        /// <param name="user"></param>
        /// <param name="userRepository"></param>
        /// <param name="placeProviderRepository"></param>
        /// <param name="placeProviderId"></param>
        /// <returns></returns>
        public static async Task <bool> IsAuthorizedToLogAsCompany(this ClaimsPrincipal user, IUserRepository userRepository, IPlaceProviderRepository placeProviderRepository, string placeProviderId)
        {
            if (user is null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (userRepository is null)
            {
                throw new ArgumentNullException(nameof(userRepository));
            }
            if (user.IsAdmin(userRepository))
            {
                return(true);
            }

            if (placeProviderRepository is null)
            {
                throw new ArgumentNullException(nameof(placeProviderRepository));
            }
            if (string.IsNullOrEmpty(placeProviderId))
            {
                throw new ArgumentNullException(nameof(placeProviderId));
            }

            var email = user.GetEmail();

            var pp = await placeProviderRepository.GetPlaceProvider(placeProviderId);

            if (pp == null)
            {
                return(false);
            }
            if (pp.Users?.Any(u => u.Email == email) == true)
            {
                return(true);
            }
            return(await placeProviderRepository.InAnyGroup(email, placeProviderId, new string[] { Groups.Admin, Groups.PPAdmin, Groups.Accountant, Groups.DataExporter, Groups.DocumentManager, Groups.MedicLab, Groups.MedicTester, Groups.RegistrationManager }));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Accountant or admin is authorized to issue invoice
        /// </summary>
        /// <param name="user"></param>
        /// <param name="userRepository"></param>
        /// <param name="placeProviderRepository"></param>
        /// <param name="placeProviderId"></param>
        /// <returns></returns>
        public static bool IsAuthorizedToIssueInvoice(this ClaimsPrincipal user, IUserRepository userRepository, IPlaceProviderRepository placeProviderRepository, string placeProviderId)
        {
            if (user is null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (userRepository is null)
            {
                throw new ArgumentNullException(nameof(userRepository));
            }
            if (placeProviderRepository is null)
            {
                throw new ArgumentNullException(nameof(placeProviderRepository));
            }
            if (string.IsNullOrEmpty(placeProviderId))
            {
                throw new ArgumentNullException(nameof(placeProviderId));
            }

            var email = user.GetEmail();

            return(placeProviderRepository.InAnyGroup(email, placeProviderId, new string[] { Groups.Admin, Groups.Accountant }).Result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Check if user has role Data exporter
        /// </summary>
        /// <param name="user"></param>
        /// <param name="userRepository"></param>
        /// <param name="placeProviderRepository"></param>
        /// <returns></returns>
        public static bool IsDataExporter(this ClaimsPrincipal user, IUserRepository userRepository, IPlaceProviderRepository placeProviderRepository)
        {
            if (user is null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (userRepository is null)
            {
                throw new ArgumentNullException(nameof(userRepository));
            }

            var email = user.GetEmail();
            var pp    = user.GetPlaceProvider();

            if (!string.IsNullOrEmpty(pp))
            {
                if (placeProviderRepository.InAnyGroup(email, pp, new string[] { Groups.DataExporter }).Result)
                {
                    return(true);
                }
            }
            return(userRepository.InAnyGroup(email, new string[] { Groups.DataExporter }, user.GetPlaceProvider()).Result);
        }