Ejemplo n.º 1
0
        /// <summary>
        /// Update the role of a user in the specified course
        /// </summary>
        public bool UpdateRole(string username, int courseID, string role, IProviderTransaction tran)
        {
            //Check permission
            Authorize(courseID, Permission.COURSE, "updateuserrole", courseID, tran);

            return(m_dp.UpdateCourseRole(username, courseID, role, tran));
        }
Ejemplo n.º 2
0
 private void CheckThrowTransactionActive(IProviderTransaction providerTransaction)
 {
     if (providerTransaction.IsTransactional && providerTransaction.WasCommitted)
     {
         throw new TransactionCompletedException("Transaction cannot be completed as it is not active. Transaction type: " + providerTransaction.GetType().FullName);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a new user
        /// </summary>
        public bool Create(string username, string password,
                           string first, string last, string email,
                           IProviderTransaction tran)
        {
            if (GetInfo(username, null) != null)
            {
                throw new DataAccessException("User already exists");
            }

            if (password.Length < Globals.MinPasswordLength)
            {
                throw new
                      DataAccessException("Password must be at least " + Globals.MinPasswordLength +
                                          " characters long!");
            }

            User user = new User();

            user.UserName  = username;
            user.FirstName = first;
            user.LastName  = last;
            user.Email     = email;
            user.VerifyKey = Globals.GeneratePassword(8);

            bool result = m_dp.CreateUser(user, password, tran);

            if (result)
            {
                SendVerifyEmail(user);
            }
            return(result);
        }
Ejemplo n.º 4
0
 private void ConditionalRollback(IProviderTransaction providerTransaction)
 {
     if (providerTransaction.IsTransactional && providerTransaction.IsActive)
     {
         providerTransaction.Rollback(this);
     }
 }
Ejemplo n.º 5
0
 protected AbstractEntityRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext)
     : base(providerMetadata, frameworkContext)
 {
     Transaction = providerTransaction;
     Revisions   = new NullProviderRevisionRepository <TypedEntity>(providerMetadata, frameworkContext);
     Schemas     = new NullProviderSchemaRepository(providerMetadata, frameworkContext);
 }
 protected AbstractSchemaRepository(ProviderMetadata providerMetadata, AbstractRevisionRepository <EntitySchema> revisions, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext)
     : base(providerMetadata, revisions, frameworkContext)
 {
     CanWrite    = true;
     Transaction = providerTransaction;
     Revisions   = revisions;
     Revisions.RelatedEntitiesLoader = x => ProviderRepositoryHelper.CreateRelationLazyLoadDelegate(this, x).Invoke(x);
 }
Ejemplo n.º 7
0
 private void ConditionalCommit(IProviderTransaction providerTransaction)
 {
     if (providerTransaction.IsTransactional && providerTransaction.IsActive)
     {
         providerTransaction.Commit(this);
         _committedTransactions.Add(providerTransaction);
     }
 }
Ejemplo n.º 8
0
 public SchemaRepository(ProviderMetadata providerMetadata, AbstractRevisionRepository <EntitySchema> revisions, IProviderTransaction providerTransaction, ISession nhSession, IFrameworkContext frameworkContext,
                         bool isReadOnly)
     : base(providerMetadata, revisions, providerTransaction, frameworkContext)
 {
     IsReadonly  = isReadOnly;
     Transaction = providerTransaction;
     Helper      = new NhSessionHelper(nhSession, frameworkContext);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Verify the user running the component has permissions
 /// Direct Provider layer call
 /// </summary>
 protected void Authorize(int courseID, string etype, string perm, int entityID,
                          IProviderTransaction tran)
 {
     if (!m_dp.CheckPermission(m_ident.Name, courseID, perm, entityID, etype, tran))
     {
         throw new DataAccessException("Permission denied for action: " + perm);
     }
 }
 protected AbstractRevisionRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext)
     : base(providerMetadata, frameworkContext)
 {
     CanWrite    = true;
     Transaction = providerTransaction;
     RevisionDataAddedOrUpdated = new HashSet <RevisionData>();
     EntityDataAddedOrUpdated   = new HashSet <T>();
 }
Ejemplo n.º 11
0
 public RevisionRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, ISession nhSession, IFrameworkContext frameworkContext,
                           bool isReadOnly)
     : base(providerMetadata, providerTransaction, frameworkContext)
 {
     IsReadonly  = isReadOnly;
     Transaction = providerTransaction;
     Helper      = new NhSessionHelper(nhSession, frameworkContext);
 }
Ejemplo n.º 12
0
 public RevisionRepository(
     ProviderMetadata providerMetadata,
     IProviderTransaction providerTransaction,
     IFrameworkContext frameworkContext,
     ExamineHelper helper)
     : base(providerMetadata, providerTransaction, frameworkContext)
 {
     Helper             = helper;
     ExamineTransaction = providerTransaction as ExamineTransaction;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Returns extended user information
        /// If the user is unknown, error handling takes place
        /// </summary>
        public User GetInfo(string username, IProviderTransaction tran)
        {
            User user = new User();

            if (!m_dp.GetUserInfo(username, user, tran))
            {
                //TODO: Do error handling stuff
                return(null);
            }
            return(user);
        }
Ejemplo n.º 14
0
 public EntityRepository(
     ProviderMetadata providerMetadata,
     IProviderTransaction providerTransaction,
     IFrameworkContext frameworkContext,
     AbstractRevisionRepository <TypedEntity> revisionRepository,
     AbstractSchemaRepository schemaSession,
     ExamineHelper helper)
     : base(providerMetadata, providerTransaction, revisionRepository, schemaSession, frameworkContext)
 {
     Helper             = helper;
     ExamineTransaction = providerTransaction as ExamineTransaction;
     Mandate.That(ExamineTransaction != null, x => new InvalidCastException("The IProviderTransaction for the Examine EntityRepository must be of Type ExamineTransaction"));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Get staff roles from a course
 /// </summary>
 public CourseRole.CourseRoleList GetTypedRoles(int courseID, bool staff, IProviderTransaction tran)
 {
     CourseRole.CourseRoleList roles  = GetRoles(courseID, tran);
     CourseRole.CourseRoleList sroles = new CourseRole.CourseRoleList();
     foreach (CourseRole role in roles)
     {
         if ((staff && role.Staff) || (!staff && !role.Staff))
         {
             sroles.Add(role);
         }
     }
     return(sroles);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Add users to the course from an XML stream
        /// </summary>
        public void BatchAddUsers(Stream xmlStream, int courseID, bool sync)
        {
            //TODO: Error checking
            User  mem     = new User();
            Users usersDB = new Users(m_ident);

            DataSet xmldata = new DataSet();

            xmldata.ReadXml(xmlStream);

            DataRowCollection users = xmldata.Tables["User"].Rows;

            IProviderTransaction tran = m_dp.BeginTransaction();

            foreach (DataRow row in users)
            {
                mem.UserName = (string)row["UserName"];
                string role = (string)row["Role"];

                //Make sure the user is in the system
                if (null == usersDB.GetInfo(mem.UserName, tran))
                {
                    m_dp.RollbackTransaction(tran);
                    throw new DataAccessException("User: "******" is not in the FrontDesk database");
                }

                User.UserList cmems = GetMembers(courseID, tran);
                //The user already exists in the course
                if (cmems.Contains(mem))
                {
                    if (sync)
                    {
                        UpdateRole(mem.UserName, courseID, role, tran);
                    }
                    else
                    {
                        m_dp.RollbackTransaction(tran);
                        throw new DataAccessException("User: "******" already exists in the course. " +
                                                      "Do a merge if you want to change the roles");
                    }
                }
                else
                {
                    m_dp.CreateCourseMember(mem.UserName, courseID, role, tran);
                }
            }
            m_dp.CommitTransaction(tran);
        }
Ejemplo n.º 17
0
 private void ConditionalCommit(IProviderTransaction providerTransaction)
 {
     if (providerTransaction.IsTransactional && providerTransaction.IsActive)
     {
         providerTransaction.Commit(this);
         _committedTransactions.Add(providerTransaction);
     }
     else if (!providerTransaction.IsTransactional && providerTransaction.HasCommitalActionsToPerform())
     {
         // The "transaction" is just a placeholder and doesn't commit, but still has actions that need performing
         // e.g. cache clearing. For example the IO provider uses a NullProviderTransaction as of May 2012
         // but still needs to clear relation caches when adding or updating files
         providerTransaction.PerformPreCommitalActions();
     }
 }
Ejemplo n.º 18
0
 protected AbstractEntityRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, AbstractRevisionRepository <TypedEntity> revisions, AbstractSchemaRepository schemas, IFrameworkContext frameworkContext)
     : base(providerMetadata, revisions, schemas, frameworkContext)
 {
     Transaction = providerTransaction;
     Revisions   = revisions;
     Schemas     = schemas;
     Revisions.RelatedEntitiesLoader   = x => ProviderRepositoryHelper.CreateRelationLazyLoadDelegate(this, x).Invoke(x);
     Revisions.RegisterRelatedEntities = relation =>
     {
         if (this.CanWriteRelations)
         {
             this.AddRelation(relation);
         }
     };
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Add a user into a course
        /// </summary>
        public bool AddUser(string username, string role, int courseID, IProviderTransaction tran)
        {
            //Check permission
            if (m_ident.Name != username)
                Authorize(courseID, Permission.COURSE, "adduser", courseID, tran);

            User.UserList cmems = GetMembers(courseID, null);

            //Check an make sure the user isn't already in the course
            foreach (User user in cmems)
                if (user.UserName == username)
                    throw new DataAccessException("User already enrolled in course");

            return m_dp.CreateCourseMember(username, courseID, role, tran);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Get all staff from a course
        /// </summary>
        public User.UserList GetStaff(int courseID, IProviderTransaction tran)
        {
            User.UserList staff = new User.UserList();
            User.UserList all   = GetMembers(courseID, tran);

            //Filter out students
            foreach (User cm in all)
            {
                if (GetRole(cm.UserName, courseID, tran).Staff)
                {
                    staff.Add(cm);
                }
            }

            return(staff);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Create a set of users specified by XML data
        /// </summary>
        public void BatchCreate(Stream xmlStream, bool sync)
        {
            User    user    = new User();
            Users   userDB  = new Users(Globals.CurrentIdentity);
            DataSet xmldata = new DataSet();

            xmldata.ReadXml(xmlStream);
            DataRowCollection users = xmldata.Tables["User"].Rows;

            IProviderTransaction tran = m_dp.BeginTransaction();

            foreach (DataRow row in users)
            {
                user.UserName  = (string)row["UserName"];
                user.FirstName = (string)row["FirstName"];
                user.LastName  = (string)row["LastName"];
                user.Email     = (string)row["Email"];

                //If the user is already in the system
                if (null != userDB.GetInfo(user.UserName, tran))
                {
                    if (sync)
                    {
                        m_dp.UpdateUser(user, tran);
                    }
                    else
                    {
                        m_dp.RollbackTransaction(tran);
                        throw new DataAccessException("User: "******" is already in the FrontDesk database. Use a merge to add additional users.");
                    }
                }
                else
                {
                    string passwd = Globals.GeneratePassword(Globals.MinPasswordLength);
                    m_dp.CreateUser(user, passwd, tran);
                    new EmailWizard(m_ident).SendByUsername(user.UserName, "FrontDesk: User Account Created",
                                                            String.Format(Globals.GetMessage("CreateUser"), user.UserName, passwd,
                                                                          user.Email));
                }
            }
            m_dp.CommitTransaction(tran);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Add a user into a course
        /// </summary>
        public bool AddUser(string username, string role, int courseID, IProviderTransaction tran)
        {
            //Check permission
            if (m_ident.Name != username)
            {
                Authorize(courseID, Permission.COURSE, "adduser", courseID, tran);
            }

            User.UserList cmems = GetMembers(courseID, null);

            //Check an make sure the user isn't already in the course
            foreach (User user in cmems)
            {
                if (user.UserName == username)
                {
                    throw new DataAccessException("User already enrolled in course");
                }
            }

            return(m_dp.CreateCourseMember(username, courseID, role, tran));
        }
Ejemplo n.º 23
0
        public EntityRepository(ProviderMetadata providerMetadata,
                                AbstractSchemaRepository schemas,
                                AbstractRevisionRepository <TypedEntity> revisions,
                                IProviderTransaction providerTransaction,
                                ISession nhSession,
                                IFrameworkContext frameworkContext,
                                bool isReadOnly)
            : base(providerMetadata, providerTransaction, revisions, schemas, frameworkContext)
        {
            Helper     = new NhSessionHelper(nhSession, frameworkContext);
            IsReadonly = isReadOnly;

#if DEBUG
            if (schemas is SchemaRepository)
            {
                var sesh = schemas as SchemaRepository;
                if (sesh.Helper.NhSession != Helper.NhSession)
                {
                    throw new InvalidOperationException("NHibernate provider can only be used in conjunction with an NHibernate schema provider when they share the same NHibernate session");
                }
            }
#endif
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Clear job from queue and actives
 /// Direct Provider layer call
 /// </summary>
 public bool Finish(int jobID, IProviderTransaction tran)
 {
     return(m_dp.DeleteAutoJob(jobID, tran));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Get all the role in a course
 /// Direct Provider layer call
 /// </summary>
 public CourseRole.CourseRoleList GetRoles(int courseID, IProviderTransaction tran)
 {
     return m_dp.GetCourseRoles(courseID, tran);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Get a user's role
 /// </summary>
 public CourseRole GetRole(string username, int courseID, IProviderTransaction tran)
 {
     return m_dp.GetUserCourseRole(username, courseID, tran);
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Create a new user
        /// </summary>
        public bool Create(string username, string password, 
            string first, string last, string email,
            IProviderTransaction tran)
        {
            if (GetInfo(username, null) != null)
                throw new DataAccessException("User already exists");

            if (password.Length < Globals.MinPasswordLength)
                throw new
                    DataAccessException("Password must be at least " + Globals.MinPasswordLength +
                    " characters long!");

            User user = new User();
            user.UserName = username;
            user.FirstName = first;
            user.LastName = last;
            user.Email = email;
            user.VerifyKey = Globals.GeneratePassword(8);

            bool result = m_dp.CreateUser(user, password, tran);
            if (result)
                SendVerifyEmail(user);
            return result;
        }
Ejemplo n.º 28
0
 public ISession GetSessionFromTransaction(IProviderTransaction transaction, bool isReadonly)
 {
     var nhTransaction = transaction as NhProviderTransaction;
     return nhTransaction != null ? nhTransaction.NhSession : GetNHibernateSession(isReadonly);
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Update the role of a user in the specified course
        /// </summary>
        public bool UpdateRole(string username, int courseID, string role, IProviderTransaction tran)
        {
            //Check permission
            Authorize(courseID, Permission.COURSE, "updateuserrole", courseID, tran);

            return m_dp.UpdateCourseRole(username, courseID, role, tran);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Update user information
 /// </summary>
 public bool Update(User user, IProviderTransaction tran)
 {
     return m_dp.UpdateUser(user, tran);
 }
Ejemplo n.º 31
0
 private void ConditionalCommit(IProviderTransaction providerTransaction)
 {
     if (providerTransaction.IsTransactional && providerTransaction.IsActive)
     {
         providerTransaction.Commit(this);
         _committedTransactions.Add(providerTransaction);
     }
     else if (!providerTransaction.IsTransactional && providerTransaction.HasCommitalActionsToPerform())
     {
         // The "transaction" is just a placeholder and doesn't commit, but still has actions that need performing
         // e.g. cache clearing. For example the IO provider uses a NullProviderTransaction as of May 2012
         // but still needs to clear relation caches when adding or updating files
         providerTransaction.PerformPreCommitalActions();
     }
 }
Ejemplo n.º 32
0
 private void CheckThrowTransactionActive(IProviderTransaction providerTransaction)
 {
     if (providerTransaction.IsTransactional && providerTransaction.WasCommitted)
         throw new TransactionCompletedException("Transaction cannot be completed as it is not active. Transaction type: " + providerTransaction.GetType().FullName);
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Get auto jobs for this asst
 /// Direct Provider layer call
 /// </summary>
 public AutoJob.AutoJobList GetAutoJobs(int asstID, IProviderTransaction tran)
 {
     return m_dp.GetAllAsstJobs(asstID, tran);
 }
Ejemplo n.º 34
0
 protected void Authorize(int courseID, string perm, int entityID, IProviderTransaction tran)
 {
     Authorize(courseID, Permission.ASSIGNMENT, perm, entityID, tran);
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Get all staff from a course
        /// </summary>
        public User.UserList GetStaff(int courseID, IProviderTransaction tran)
        {
            User.UserList staff = new User.UserList();
            User.UserList all = GetMembers(courseID, tran);

            //Filter out students
            foreach (User cm in all)
                 if (GetRole(cm.UserName, courseID, tran).Staff)
                     staff.Add(cm);

            return staff;
        }
Ejemplo n.º 36
0
 protected void Authorize(int courseID, string perm, int entityID, IProviderTransaction tran)
 {
     Authorize(courseID, Permission.ASSIGNMENT, perm, entityID, tran);
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Get staff roles from a course
 /// </summary>
 public CourseRole.CourseRoleList GetTypedRoles(int courseID, bool staff, IProviderTransaction tran)
 {
     CourseRole.CourseRoleList roles = GetRoles(courseID, tran);
     CourseRole.CourseRoleList sroles = new CourseRole.CourseRoleList();
     foreach (CourseRole role in roles)
         if ((staff && role.Staff) || (!staff && !role.Staff))
             sroles.Add(role);
     return sroles;
 }
Ejemplo n.º 38
0
 private void ConditionalRollback(IProviderTransaction providerTransaction)
 {
     if (providerTransaction.IsTransactional && providerTransaction.IsActive)
         providerTransaction.Rollback(this);
 }
Ejemplo n.º 39
0
        public EntityRepository(ProviderMetadata providerMetadata, AbstractSchemaRepository schemas, AbstractRevisionRepository <TypedEntity> revisions, IProviderTransaction providerTransaction, Settings settings, IFrameworkContext frameworkContext)
            : base(providerMetadata, providerTransaction, revisions, schemas, frameworkContext)
        {
            Settings = settings;

            EnsureRootPath();
        }
Ejemplo n.º 40
0
 /// <summary>
 /// Verify the user running the component has permissions
 /// Direct Provider layer call
 /// </summary>
 protected void Authorize(int courseID, string etype, string perm, int entityID, 
     IProviderTransaction tran)
 {
     if (!m_dp.CheckPermission(m_ident.Name, courseID, perm, entityID, etype, tran))
         throw new DataAccessException("Permission denied for action: " + perm);
 }
Ejemplo n.º 41
0
        public ISession GetSessionFromTransaction(IProviderTransaction transaction, bool isReadonly)
        {
            var nhTransaction = transaction as NhProviderTransaction;

            return(nhTransaction != null ? nhTransaction.NhSession : GetNHibernateSession(isReadonly));
        }
Ejemplo n.º 42
0
 /// <summary>
 /// Get all members of a course
 /// Direct Provider layer call
 /// </summary>
 public User.UserList GetMembers(int courseID, IProviderTransaction tran)
 {
     return m_dp.GetCourseMembers(courseID, tran);
 }
Ejemplo n.º 43
0
 /// <summary>
 /// Returns extended user information
 /// If the user is unknown, error handling takes place
 /// </summary>
 public User GetInfo(string username, IProviderTransaction tran)
 {
     User user = new User();
     if (!m_dp.GetUserInfo(username, user, tran)) {
         //TODO: Do error handling stuff
         return null;
     }
     return user;
 }
Ejemplo n.º 44
0
 public SchemaRepository(ProviderMetadata providerMetadata, AbstractRevisionRepository <EntitySchema> revisions, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext, DependencyHelper helper)
     : base(providerMetadata, revisions, providerTransaction, frameworkContext)
 {
     _helper = helper;
 }
Ejemplo n.º 45
0
 public EntityRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext, DependencyHelper helper)
     : base(providerMetadata, providerTransaction, frameworkContext)
 {
     _helper = helper;
 }
Ejemplo n.º 46
0
 public EntityRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, AbstractRevisionRepository <TypedEntity> revisions, AbstractSchemaRepository schemas, IFrameworkContext frameworkContext, DependencyHelper helper)
     : base(providerMetadata, providerTransaction, revisions, schemas, frameworkContext)
 {
     _helper = helper;
 }
Ejemplo n.º 47
0
 /// <summary>
 /// Clear job from queue and actives
 /// Direct Provider layer call
 /// </summary>
 public bool Finish(int jobID, IProviderTransaction tran)
 {
     return m_dp.DeleteAutoJob(jobID, tran);
 }
 protected AbstractSchemaRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext)
     : this(providerMetadata, new NullProviderRevisionRepository <EntitySchema>(providerMetadata, frameworkContext), providerTransaction, frameworkContext)
 {
     Transaction = providerTransaction;
 }