Ejemplo n.º 1
0
 public static EventAlertWrapper ConvertToTypeSurrogated(EventAlertType type)
 {
     return(new EventAlertWrapper()
     {
         Type = (int)type
     });
 }
Ejemplo n.º 2
0
        private void UpdateEventNotifications(int eventId, int calendarId, DateTime eventUtcStartDate, EventAlertType baseEventAlertType, RecurrenceRule rrule,
            IEnumerable<ASC.Web.Core.Calendars.SharingOptions.PublicItem> eventPublicItems,
            IEnumerable<ASC.Web.Core.Calendars.SharingOptions.PublicItem> calendarPublicItems)
        {
            var cc = new ColumnCollection();
            var userIdCol = cc.RegistryColumn("user_id");
            var alertTypeCol = cc.RegistryColumn("alert_type");
            var isUnsubscribeCol = cc.RegistryColumn("is_unsubscribe");

            var eventUsersData = DbManager.ExecuteList(new SqlQuery("calendar_event_user").Select(cc.SelectQuery).Where(Exp.Eq("event_id", eventId)));

            var calendarData = DbManager.ExecuteList(new SqlQuery("calendar_calendars").Select("alert_type", "owner_id", "time_zone").Where(Exp.Eq("id", calendarId)));
            var calendarAlertType = calendarData.Select(r => (EventAlertType)Convert.ToInt32(r[0])).First();
            Guid calendarOwner = calendarData.Select(r => new Guid(Convert.ToString(r[1]))).First();
            TimeZoneInfo calendarTimeZone = calendarData.Select(r => TimeZoneConverter.GetTimeZone(Convert.ToString(r[2]))).First();

            List<UserAlertType> eventUsers = new List<UserAlertType>();

            #region shared event's data

            if (eventPublicItems == null)
            {
                eventPublicItems = new List<SharingOptions.PublicItem>(DbManager.ExecuteList(new SqlQuery("calendar_event_item").Select("item_id", "is_group").Where(Exp.Eq("event_id", eventId)))
                                                                       .Select(r => new ASC.Web.Core.Calendars.SharingOptions.PublicItem() { Id = new Guid(Convert.ToString(r[0])), IsGroup = Convert.ToBoolean(r[1]) }));
            }

            foreach (var item in eventPublicItems)
            {
                if (item.IsGroup)
                    eventUsers.AddRange(CoreContext.UserManager.GetUsersByGroup(item.Id).Select(u => new UserAlertType(u.ID, baseEventAlertType, calendarTimeZone)));
                else
                    eventUsers.Add(new UserAlertType(item.Id, baseEventAlertType, calendarTimeZone));
            }

            //remove calendar owner
            eventUsers.RemoveAll(u => u.UserId.Equals(calendarOwner));

            //remove unsubscribed and exec personal alert_type
            if (eventUsers.Count > 0)
            {
                foreach (var r in eventUsersData)
                {
                    if (isUnsubscribeCol.Parse<bool>(r))
                        eventUsers.RemoveAll(u => u.UserId.Equals(userIdCol.Parse<Guid>(r)));
                    else
                        eventUsers.ForEach(u =>
                        {
                            if (u.UserId.Equals(userIdCol.Parse<Guid>(r)))
                                u.AlertType = (EventAlertType)alertTypeCol.Parse<int>(r);
                        });

                }
            }

            //remove and exec sharing calendar options
            if (eventUsers.Count > 0)
            {
                var extCalendarAlertTypes = DbManager.ExecuteList(new SqlQuery("calendar_calendar_user cu")
                                                        .Select("cu.user_id", "cu.alert_type", "cu.is_accepted", "cu.time_zone")
                                                        .Where(Exp.Eq("cu.ext_calendar_id", SharedEventsCalendar.CalendarId) & Exp.In("cu.user_id", eventUsers.Select(u => u.UserId).ToArray())));

                foreach (var r in extCalendarAlertTypes)
                {
                    if (!Convert.ToBoolean(r[2]))
                    {
                        //remove unsubscribed from shared events calendar
                        eventUsers.RemoveAll(u => u.UserId.Equals(new Guid(Convert.ToString(r[0]))));
                        continue;
                    }
                    eventUsers.ForEach(u =>
                    {
                        if (u.UserId.Equals(new Guid(Convert.ToString(r[0]))))
                            u.TimeZone = ((r[3] == null || r[3] == DBNull.Value) ? calendarTimeZone : TimeZoneConverter.GetTimeZone(Convert.ToString(r[3])));

                        if (u.AlertType == EventAlertType.Default && u.UserId.Equals(new Guid(Convert.ToString(r[0]))))
                            u.AlertType = (EventAlertType)Convert.ToInt32(r[1]);
                    });
                };

                eventUsers.ForEach(u =>
                {
                    if (u.AlertType == EventAlertType.Default)
                        u.AlertType = EventAlertType.Hour;
                });

            }
            #endregion

            #region calendar's data

            if (calendarPublicItems == null)
            {
                calendarPublicItems = new List<SharingOptions.PublicItem>(DbManager.ExecuteList(new SqlQuery("calendar_calendar_item").Select("item_id", "is_group").Where(Exp.Eq("calendar_id", calendarId)))
                                                                       .Select(r => new ASC.Web.Core.Calendars.SharingOptions.PublicItem() { Id = new Guid(Convert.ToString(r[0])), IsGroup = Convert.ToBoolean(r[1]) }));
            }

            //calendar users
            List<UserAlertType> calendarUsers = new List<UserAlertType>();
            foreach (var item in eventPublicItems)
            {
                if (item.IsGroup)
                    calendarUsers.AddRange(CoreContext.UserManager.GetUsersByGroup(item.Id).Select(u => new UserAlertType(u.ID, baseEventAlertType, calendarTimeZone)));
                else
                    calendarUsers.Add(new UserAlertType(item.Id, baseEventAlertType, calendarTimeZone));
            }

            calendarUsers.Add(new UserAlertType(calendarOwner, baseEventAlertType, calendarTimeZone));

            //remove event's users
            calendarUsers.RemoveAll(u => eventUsers.Exists(eu => eu.UserId.Equals(u.UserId)));

            //calendar options            
            if (calendarUsers.Count > 0)
            {
                //set personal alert_type
                foreach (var r in eventUsersData)
                {
                    eventUsers.ForEach(u =>
                    {
                        if (u.UserId.Equals(new Guid(Convert.ToString(r[0]))))
                            u.AlertType = (EventAlertType)(Convert.ToInt32(r[1]));
                    });

                }



                var calendarAlertTypes = DbManager.ExecuteList(new SqlQuery("calendar_calendar_user")
                                                      .Select("user_id", "alert_type", "is_accepted", "time_zone")
                                                      .Where(Exp.Eq("calendar_id", calendarId) & Exp.In("user_id", calendarUsers.Select(u => u.UserId).ToArray())));


                foreach (var r in calendarAlertTypes)
                {
                    if (!Convert.ToBoolean(r[2]))
                    {
                        //remove unsubscribed
                        calendarUsers.RemoveAll(u => u.UserId.Equals(new Guid(Convert.ToString(r[0]))));
                        continue;
                    }
                    calendarUsers.ForEach(u =>
                    {
                        if (u.UserId.Equals(new Guid(Convert.ToString(r[0]))))
                            u.TimeZone = ((r[3] == null || r[3] == DBNull.Value) ? calendarTimeZone : TimeZoneConverter.GetTimeZone(Convert.ToString(r[3])));

                        if (u.AlertType == EventAlertType.Default && u.UserId.Equals(new Guid(Convert.ToString(r[0]))))
                            u.AlertType = (EventAlertType)Convert.ToInt32(r[1]);
                    });
                };

                calendarUsers.ForEach(u =>
                {
                    if (u.AlertType == EventAlertType.Default)
                        u.AlertType = calendarAlertType;
                });
            }

            #endregion


            //clear notifications
            DbManager.ExecuteNonQuery(new SqlDelete("calendar_notifications").Where("event_id", eventId));

            eventUsers.AddRange(calendarUsers);

            foreach (var u in eventUsers)
            {
                //todo: recount
                var alertDate = GetNextAlertDate(eventUtcStartDate, rrule, u.AlertType, u.TimeZone);
                if (!alertDate.Equals(DateTime.MinValue))
                {
                    DbManager.ExecuteNonQuery(new SqlInsert("calendar_notifications", true).InColumnValue("user_id", u.UserId)
                                                                                     .InColumnValue("event_id", eventId)
                                                                                     .InColumnValue("rrule", rrule.ToString())
                                                                                     .InColumnValue("alert_type", (int)u.AlertType)
                                                                                     .InColumnValue("tenant", CoreContext.TenantManager.GetCurrentTenant().TenantId)
                                                                                     .InColumnValue("notify_date", alertDate)
                                                                                     .InColumnValue("time_zone", u.TimeZone.Id));
                }
            }
        }
Ejemplo n.º 3
0
        private DateTime GetNextAlertDate(DateTime utcStartDate, RecurrenceRule rrule, EventAlertType eventAlertType, TimeZoneInfo timeZone)
        {
            if (eventAlertType == EventAlertType.Never)
                return DateTime.MinValue;

            var localFromDate = DateTime.UtcNow.Add(timeZone.BaseUtcOffset);
            var localStartDate = utcStartDate.Kind == DateTimeKind.Local ? utcStartDate : utcStartDate.Add(timeZone.BaseUtcOffset);
            var dates = rrule.GetDates(localStartDate, localFromDate, 3);
            for (var i = 0; i < dates.Count; i++)
            {
                dates[i] = dates[i].AddMinutes((-1) * (int)timeZone.BaseUtcOffset.TotalMinutes);
            }

            foreach (var d in dates)
            {
                var dd = d.AddMinutes(GetBeforeMinutes(eventAlertType));
                if (dd > DateTime.UtcNow)
                    return dd;
            }

            return DateTime.MinValue;
        }
Ejemplo n.º 4
0
 public UserAlertType(Guid userId, EventAlertType alertType, TimeZoneInfo timeZone)
 {
     this.UserId = userId;
     this.AlertType = alertType;
     this.TimeZone = timeZone;
 }
Ejemplo n.º 5
0
        private List <EventWrapper> CreateEvent(int calendarId, string name, string description, DateTime utcStartDate, DateTime utcEndDate, RecurrenceRule rrule, EventAlertType alertType, bool isAllDayLong, List <SharingParam> sharingOptions)
        {
            var sharingOptionsList = sharingOptions ?? new List <SharingParam>();

            //check permissions
            CheckPermissions(_dataProvider.GetCalendarById(calendarId),
                             CalendarAccessRights.FullAccessAction);

            name = (name ?? "").Trim();
            if (String.IsNullOrEmpty(name))
            {
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);
            }

            description = (description ?? "").Trim();

            var usrIds = new List <Guid>();
            var evt    = _dataProvider.CreateEvent(calendarId, SecurityContext.CurrentAccount.ID,
                                                   name, description, utcStartDate, utcEndDate, rrule, alertType, isAllDayLong,
                                                   sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList());

            if (evt != null)
            {
                foreach (var opt in sharingOptionsList)
                {
                    if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase))
                    {
                        CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, evt));
                    }
                }

                //notify
                CalendarNotifyClient.NotifyAboutSharingEvent(evt);

                return(new EventWrapper(evt, SecurityContext.CurrentAccount.ID,
                                        _dataProvider.GetTimeZoneForCalendar(SecurityContext.CurrentAccount.ID, calendarId))
                       .GetList(utcStartDate, utcStartDate.AddMonths(_monthCount)));
            }
            return(null);
        }
Ejemplo n.º 6
0
        public CalendarWrapper CreateCalendar(string name, string description, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, List<SharingParam> sharingOptions)
        {
            var sharingOptionsList = sharingOptions ?? new List<SharingParam>();
            var timeZoneInfo = TimeZoneConverter.GetTimeZone(timeZone);

            name = (name ?? "").Trim();
            if (String.IsNullOrEmpty(name))
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);

            description = (description ?? "").Trim();
            textColor = (textColor ?? "").Trim();
            backgroundColor = (backgroundColor ?? "").Trim();

            var cal = _dataProvider.CreateCalendar(
                        SecurityContext.CurrentAccount.ID, name, description, textColor, backgroundColor, timeZoneInfo, alertType, null,
                        sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList(),
                        new List<UserViewSettings>());

            if (cal != null)
            {
                foreach (var opt in sharingOptionsList)
                    if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase))
                        CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, cal));

                //notify
                CalendarNotifyClient.NotifyAboutSharingCalendar(cal);

                return new CalendarWrapper(cal);
            }
            return null;
        }
Ejemplo n.º 7
0
        public Calendar CreateCalendar(Guid ownerId, string name, string description, string textColor, string backgroundColor, TimeZoneInfo timeZone, EventAlertType eventAlertType, string iCalUrl, List<SharingOptions.PublicItem> publicItems, List<UserViewSettings> viewSettings)
        {
            int calendarId = 0;
            using (var tr = DbManager.BeginTransaction())
            {

                calendarId = DbManager.ExecuteScalar<int>(new SqlInsert("calendar_calendars")
                                                    .InColumnValue("id", 0)
                                                    .InColumnValue("tenant", CoreContext.TenantManager.GetCurrentTenant().TenantId)
                                                    .InColumnValue("owner_id", ownerId)
                                                    .InColumnValue("name", name)
                                                    .InColumnValue("description", description)
                                                    .InColumnValue("text_color", textColor)
                                                    .InColumnValue("background_color", backgroundColor)
                                                    .InColumnValue("alert_type", (int)eventAlertType)
                                                    .InColumnValue("time_zone", timeZone.Id)
                                                    .InColumnValue("ical_url", iCalUrl)
                                                    .Identity<int>(0, 0, true));

                if (publicItems != null)
                {
                    foreach (var item in publicItems)
                    {
                        DbManager.ExecuteNonQuery(new SqlInsert("calendar_calendar_item")
                                                    .InColumnValue("calendar_id", calendarId)
                                                    .InColumnValue("item_id", item.Id)
                                                    .InColumnValue("is_group", item.IsGroup));
                    }
                }

                if (viewSettings != null)
                {
                    foreach (var view in viewSettings)
                    {
                        DbManager.ExecuteNonQuery(new SqlInsert("calendar_calendar_user")
                                                    .InColumnValue("calendar_id", calendarId)
                                                    .InColumnValue("user_id", view.UserId)
                                                    .InColumnValue("hide_events", view.IsHideEvents)
                                                    .InColumnValue("is_accepted", view.IsAccepted)
                                                    .InColumnValue("text_color", view.TextColor)
                                                    .InColumnValue("background_color", view.BackgroundColor)
                                                    .InColumnValue("alert_type", (int)view.EventAlertType)
                                                    .InColumnValue("name", view.Name ?? "")
                                                    .InColumnValue("time_zone", view.TimeZone != null ? view.TimeZone.Id : null)
                                                    );

                    }
                }
                tr.Commit();
            }

            return GetCalendarById(calendarId);
        }
Ejemplo n.º 8
0
        public CalendarWrapper UpdateCalendarView(string calendarId, string name, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, bool hideEvents)
        {
            TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone);

            name = (name ?? "").Trim();
            if (String.IsNullOrEmpty(name))
            {
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);
            }

            var settings = new UserViewSettings()
            {
                BackgroundColor = backgroundColor,
                CalendarId      = calendarId,
                IsHideEvents    = hideEvents,
                TextColor       = textColor,
                EventAlertType  = alertType,
                IsAccepted      = true,
                UserId          = SecurityContext.CurrentAccount.ID,
                Name            = name,
                TimeZone        = timeZoneInfo
            };

            _dataProvider.UpdateCalendarUserView(settings);
            return(GetCalendarById(calendarId));
        }
Ejemplo n.º 9
0
        private List<EventWrapper> CreateEvent(int calendarId, string name, string description, DateTime utcStartDate, DateTime utcEndDate, RecurrenceRule rrule, EventAlertType alertType, bool isAllDayLong, List<SharingParam> sharingOptions)
        {
            var sharingOptionsList = sharingOptions ?? new List<SharingParam>();

            //check permissions
            CheckPermissions(_dataProvider.GetCalendarById(calendarId),
                              CalendarAccessRights.FullAccessAction);

            name = (HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(name)) ?? "").Trim();
            if (String.IsNullOrEmpty(name))
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);

            description = (description ?? "").Trim();

            var evt = _dataProvider.CreateEvent(calendarId, SecurityContext.CurrentAccount.ID,
                                                name, description, utcStartDate, utcEndDate, rrule, alertType, isAllDayLong,
                                                sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList());

            if (evt != null)
            {
                foreach (var opt in sharingOptionsList)
                    if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase))
                        CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, evt));

                //notify
                CalendarNotifyClient.NotifyAboutSharingEvent(evt);

                return new EventWrapper(evt, SecurityContext.CurrentAccount.ID,
                                        _dataProvider.GetTimeZoneForCalendar(SecurityContext.CurrentAccount.ID, calendarId))
                                        .GetList(utcStartDate, utcStartDate.AddMonths(_monthCount));
            }
            return null;
        }
Ejemplo n.º 10
0
        public List<EventWrapper> UpdateEvent(string calendarId, int eventId, string name, string description, ApiDateTime startDate, ApiDateTime endDate, string repeatType, EventAlertType alertType, bool isAllDayLong, List<SharingParam> sharingOptions)
        {
            var sharingOptionsList = sharingOptions ?? new List<SharingParam>();

            var oldEvent = _dataProvider.GetEventById(eventId);
            //check permissions
            CheckPermissions(oldEvent, CalendarAccessRights.FullAccessAction);

            name = (name ?? "").Trim();
            if (String.IsNullOrEmpty(name))
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);

            description = (description ?? "").Trim();

            TimeZoneInfo timeZone = null;
            int calId = int.Parse(oldEvent.CalendarId);
            if (!int.TryParse(calendarId, out calId))
            {
                calId = int.Parse(oldEvent.CalendarId);
                timeZone = _dataProvider.GetTimeZoneForSharedEventsCalendar(SecurityContext.CurrentAccount.ID);
            }
            else
                timeZone = _dataProvider.GetTimeZoneForCalendar(SecurityContext.CurrentAccount.ID, calId);

            var rrule = RecurrenceRule.Parse(repeatType);
            var evt = _dataProvider.UpdateEvent(eventId, calId,
                                                oldEvent.OwnerId, name, description, startDate.UtcTime, endDate.UtcTime, rrule, alertType, isAllDayLong,
                                                sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList());

            if (evt != null)
            {
                //clear old rights
                CoreContext.AuthorizationManager.RemoveAllAces(evt);

                foreach (var opt in sharingOptionsList)
                    if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase))
                        CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, evt));

                //notify
                CalendarNotifyClient.NotifyAboutSharingEvent(evt, oldEvent);

                evt.CalendarId = calendarId;
                return new EventWrapper(evt, SecurityContext.CurrentAccount.ID, timeZone).GetList(startDate.UtcTime, startDate.UtcTime.AddMonths(_monthCount));
            }
            return null;
        }
Ejemplo n.º 11
0
 public List<EventWrapper> AddEvent(int calendarId, string name, string description, ApiDateTime startDate, ApiDateTime endDate, string repeatType, EventAlertType alertType, bool isAllDayLong, List<SharingParam> sharingOptions)
 {
     return CreateEvent(calendarId, name, description, startDate.UtcTime, endDate.UtcTime, RecurrenceRule.Parse(repeatType), alertType, isAllDayLong, sharingOptions);
 }
Ejemplo n.º 12
0
        public CalendarWrapper UpdateCalendarView(string calendarId, string name, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, bool hideEvents)
        {
            TimeZoneInfo timeZoneInfo = TimeZoneConverter.GetTimeZone(timeZone);
            name = (name ?? "").Trim();
            if (String.IsNullOrEmpty(name))
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);

            var settings = new UserViewSettings()
            {
                BackgroundColor = backgroundColor,
                CalendarId = calendarId,
                IsHideEvents = hideEvents,
                TextColor = textColor,
                EventAlertType = alertType,
                IsAccepted = true,
                UserId = SecurityContext.CurrentAccount.ID,
                Name = name,
                TimeZone = timeZoneInfo
            };

            _dataProvider.UpdateCalendarUserView(settings);
            return GetCalendarById(calendarId);
        }
Ejemplo n.º 13
0
        public CalendarWrapper UpdateCalendar(string calendarId, string name, string description, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, bool hideEvents, List<SharingParam> sharingOptions)
        {
            TimeZoneInfo timeZoneInfo = TimeZoneConverter.GetTimeZone(timeZone);
            int calId;
            if (int.TryParse(calendarId, out calId))
            {
                var oldCal = _dataProvider.GetCalendarById(calId);
                if (CheckPermissions(oldCal, CalendarAccessRights.FullAccessAction, true))
                {
                    //update calendar and share options
                    var sharingOptionsList = sharingOptions ?? new List<SharingParam>();

                    name = (name ?? "").Trim();
                    if (String.IsNullOrEmpty(name))
                        throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);

                    description = (description ?? "").Trim();
                    textColor = (textColor ?? "").Trim();
                    backgroundColor = (backgroundColor ?? "").Trim();


                    //view
                    var userOptions = oldCal.ViewSettings;
                    var usrOpt = userOptions.Find(o => o.UserId.Equals(SecurityContext.CurrentAccount.ID));
                    if (usrOpt == null)
                    {
                        userOptions.Add(new UserViewSettings()
                        {
                            Name = name,
                            TextColor = textColor,
                            BackgroundColor = backgroundColor,
                            EventAlertType = alertType,
                            IsAccepted = true,
                            UserId = SecurityContext.CurrentAccount.ID,
                            TimeZone = timeZoneInfo
                        });
                    }
                    else
                    {
                        usrOpt.Name = name;
                        usrOpt.TextColor = textColor;
                        usrOpt.BackgroundColor = backgroundColor;
                        usrOpt.EventAlertType = alertType;
                        usrOpt.TimeZone = timeZoneInfo;
                    }

                    userOptions.RemoveAll(o => !o.UserId.Equals(oldCal.OwnerId) & !sharingOptionsList.Exists(opt => (!opt.IsGroup && o.UserId.Equals(opt.Id))
                                                                               || opt.IsGroup && CoreContext.UserManager.IsUserInGroup(o.UserId, opt.Id)));

                    //check owner
                    if (!oldCal.OwnerId.Equals(SecurityContext.CurrentAccount.ID))
                    {
                        name = oldCal.Name;
                        description = oldCal.Description;
                    }

                    var cal = _dataProvider.UpdateCalendar(calId, name, description,
                                        sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList(),
                                        userOptions);
                    if (cal != null)
                    {
                        //clear old rights
                        CoreContext.AuthorizationManager.RemoveAllAces(cal);

                        foreach (var opt in sharingOptionsList)
                            if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase))
                                CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, cal));

                        //notify
                        CalendarNotifyClient.NotifyAboutSharingCalendar(cal, oldCal);
                        return new CalendarWrapper(cal);
                    }
                    return null;
                }
            }

            //update view
            return UpdateCalendarView(calendarId, name, textColor, backgroundColor, timeZone, alertType, hideEvents);

        }
Ejemplo n.º 14
0
        public CalendarWrapper CreateCalendar(string name, string description, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, List <SharingParam> sharingOptions)
        {
            var sharingOptionsList = sharingOptions ?? new List <SharingParam>();
            var timeZoneInfo       = TimeZoneInfo.FindSystemTimeZoneById(timeZone);

            name = (name ?? "").Trim();
            if (String.IsNullOrEmpty(name))
            {
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);
            }

            description     = (description ?? "").Trim();
            textColor       = (textColor ?? "").Trim();
            backgroundColor = (backgroundColor ?? "").Trim();

            var cal = _dataProvider.CreateCalendar(
                SecurityContext.CurrentAccount.ID, name, description, textColor, backgroundColor, timeZoneInfo, alertType, null,
                sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList(),
                new List <UserViewSettings>());

            if (cal != null)
            {
                foreach (var opt in sharingOptionsList)
                {
                    if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase))
                    {
                        CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, cal));
                    }
                }

                //notify
                CalendarNotifyClient.NotifyAboutSharingCalendar(cal);

                return(new CalendarWrapper(cal));
            }
            return(null);
        }
Ejemplo n.º 15
0
        public Event CreateEvent(int calendarId, Guid ownerId, string name, string description,
                DateTime utcStartDate, DateTime utcEndDate, RecurrenceRule rrule, EventAlertType alertType, bool isAllDayLong, List<ASC.Web.Core.Calendars.SharingOptions.PublicItem> publicItems)
        {
            int eventId = 0;
            using (var tr = DbManager.BeginTransaction())
            {

                eventId = DbManager.ExecuteScalar<int>(new SqlInsert("calendar_events")
                                                    .InColumnValue("id", 0)
                                                    .InColumnValue("tenant", CoreContext.TenantManager.GetCurrentTenant().TenantId)
                                                    .InColumnValue("name", name)
                                                    .InColumnValue("description", description)
                                                    .InColumnValue("calendar_id", calendarId)
                                                    .InColumnValue("owner_id", ownerId)
                                                    .InColumnValue("start_date", utcStartDate.ToString("yyyy-MM-dd HH:mm:ss"))
                                                    .InColumnValue("end_date", utcEndDate.ToString("yyyy-MM-dd HH:mm:ss"))
                                                    .InColumnValue("all_day_long", isAllDayLong)
                                                    .InColumnValue("rrule", rrule.ToString())
                                                    .InColumnValue("alert_type", (int)alertType)
                                                    .Identity<int>(0, 0, true));

                foreach (var item in publicItems)
                {
                    DbManager.ExecuteNonQuery(new SqlInsert("calendar_event_item")
                                                .InColumnValue("event_id", eventId)
                                                .InColumnValue("item_id", item.Id)
                                                .InColumnValue("is_group", item.IsGroup));

                }

                //update notifications
                UpdateEventNotifications(eventId, calendarId, utcStartDate, alertType, rrule, publicItems, null);

                tr.Commit();
            }

            return GetEventById(eventId);
        }
Ejemplo n.º 16
0
        public CalendarWrapper UpdateCalendar(string calendarId, string name, string description, string textColor, string backgroundColor, string timeZone, EventAlertType alertType, bool hideEvents, List <SharingParam> sharingOptions)
        {
            TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone);
            int          calId;

            if (int.TryParse(calendarId, out calId))
            {
                var oldCal = _dataProvider.GetCalendarById(calId);
                if (CheckPermissions(oldCal, CalendarAccessRights.FullAccessAction, true))
                {
                    //update calendar and share options
                    var sharingOptionsList = sharingOptions ?? new List <SharingParam>();

                    name = (name ?? "").Trim();
                    if (String.IsNullOrEmpty(name))
                    {
                        throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);
                    }

                    description     = (description ?? "").Trim();
                    textColor       = (textColor ?? "").Trim();
                    backgroundColor = (backgroundColor ?? "").Trim();


                    //view
                    var userOptions = oldCal.ViewSettings;
                    var usrOpt      = userOptions.Find(o => o.UserId.Equals(SecurityContext.CurrentAccount.ID));
                    if (usrOpt == null)
                    {
                        userOptions.Add(new UserViewSettings()
                        {
                            Name            = name,
                            TextColor       = textColor,
                            BackgroundColor = backgroundColor,
                            EventAlertType  = alertType,
                            IsAccepted      = true,
                            UserId          = SecurityContext.CurrentAccount.ID,
                            TimeZone        = timeZoneInfo
                        });
                    }
                    else
                    {
                        usrOpt.Name            = name;
                        usrOpt.TextColor       = textColor;
                        usrOpt.BackgroundColor = backgroundColor;
                        usrOpt.EventAlertType  = alertType;
                        usrOpt.TimeZone        = timeZoneInfo;
                    }

                    userOptions.RemoveAll(o => !o.UserId.Equals(oldCal.OwnerId) & !sharingOptionsList.Exists(opt => (!opt.IsGroup && o.UserId.Equals(opt.Id)) ||
                                                                                                             opt.IsGroup && CoreContext.UserManager.IsUserInGroup(o.UserId, opt.Id)));

                    //check owner
                    if (!oldCal.OwnerId.Equals(SecurityContext.CurrentAccount.ID))
                    {
                        name        = oldCal.Name;
                        description = oldCal.Description;
                    }

                    var cal = _dataProvider.UpdateCalendar(calId, name, description,
                                                           sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList(),
                                                           userOptions);
                    if (cal != null)
                    {
                        //clear old rights
                        CoreContext.AuthorizationManager.RemoveAllAces(cal);

                        foreach (var opt in sharingOptionsList)
                        {
                            if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase))
                            {
                                CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, cal));
                            }
                        }

                        //notify
                        CalendarNotifyClient.NotifyAboutSharingCalendar(cal, oldCal);
                        return(new CalendarWrapper(cal));
                    }
                    return(null);
                }
            }

            //update view
            return(UpdateCalendarView(calendarId, name, textColor, backgroundColor, timeZone, alertType, hideEvents));
        }
Ejemplo n.º 17
0
        public Event UpdateEvent(int eventId, int calendarId, Guid ownerId, string name, string description,
                DateTime utcStartDate, DateTime utcEndDate, RecurrenceRule rrule, EventAlertType alertType, bool isAllDayLong, List<ASC.Web.Core.Calendars.SharingOptions.PublicItem> publicItems)
        {

            using (var tr = DbManager.BeginTransaction())
            {
                var query = new SqlUpdate("calendar_events")
                                .Set("name", name)
                                .Set("description", description)
                                .Set("calendar_id", calendarId)
                                .Set("owner_id", ownerId)
                                .Set("start_date", utcStartDate.ToString("yyyy-MM-dd HH:mm:ss"))
                                .Set("end_date", utcEndDate.ToString("yyyy-MM-dd HH:mm:ss"))
                                .Set("all_day_long", isAllDayLong)
                                .Set("rrule", rrule.ToString())
                                .Where(Exp.Eq("id", eventId));

                if (ownerId.Equals(SecurityContext.CurrentAccount.ID))
                    query = query.Set("alert_type", (int)alertType);
                else
                    DbManager.ExecuteNonQuery(new SqlInsert("calendar_event_user", true).InColumnValue("event_id", eventId)
                                                                                    .InColumnValue("user_id", SecurityContext.CurrentAccount.ID)
                                                                                    .InColumnValue("alert_type", alertType));


                DbManager.ExecuteNonQuery(query);

                var userIds = DbManager.ExecuteList(new SqlQuery("calendar_event_user").Select("user_id").Where("event_id", eventId)).Select(r => new Guid(Convert.ToString(r[0])));
                foreach (var usrId in userIds)
                {
                    if (!publicItems.Exists(i => (i.IsGroup && CoreContext.UserManager.IsUserInGroup(usrId, i.Id))
                                              || (!i.IsGroup && i.Id.Equals(usrId))))
                    {
                        DbManager.ExecuteNonQuery(new SqlDelete("calendar_event_user").Where(Exp.Eq("user_id", usrId) & Exp.Eq("event_id", eventId)));
                    }
                }

                DbManager.ExecuteNonQuery(new SqlDelete("calendar_event_item").Where("event_id", eventId));
                foreach (var item in publicItems)
                {
                    DbManager.ExecuteNonQuery(new SqlInsert("calendar_event_item")
                                                   .InColumnValue("event_id", eventId)
                                                   .InColumnValue("item_id", item.Id)
                                                   .InColumnValue("is_group", item.IsGroup));


                }

                //update notifications
                var baseAlertType = DbManager.ExecuteList(new SqlQuery("calendar_events").Select("alert_type").Where("id", eventId))
                                    .Select(r => (EventAlertType)Convert.ToInt32(r[0])).First();
                UpdateEventNotifications(eventId, calendarId, utcStartDate, baseAlertType, rrule, publicItems, null);


                tr.Commit();
            }

            return GetEventById(eventId);
        }
Ejemplo n.º 18
0
 public List <EventWrapper> AddEvent(int calendarId, string name, string description, ApiDateTime startDate, ApiDateTime endDate, string repeatType, EventAlertType alertType, bool isAllDayLong, List <SharingParam> sharingOptions)
 {
     return(CreateEvent(calendarId, name, description, startDate.UtcTime, endDate.UtcTime, RecurrenceRule.Parse(repeatType), alertType, isAllDayLong, sharingOptions));
 }
Ejemplo n.º 19
0
        internal static int GetBeforeMinutes(EventAlertType eventAlertType)
        {
            switch (eventAlertType)
            {
                case EventAlertType.Day:
                    return -24 * 60;
                case EventAlertType.FifteenMinutes:
                    return -15;
                case EventAlertType.FiveMinutes:
                    return -5;
                case EventAlertType.HalfHour:
                    return -30;
                case EventAlertType.Hour:
                    return -60;
                case EventAlertType.TwoHours:
                    return -120;
            }

            return 0;
        }
Ejemplo n.º 20
0
        public List <EventWrapper> UpdateEvent(string calendarId, int eventId, string name, string description, ApiDateTime startDate, ApiDateTime endDate, string repeatType, EventAlertType alertType, bool isAllDayLong, List <SharingParam> sharingOptions)
        {
            var sharingOptionsList = sharingOptions ?? new List <SharingParam>();

            var oldEvent = _dataProvider.GetEventById(eventId);

            //check permissions
            CheckPermissions(oldEvent, CalendarAccessRights.FullAccessAction);

            name = (name ?? "").Trim();
            if (String.IsNullOrEmpty(name))
            {
                throw new Exception(Resources.CalendarApiResource.ErrorEmptyName);
            }

            description = (description ?? "").Trim();

            TimeZoneInfo timeZone = null;
            int          calId    = int.Parse(oldEvent.CalendarId);

            if (!int.TryParse(calendarId, out calId))
            {
                calId    = int.Parse(oldEvent.CalendarId);
                timeZone = _dataProvider.GetTimeZoneForSharedEventsCalendar(SecurityContext.CurrentAccount.ID);
            }
            else
            {
                timeZone = _dataProvider.GetTimeZoneForCalendar(SecurityContext.CurrentAccount.ID, calId);
            }

            var rrule  = RecurrenceRule.Parse(repeatType);
            var usrIds = new List <Guid>();
            var evt    = _dataProvider.UpdateEvent(eventId, calId,
                                                   oldEvent.OwnerId, name, description, startDate.UtcTime, endDate.UtcTime, rrule, alertType, isAllDayLong,
                                                   sharingOptionsList.Select(o => o as SharingOptions.PublicItem).ToList());

            if (evt != null)
            {
                //clear old rights
                CoreContext.AuthorizationManager.RemoveAllAces(evt);

                foreach (var opt in sharingOptionsList)
                {
                    if (String.Equals(opt.actionId, AccessOption.FullAccessOption.Id, StringComparison.InvariantCultureIgnoreCase))
                    {
                        CoreContext.AuthorizationManager.AddAce(new AzRecord(opt.Id, CalendarAccessRights.FullAccessAction.ID, ASC.Common.Security.Authorizing.AceType.Allow, evt));
                    }
                }

                //notify
                CalendarNotifyClient.NotifyAboutSharingEvent(evt, oldEvent);

                evt.CalendarId = calendarId;
                return(new EventWrapper(evt, SecurityContext.CurrentAccount.ID, timeZone).GetList(startDate.UtcTime, startDate.UtcTime.AddMonths(_monthCount)));
            }
            return(null);
        }
Ejemplo n.º 21
0
 public static EventAlertWrapper ConvertToTypeSurrogated(EventAlertType type)
 {
     return new EventAlertWrapper() { Type = (int)type };
 }