Ejemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="context"></param>
        public CalendarApi(ApiContext context)
        {
            _context = context;
            CalendarManager.Instance.RegistryCalendar(new SharedEventsCalendar());
            CalendarManager.Instance.RegistryCalendar(new BirthdayReminderCalendar());

            CalendarNotifyClient.RegisterSendMethod();
        }
Ejemplo n.º 2
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.º 3
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.º 4
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.º 5
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));
        }