public static void GrantPermission <T>(
            this ConsentContext context,
            T securable,
            ConsentRole role,
            string permission) where T : class, ISecurable
        {
            if (context.Set <T>().ToInjectable()
                .Any(_ => _ == securable && _.GrantsPermissionToRole(role, permission)))
            {
                return;
            }

            var permissionEntity = context.Set <PermissionEntity>().SingleOrDefault(_ => _.Access == permission);
            var rolePrincipal    = context.Set <RoleSecurityPrincipal>().SingleOrDefault(_ => _.Role == role)
                                   ?? new RoleSecurityPrincipal {
                Role = role
            };

            context.Set <AccessControlEntity>().Add(
                new AccessControlEntity
            {
                ACL        = securable.ACL,
                Permission = permissionEntity,
                Prinicipal = rolePrincipal
            });
        }
Beispiel #2
0
 /// <inheritdoc />
 public Subject(IUserProvider user, ConsentContext db, IStudySubjectRepository subjects,
                IConsentRepository consents, IIdentityRepository identity)
 {
     Db            = db;
     this.user     = user;
     this.subjects = subjects;
     this.consents = consents;
     this.identity = identity;
 }
        private IdentityRepository CreateRepository(ConsentContext context)
        {
            var registry = new IdentifierDefinitionRegistry(Identifiers.Definitions.KnownIdentifiers)
            {
                testIdentifierDefinition
            };

            return(new IdentityRepository(registry, context));
        }
Beispiel #4
0
        private static IStudySubjectRepository CreateStudySubjectRepository(ConsentContext db)
        {
            var storeProvider = (IStoreProvider) new ContextStoreProvider(db);

            return(new StudySubjectRepository(new StudyRepository(storeProvider.Get <StudyEntity>()),
                                              storeProvider.Get <StudySubjectEntity>(),
                                              storeProvider.Get <PersonEntity>(),
                                              storeProvider.Get <ConsentEntity>()
                                              ));
        }
Beispiel #5
0
        protected DbTests(ITestOutputHelper outputHelper, DatabaseFixture fixture)
        {
            this.outputHelper = outputHelper;
            this.fixture      = fixture;
            Context           = fixture.GetContext(outputHelper);
            transaction       = Context.Database.BeginTransaction();

            createContext = CreateNewContextInSameTransaction();
            updateContext = CreateNewContextInSameTransaction();
            readContext   = CreateNewContextInSameTransaction();
        }
Beispiel #6
0
        /// <summary>
        ///     Creates a new context for the given user pair.
        /// </summary>
        /// <param name="asker">The person that initiated a consent gated action</param>
        /// <param name="askee">
        ///     The person <see cref="askee"/> is asking consent
        ///     from
        /// </param>
        public void Create([NotNull] string asker, [NotNull] string askee)
        {
            var askerContext = new ConsentContext {
                User = askee
            };
            var askeeContext = new ConsentContext {
                User = asker, Agreed = true
            };

            _consentData[asker.ToLowerInvariant()] = askerContext;
            _consentData[askee.ToLowerInvariant()] = askeeContext;
        }
Beispiel #7
0
        /// <summary>
        ///     Returns all offers created by a given user.
        /// </summary>
        /// <param name="username">
        ///     The username of the person that triggered a
        ///     given consensual action
        /// </param>
        public IEnumerable <string> GetAllOffersFor(string username)
        {
            foreach (KeyValuePair <string, ConsentContext> pair in _consentData)
            {
                string         asker   = pair.Key;
                ConsentContext context = pair.Value;

                if (string.Equals(username, context.User, StringComparison.InvariantCultureIgnoreCase))
                {
                    yield return(asker);
                }
            }
        }
Beispiel #8
0
        private static ConsentRepository CreateConsentRepository(
            ConsentContext consentContext,
            params EvidenceDefinition[] evidentTypes)
        {
            var storeProvider = (IStoreProvider) new ContextStoreProvider(consentContext);


            var evidenceRegistry =
                evidentTypes.Any() ? new EvidenceDefinitionRegistry(evidentTypes) : KnownEvidence.Registry;

            return(new ConsentRepository(
                       (StudySubjectRepository)CreateStudySubjectRepository(consentContext),
                       storeProvider.Get <PersonEntity>(),
                       storeProvider.Get <ConsentEntity>(),
                       storeProvider.Get <EvidenceEntity>(),
                       evidenceRegistry
                       ));
        }
Beispiel #9
0
 public ConsentRepository(ConsentContext consentContext)
 {
     this.consentContext = consentContext;
 }
Beispiel #10
0
 public AutoCommitActionFilter(IServiceProvider serviceProvider)
 {
     consentContext = serviceProvider.GetRequiredService <ConsentContext>();
     logger         = serviceProvider.GetRequiredService <ILogger <AutoCommitActionFilter> >();
 }
Beispiel #11
0
 /// <inheritdoc />
 public IQueryable <PersonEntity> ApplyTo(IQueryable <PersonEntity> queryable, ConsentContext context) =>
 queryable.Where(p => PersonIds.Contains(p.Id));
 private IIncludableQueryable <PersonEntity, AccessControlList> People(ConsentContext context)
 {
     return(context.People.AsNoTracking()
            .Include(_ => _.Identifiers)
            .Include(_ => _.ACL));
 }
Beispiel #13
0
 /// <inheritdoc />
 public IQueryable <PersonEntity> ApplyTo(IQueryable <PersonEntity> queryable, ConsentContext context)
 {
     return
         (from person in queryable
          join consent in context.Set <ConsentEntity>()
          on person.Id equals consent.StudySubject.Person.Id
          where consent.StudySubject.Study.Id == studyId
          select person);
 }