Example #1
0
        private FormResult PostCreateThreadForm(Form form)
        {
            // Get logged on user details
            long tenantId = _authenticationService.TenantId;
            long userId   = _authenticationService.GetCurrentUser().User.UserId;

            // Get page and element identifiers
            string[] parts     = form.Context.Split('|');
            long     pageId    = Convert.ToInt64(parts[1]);
            long     elementId = Convert.ToInt64(parts[2]);

            // Get information required to create new thread
            CreateThreadInfo info = new CreateThreadInfo
            {
                ElementId = elementId,
                Message   = ((MultiLineTextField)form.Fields["message"]).Value,
                Notify    = ((BooleanField)form.Fields["notify"]).Value,
                Subject   = ((TextField)form.Fields["subject"]).Value,
                UserId    = userId,
                TenantId  = tenantId
            };

            // Create new thread
            long threadId = _forumService.CreateThread(info);

            // Return form result with no errors
            string status = _forumUrlService.GetThreadUrl(pageId, threadId, info.Subject);

            return(_formHelperService.GetFormResult(status));
        }
Example #2
0
        public long CreateThread(CreateThreadInfo info, IUnitOfWork unitOfWork = null)
        {
            // Check user permissions
            _forumAuthorizer.AuthorizeCreateThread(info);

            // Validate supplied thread details
            _forumValidator.ValidateCreateThread(info);

            // Remove extraneous white space
            info.Subject = info.Subject.Trim();
            info.Message = info.Message.Trim();

            // Create forum thread
            return(_forumRepository.CreateThread(info, DateTime.UtcNow, unitOfWork));
        }
        public void AuthorizeCreateThread(CreateThreadInfo info)
        {
            // Check user has correct role and function membership
            _functionAuthorizer.Authorize(new UserFunction {
                Function = ForumFunctions.ForumUser, UserId = info.UserId, TenantId = info.TenantId
            });

            // Get forum details
            ForumSettings forumSettings = new ForumSettings {
                TenantId = info.TenantId, ElementId = info.ElementId
            };

            _forumRepository.Read(forumSettings);

            // Check that forum owner and thread starter are the same person if forum has owner only threads set true
            if ((forumSettings.OwnerOnlyThreads) && (forumSettings.OwnerUserId != info.UserId || forumSettings.OwnerTenantId != info.TenantId))
            {
                throw new AuthorizationException(string.Format("User {0} not authorized to create thread in forum {1}", info.UserId, info.ElementId));
            }
        }
Example #4
0
        public long CreateThread(CreateThreadInfo info, DateTime created, IUnitOfWork unitOfWork = null)
        {
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            try
            {
                IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork ?? localUnitOfWork);
                string           sql = _sqlManager.GetSql("Sql.CreateForumThread.sql");
                dbm.SetSQL(sql);
                dbm.AddParameter("@TenantId", FieldType.BigInt, info.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, info.ElementId);
                dbm.AddParameter("@Subject", FieldType.NVarChar, 256, info.Subject);
                dbm.AddParameter("@Notify", FieldType.Bit, info.Notify);
                dbm.AddParameter("@UserId", FieldType.BigInt, info.UserId);
                dbm.AddParameter("@Message", FieldType.NVarChar, -1, info.Message);
                dbm.AddParameter("@Created", FieldType.DateTime, created);
                dbm.AddOutputParameter("@ThreadId", FieldType.BigInt);
                Dictionary <string, object> outputValues = new Dictionary <string, object>();
                dbm.ExecuteNonQuery(outputValues);
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
                return((long)outputValues["@ThreadId"]);
            }
            catch (Exception)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }
Example #5
0
 public void ValidateCreateThread(CreateThreadInfo info)
 {
     _modelValidator.Validate(info);
 }