Ejemplo n.º 1
0
        public static bool CanGoToFeed(Message discussion, Guid userId)
        {
            if (discussion == null) return false;

            if (discussion.CreateBy == userId) return true;
            if (!CanGoToFeed(discussion.Project, userId)) return false;

            var participiants = new MessageEngine(GetFactory(), null).GetSubscribers(discussion);
            return participiants.Any(r => new Guid(r.ID).Equals(userId)) &&
                   GetTeamSecurityForParticipants(discussion.Project, userId, ProjectTeamSecurity.Messages);
        }
Ejemplo n.º 2
0
        public void SaveOrUpdateTest()
        {
            var daoFactory = new DaoFactory("projects", 0);
            var messageDao = daoFactory.GetMessageDao();

            var message = new Message()
            {
                Title = "New Message",
                Project = daoFactory.GetProjectDao().GetById(1),
                Content = "Content",
            };

            messageDao.Save(message);
        }
Ejemplo n.º 3
0
 public MessageWrapper(Message message)
 {
     Created = (ApiDateTime)message.CreateOn;
     CreatedBy = EmployeeWraper.Get(message.CreateBy);
     Updated = (ApiDateTime)message.LastModifiedOn;
     if (message.CreateBy != message.LastModifiedBy)
         UpdatedBy = EmployeeWraper.Get(message.LastModifiedBy);
     Id = message.ID;
     Text = message.Content;
     Title = message.Title;
     if (message.Project != null)
     {
         ProjectOwner = new SimpleProjectWrapper(message.Project);
     }
     CanEdit = ProjectSecurity.CanEdit(message);
     CommentsCount = message.CommentsCount;
 }
Ejemplo n.º 4
0
 public MessageWrapper(Message message)
 {
     Id = message.ID;
     if (message.Project != null)
     {
         ProjectOwner = new SimpleProjectWrapper(message.Project);
     }
     Title = message.Title;
     Text = message.Content;
     Created = (ApiDateTime)message.CreateOn;
     CreatedBy = new EmployeeWraperFull(CoreContext.UserManager.GetUsers(message.CreateBy));
     Updated = (ApiDateTime)message.LastModifiedOn;
     if (message.CreateBy != message.LastModifiedBy)
     {
         UpdatedBy = EmployeeWraper.Get(message.LastModifiedBy);
     }
     CanEdit = ProjectSecurity.CanEdit(message);
     CommentsCount = message.CommentsCount;
 }
Ejemplo n.º 5
0
        private void LoadDiscussionActionControl(Message discussion)
        {
            var discussionAction = (DiscussionAction)LoadControl(PathProvider.GetFileStaticRelativePath("Messages/DiscussionAction.ascx"));
            discussionAction.Discussion = discussion;
            contentHolder.Controls.Add(discussionAction);

            Master.DisabledPrjNavPanel = true;
        }
Ejemplo n.º 6
0
 public static void DemandEdit(Message message)
 {
     if (!CanEdit(message)) throw CreateSecurityException();
 }
Ejemplo n.º 7
0
 private void LoadDiscussionDetailsControl(Message discussion)
 {
     var discussionDetails = (DiscussionDetails)LoadControl(PathProvider.GetFileStaticRelativePath("Messages/DiscussionDetails.ascx"));
     discussionDetails.Discussion = discussion;
     contentHolder.Controls.Add(discussionDetails);
 }
Ejemplo n.º 8
0
 public static void AttachFileToMessage(Message message, object fileId)
 {
     Global.EngineFactory.GetMessageEngine().AttachFile(message, fileId, false);
 }
Ejemplo n.º 9
0
        public static bool CanEdit(Message message)
        {
            if (!Can(message)) return false;
            if (IsProjectManager(message.Project)) return true;
            if (!CanRead(message)) return false;

            return IsInTeam(message.Project) && message.CreateBy == CurrentUserId;
        }
Ejemplo n.º 10
0
 private void LoadDiscussionDetailsControl(Project project, Message discussion)
 {
     var discussionDetails = (DiscussionDetails)LoadControl(PathProvider.GetControlVirtualPath("DiscussionDetails.ascx"));
     discussionDetails.Discussion = discussion;
     discussionDetails.Project = project;
     contentHolder.Controls.Add(discussionDetails);
 }
Ejemplo n.º 11
0
        public void Delete(Message message)
        {
            if (message == null) throw new ArgumentNullException("message");
            if (message.Project == null) throw new Exception("Project");

            ProjectSecurity.DemandEdit(message);
            TimeLinePublisher.Message(message, EngineResource.ActionText_Delete, UserActivityConstants.ActivityActionType, UserActivityConstants.SmallActivity);

            _messageDao.Delete(message.ID);

            String objectID = String.Format("{0}_{1}", message.UniqID, message.Project.ID);
            NotifySource.Instance.GetSubscriptionProvider().UnSubscribe(NotifyConstants.Event_NewCommentForMessage, objectID);
        }
Ejemplo n.º 12
0
 public static IEnumerable<File> GetMessageFiles(Message message)
 {
     return Global.EngineFactory.GetMessageEngine().GetFiles(message);
 }
Ejemplo n.º 13
0
 public void SendAboutMessageAction(List<IRecipient> recipients, Message message, bool isNew, Hashtable fileListInfoHashtable)
 {
     client.SendNoticeToAsync(
         isNew ? NotifyConstants.Event_MessageCreated : NotifyConstants.Event_MessageEdited,
         message.NotifyId,
         recipients.ToArray(), 
         GetDefaultSenders(recipients.FirstOrDefault()),
         null,
         new TagValue(NotifyConstants.Tag_ProjectID, message.Project.ID),
         new TagValue(NotifyConstants.Tag_ProjectTitle, message.Project.Title),
         new TagValue(NotifyConstants.Tag_EntityTitle, message.Title),
         new TagValue(NotifyConstants.Tag_EntityID, message.ID),
         new TagValue(NotifyConstants.Tag_EventType, isNew ? "NewMessage" : "EditMessage"),
         new TagValue(NotifyConstants.Tag_AdditionalData, new Hashtable { { "MessagePreview", message.Content }, { "Files", fileListInfoHashtable } }),
         ReplyToTagProvider.Comment("project.message", message.ID.ToString()));
 }
Ejemplo n.º 14
0
 public static bool CanRead(Message message)
 {
     if (!IsProjectsEnabled(CurrentUserId)) return false;
     return CanRead(message, CurrentUserId);
 }
Ejemplo n.º 15
0
 public Message SaveOrUpdate(Message message,bool notify, IEnumerable<Guid> participant, IEnumerable<int > fileIds)
 {
     return SaveOrUpdate(message, notify, participant, fileIds, false);
 }
Ejemplo n.º 16
0
        private void NotifyComment(Comment comment, Message message)
        {
            //Don't send anything if notifications are disabled
            if (_engineFactory.DisableNotifications) return;

            NotifyClient.Instance.SendNewComment(message, comment);

            var subscriptionProvider = NotifySource.Instance.GetSubscriptionProvider();
            var recipient = NotifySource.Instance.GetRecipientsProvider().GetRecipient(SecurityContext.CurrentAccount.ID.ToString());
            if (subscriptionProvider.IsUnsubscribe((IDirectRecipient)recipient, NotifyConstants.Event_NewCommentForMessage, message.NotifyId))
                return;

            var objects = new List<String>(subscriptionProvider.GetSubscriptions(NotifyConstants.Event_NewCommentForMessage, recipient));
            var subscribed = !String.IsNullOrEmpty(objects.Find(item => String.Compare(item, message.NotifyId, true) == 0));
            if (!subscribed)
            {
                subscriptionProvider.Subscribe(NotifyConstants.Event_NewCommentForMessage, message.NotifyId, recipient);
            }
        }
Ejemplo n.º 17
0
 public Comment SaveMessageComment(Message message, Comment comment)
 {
     ProjectSecurity.DemandRead(message);
     _engineFactory.GetCommentEngine().SaveOrUpdate(comment);
     NotifyComment(comment, message);
     TimeLinePublisher.Comment(message, EngineResource.ActionText_Add);
     return comment;
 }
Ejemplo n.º 18
0
        protected void NotifyParticipiant(Message message, bool isMessageNew, IEnumerable<Guid> participant, IEnumerable<Files.Core.File> uploadedFiles, bool sendNotify)
        {
            //Don't send anything if notifications are disabled
            if (_engineFactory.DisableNotifications) return;


            var subscriptionProvider = NotifySource.Instance.GetSubscriptionProvider();
            var recipientsProvider = NotifySource.Instance.GetRecipientsProvider();

            var objectId = message.NotifyId;
            var subscriptionRecipients = subscriptionProvider.GetRecipients(NotifyConstants.Event_NewCommentForMessage, objectId);
            var recipients = new HashSet<Guid>(participant) { SecurityContext.CurrentAccount.ID };

            foreach (var subscriptionRecipient in subscriptionRecipients)
            {
                var subscriptionRecipientId = new Guid(subscriptionRecipient.ID);
                if (!recipients.Contains(subscriptionRecipientId))
                {
                    subscriptionProvider.UnSubscribe(NotifyConstants.Event_NewCommentForMessage, objectId, subscriptionRecipient);
                }
            }
            var senders =  recipients.Select(r => recipientsProvider.GetRecipient(r.ToString()))
                .Where(r => r != null && !subscriptionProvider.IsUnsubscribe((IDirectRecipient)r, NotifyConstants.Event_NewCommentForMessage, objectId))
                .ToList();

            senders.ForEach(r => subscriptionProvider.Subscribe(NotifyConstants.Event_NewCommentForMessage, objectId, r));
            senders.RemoveAll(r => r.ID == SecurityContext.CurrentAccount.ID.ToString());

            if (sendNotify && senders.Any())
            {
                NotifyClient.Instance.SendAboutMessageAction(senders, message, isMessageNew, FileEngine.GetFileListInfoHashtable(uploadedFiles));
            }
        }
Ejemplo n.º 19
0
 private void LoadDiscussionActionControl(Project project, Message discussion)
 {
     var discussionAction = (DiscussionAction)LoadControl(PathProvider.GetControlVirtualPath("DiscussionAction.ascx"));
     discussionAction.Project = project;
     discussionAction.Discussion = discussion;
     contentHolder.Controls.Add(discussionAction);
 }
Ejemplo n.º 20
0
        public Message SaveOrUpdate(Message message, bool notify, IEnumerable<Guid> participant, IEnumerable<int> fileIds)
        {
            if (message == null) throw new ArgumentNullException("message");

            var isNew = message.ID == default(int);

            message.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            message.LastModifiedOn = TenantUtil.DateTimeNow();

            if (isNew)
            {
                if (message.CreateBy == default(Guid)) message.CreateBy = SecurityContext.CurrentAccount.ID;
                if (message.CreateOn == default(DateTime)) message.CreateOn = TenantUtil.DateTimeNow();

                ProjectSecurity.DemandCreateMessage(message.Project);
                messageDao.Save(message);
            }
            else
            {
                ProjectSecurity.DemandEdit(message);
                messageDao.Save(message);
            }

            if (fileIds != null)
            {
                foreach (var fileId in fileIds)
                {
                    AttachFile(message, fileId, false);
                }
            }

            if (!participant.Any())
                participant = GetSubscribers(message).Select(r=> new Guid(r.ID));

            NotifyParticipiant(message, isNew, participant, GetFiles(message), notify);

            return message;
        }
Ejemplo n.º 21
0
        protected override void PageLoad()
        {
            Project = RequestContext.GetCurrentProject(false);

            if (RequestContext.IsInConcreteProject())
            {
                var project = RequestContext.GetCurrentProject(false);

                if (project == null)
                {
                    Response.Redirect("messages.aspx", true);
                }
                else
                {
                    if (!ProjectSecurity.CanReadMessages(Project))
                    {
                        Response.Redirect("projects.aspx?prjID=" + project.ID, true);
                    }
                }
            }
            ((IStudioMaster)Master).DisabledSidePanel = true;

            int discussionId;
            if (int.TryParse(UrlParameters.EntityID, out discussionId))
            {
                if (Project == null) return;

                Discussion = Global.EngineFactory.GetMessageEngine().GetByID(discussionId);

                if (string.Compare(UrlParameters.ActionType, "edit", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (ProjectSecurity.CanEdit(Discussion))
                    {
                        LoadDiscussionActionControl(Project, Discussion);
                    }
                    else
                    {
                        Response.Redirect("messages.aspx", true);
                    }
                }
                else if (Discussion != null && ProjectSecurity.CanRead(Discussion.Project) && Discussion.Project.ID == Project.ID)
                {
                    LoadDiscussionDetailsControl(Project, Discussion);
                }
                else
                {
                    LoadElementNotFoundControl(Project.ID);
                }
            }
            else
            {
                if (string.Compare(UrlParameters.ActionType, "add", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (ProjectSecurity.CanCreateMessage(Project))
                    {
                        LoadDiscussionActionControl(Project, null);
                    }
                    else
                    {
                        Response.Redirect("messages.aspx", true);
                    }
                }
                else
                {
                    LoadDiscussionsListControl(Project == null ? -1 : Project.ID);
                }
            }

            InitBreadCrumbs();

            Title = HeaderStringHelper.GetPageTitle(MessageResource.Messages, Master.BreadCrumbs);
        }
Ejemplo n.º 22
0
        public void Delete(Message message)
        {
            if (message == null) throw new ArgumentNullException("message");
            if (message.Project == null) throw new Exception("Project");

            ProjectSecurity.DemandEdit(message);

            messageDao.Delete(message.ID);

            var recipients = GetSubscribers(message);

            if (recipients.Any() && !engineFactory.DisableNotifications)
            {
                NotifyClient.Instance.SendAboutMessageDeleting(recipients, message);
            }

            UnSubscribe(message);
        }
Ejemplo n.º 23
0
        public MessageWrapper AddProjectMessage(int projectid, string title, string content, string participants, bool? notify)
        {
            if (string.IsNullOrEmpty(title)) throw new ArgumentException(@"title can't be empty", "title");
            if (string.IsNullOrEmpty(content)) throw new ArgumentException(@"description can't be empty", "content");

            var project = EngineFactory.GetProjectEngine().GetByID(projectid).NotFoundIfNull();

            ProjectSecurity.DemandCreateMessage(project);

            var newMessage = new Message
            {
                Content = content,
                Title = title,
                Project = project,
            };

            EngineFactory.GetMessageEngine().SaveOrUpdate(newMessage, notify ?? true, ToGuidList(participants), null);
            return new MessageWrapper(newMessage);
        }
Ejemplo n.º 24
0
        public Message SaveOrUpdate(Message message, bool notify, IEnumerable<Guid> participant, IEnumerable<int> fileIds, bool isImport)
        {
            if (message == null) throw new ArgumentNullException("message");

            var isNew = message.ID == default(int);

            message.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            message.LastModifiedOn = TenantUtil.DateTimeNow();

            if (isNew)
            {
                if (message.CreateBy == default(Guid)) message.CreateBy = SecurityContext.CurrentAccount.ID;
                if (message.CreateOn == default(DateTime)) message.CreateOn = TenantUtil.DateTimeNow();

                ProjectSecurity.DemandCreateMessage(message.Project);
                _messageDao.Save(message);
                TimeLinePublisher.Message(message, isImport ? EngineResource.ActionText_Imported : EngineResource.ActionText_Create, UserActivityConstants.ContentActionType, UserActivityConstants.NormalContent);
            }
            else
            {
                ProjectSecurity.DemandEdit(message);
                _messageDao.Save(message);
                TimeLinePublisher.Message(message, EngineResource.ActionText_Update, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity, true);
            }

            var fileEngine = _engineFactory.GetFileEngine();
            if (fileIds != null)
            {
                foreach (var fileId in fileIds)
                {
                    fileEngine.AttachFileToMessage(message.ID,fileId);
                }
            }

            NotifyParticipiant(message, isNew, participant, fileEngine.GetMessageFiles(message), notify);

            return message;
        }
Ejemplo n.º 25
0
 public bool CanRead(Message message)
 {
     return ProjectSecurity.CanRead(message);
 }
Ejemplo n.º 26
0
        public static bool CanGoToFeed(Message discussion, Guid userId)
        {
            if (discussion == null || !IsProjectsEnabled(userId))
            {
                return false;
            }
            if (discussion.CreateBy == userId)
            {
                return true;
            }
            if (!IsInTeam(discussion.Project, userId, false) && !IsFollow(discussion.Project, userId))
            {
                return false;
            }

            var isSubscriber = new MessageEngine(GetFactory(), null).GetSubscribers(discussion).Any(r => new Guid(r.ID).Equals(userId));
            return isSubscriber && GetTeamSecurityForParticipants(discussion.Project, userId, ProjectTeamSecurity.Messages);
        }
Ejemplo n.º 27
0
        public Message ChangeStatus(Message message)
        {
            message.LastModifiedBy = SecurityContext.CurrentAccount.ID;
            message.LastModifiedOn = TenantUtil.DateTimeNow();

            ProjectSecurity.DemandEdit(message);
            messageDao.Save(message);

            return message;
        }
Ejemplo n.º 28
0
        public static bool CanRead(Message message, Guid userId)
        {
            if (message == null || !CanRead(message.Project, userId)) return false;

            return CanReadMessages(message.Project, userId);
        }
Ejemplo n.º 29
0
        protected void NotifyParticipiant(Message message, bool isMessageNew, IEnumerable<Guid> participant, IEnumerable<File> uploadedFiles, bool sendNotify)
        {
            //Don't send anything if notifications are disabled
            if (engineFactory.DisableNotifications) return;

            var subscriptionRecipients = GetSubscribers(message);
            var recipients = new HashSet<Guid>(participant) { SecurityContext.CurrentAccount.ID };

            foreach (var subscriptionRecipient in subscriptionRecipients)
            {
                var subscriptionRecipientId = new Guid(subscriptionRecipient.ID);
                if (!recipients.Contains(subscriptionRecipientId))
                {
                    UnSubscribe(message, subscriptionRecipientId);
                }
            }

            foreach (var subscriber in recipients)
            {
                Subscribe(message, subscriber);
            }

            if (sendNotify && recipients.Any())
            {
                NotifyClient.Instance.SendAboutMessageAction(GetSubscribers(message), message, isMessageNew, FileEngine.GetFileListInfoHashtable(uploadedFiles));
            }
        }
Ejemplo n.º 30
0
 public static bool CanRead(Message message)
 {
     return CanRead(message, CurrentUserId);
 }