Beispiel #1
0
        public static bool IsUserInGroup(int userId, InternalSecureGroups groupId)
        {
            UserLight cu   = CurrentUser;
            int       cuid = (cu != null ? cu.UserID : 0);

            return(IsUserInGroup(groupId, userId, cuid));
        }
Beispiel #2
0
        static UserLight Load(IDataReader reader)
        {
            UserLight u = null;

            if (reader.Read())
            {
                u = new UserLight();

                u.m_UserID         = (int)reader["UserId"];
                u.m_Login          = reader["Login"].ToString();
                u.m_FirstName      = reader["FirstName"].ToString();
                u.m_LastName       = reader["LastName"].ToString();
                u.m_Email          = reader["Email"].ToString();
                u.m_IsExternal     = (bool)reader["IsExternal"];
                u.m_IsPending      = (bool)reader["IsPending"];
                u.m_IsAlertService = (u.m_Login.ToLower() == "alert" || u.m_Login.ToLower().StartsWith("alert@"));

                reader.Close();

                using (IDataReader prefReader = DBUser.GetUserPreferences(u.m_UserID))
                {
                    if (prefReader.Read())
                    {
                        u.m_TimeZoneId = (int)prefReader["TimeZoneId"];
                        u.m_Culture    = (string)prefReader["Locale"];
                        u.m_LanguageId = (int)prefReader["LanguageId"];
                    }
                    else
                    {
                        u.m_TimeZoneId = User.GetTimeZoneByBias(-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours);
                    }
                }
            }
            return(u);
        }
Beispiel #3
0
        private void BindSingleUser(int userId)
        {
            Mediachase.IBN.Business.UserLight usr = Mediachase.IBN.Business.UserLight.Load(userId);
            UserList.Items.Add(new ListItem(usr.LastName + ", " + usr.FirstName, usr.UserID.ToString()));

            UserList.Enabled = false;                           // lock
            UserRow.Visible  = false;
        }
Beispiel #4
0
        public static UserLight GetUser(string login, string password)
        {
            // TODO: for testing stage only
            if (login.IndexOf("@") >= 0)
            {
                login = login.Substring(0, login.IndexOf("@"));
            }

            int UserId = Security.UserLogin(login, password);

            return(UserLight.Load(UserId));
        }
Beispiel #5
0
        /// <summary>
        /// Gets the default recipint list.
        /// </summary>
        /// <param name="Mode">The mode.</param>
        /// <param name="Params">The params.</param>
        /// <returns></returns>
        public static string[] GetDefaultRecipientList(string Mode, NameValueCollection Params)
        {
            List <string> retVal = new List <string>();

            Mode = Mode.ToLower();

            switch (Mode)
            {
            case EMailClient.IssueMode:
                if (Params["IssueId"] == null)
                {
                    throw new ArgumentNullException("Params[\"IssueId\"]");
                }

                int issueId = int.Parse(Params["IssueId"]);

                int incidentBoxId = Incident.GetIncidentBox(issueId);

                IncidentBoxDocument incBoxDoc = IncidentBoxDocument.Load(incidentBoxId);

                // InternalEmailRecipients
                if (incBoxDoc.EMailRouterBlock.AllowEMailRouting)
                {
                    foreach (int userId in Incident.GetInternalEmailRecipients(issueId))
                    {
                        UserLight user = UserLight.Load(userId);
                        if (!retVal.Contains(user.Email))
                        {
                            retVal.Add(user.Email);
                        }
                    }
                }

                // External Emalil
                foreach (EMailIssueExternalRecipient exRecipient in EMailIssueExternalRecipient.List(issueId))
                {
                    if (!retVal.Contains(exRecipient.EMail))
                    {
                        retVal.Add(exRecipient.EMail);
                    }
                }

                break;

            default:
                break;
            }

            return(retVal.ToArray());
        }
Beispiel #6
0
        private void BindUsers()
        {
            EnsureSelectInstance();

            string savedValue;

            if (!IsPostBack)
            {
                savedValue = Mediachase.IBN.Business.Security.CurrentUser.UserID.ToString();
            }
            else
            {
                savedValue = UserList.SelectedValue;
            }

            UserList.Items.Clear();

            if (BlockInstanceList.SelectedValue != "0")                 // 0 = All Projects
            {
                TimeTrackingBlockTypeInstance inst = MetaObjectActivator.CreateInstance <TimeTrackingBlockTypeInstance>(TimeTrackingBlockTypeInstance.GetAssignedMetaClass(), int.Parse(BlockInstanceList.SelectedValue, CultureInfo.InvariantCulture));

                if (Mediachase.Ibn.Data.Services.Security.CheckObjectRight(inst, TimeTrackingManager.Right_AddAnyTTBlock))
                {
                    Principal[] mas = Principal.List(new FilterElementCollection(FilterElement.EqualElement("Card", "User"), FilterElement.EqualElement("Activity", 3)), new SortingElementCollection(new SortingElement("Name", SortingElementType.Asc)));
                    foreach (Principal pl in mas)
                    {
                        UserList.Items.Add(new ListItem(pl.Name, pl.PrimaryKeyId.ToString()));
                    }
                }
            }

            if (UserList.Items.Count == 0)
            {
                Mediachase.IBN.Business.UserLight usr = Mediachase.IBN.Business.Security.CurrentUser;
                UserList.Items.Add(new ListItem(usr.LastName + ", " + usr.FirstName, usr.UserID.ToString()));
            }

            if (savedValue != null)
            {
                CHelper.SafeSelect(UserList, savedValue);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Returns previous user.
        /// </summary>
        internal static UserLight SetCurrentUser(string login, out UserLight currentUser)
        {
            // TODO: for testing stage only
            if (login.IndexOf("@") >= 0)
            {
                login = login.Substring(0, login.IndexOf("@"));
            }

            UserLight ret = null;

            currentUser = null;

            UserLight u = UserLight.Load(login);

            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                if (context.Items.Contains(sUserLight))
                {
                    ret         = (UserLight)context.Items[sUserLight];
                    currentUser = ret;
                }

                if (u != null)
                {
                    context.Items[sUserLight] = u;
                    context.User = new GenericPrincipal(new GenericIdentity(login), null);
                    currentUser  = u;
                }
            }
            else
            {
                ret           = m_CurrentUser;
                currentUser   = u;
                m_CurrentUser = currentUser;
            }
            return(ret);
        }
Beispiel #8
0
        /// <summary>
        /// Returns previous user.
        /// </summary>
        internal static UserLight SetCurrentUser(UserLight user)
        {
            UserLight ret = null;

            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                if (context.Items.Contains(sUserLight))
                {
                    ret = (UserLight)context.Items[sUserLight];
                    context.Items.Remove(sUserLight);
                }
                context.Items.Add(sUserLight, user);
                context.User = user == null ? null : new GenericPrincipal(new GenericIdentity(user.Login), null);
            }
            else
            {
                ret           = m_CurrentUser;
                m_CurrentUser = user;
            }

            return(ret);
        }
Beispiel #9
0
 internal void Init(UserLight user, string email, string emailFrom)
 {
     Email = email;
     IsExternal = true;
     IsNotifiedByEmail = true;
     LanguageId = user.LanguageId;
     Locale = user.Culture;
     TimeZoneId = user.TimeZoneId;
     EmailFrom = emailFrom;
 }
Beispiel #10
0
        static public void UserLoginByTicket(EMail.IncidentUserTicket ticket)
        {
            UserLight user = UserLight.Load(ticket.UserId);

            SetCurrentUser(user);
        }
Beispiel #11
0
        private void BindUsersByBlockTypeInstance(int blockTypeInstanceId)
        {
            string savedValue;

            if (!IsPostBack)
            {
                savedValue = Mediachase.IBN.Business.Security.CurrentUser.UserID.ToString();
            }
            else
            {
                savedValue = UserList.SelectedValue;
            }

            DateTime startDate = DTCWeek.SelectedDate;

            //if (startDate == DateTime.MinValue)
            //    startDate = CHelper.GetWeekStartByDate(DTCWeek.Value);

            UserList.Items.Clear();

            TimeTrackingBlockTypeInstance inst = MetaObjectActivator.CreateInstance <TimeTrackingBlockTypeInstance>(TimeTrackingBlockTypeInstance.GetAssignedMetaClass(), blockTypeInstanceId);

            if (Mediachase.Ibn.Data.Services.Security.CheckObjectRight(inst, TimeTrackingManager.Right_AddAnyTTBlock))
            {
                #region 1. Make the Dictionary of Principal
                Dictionary <int, string> allUsers = new Dictionary <int, string>();
                Principal[] principals            = Principal.List(new FilterElementCollection(FilterElement.EqualElement("Card", "User"), FilterElement.EqualElement("Activity", 3)), new SortingElementCollection(new SortingElement("Name", SortingElementType.Asc)));
                foreach (Principal p in principals)
                {
                    allUsers.Add(p.PrimaryKeyId.Value, p.Name);
                }
                #endregion

                #region 2. Make the list of the Id (to pass it as array) and the Dictionary of TimeTrackingBlock
                List <int> idList = new List <int>();
                Dictionary <int, TimeTrackingBlock> allblocks = new Dictionary <int, TimeTrackingBlock>();
                TimeTrackingBlock[] blocks = TimeTrackingBlock.List(FilterElement.EqualElement("StartDate", startDate), FilterElement.EqualElement("BlockTypeInstanceId", blockTypeInstanceId));
                foreach (TimeTrackingBlock block in blocks)
                {
                    idList.Add(block.PrimaryKeyId.Value);
                    allblocks.Add(block.PrimaryKeyId.Value, block);
                }
                #endregion

                #region 3. Get the list of the existing blocks with rights and remove the forbidden items from allUsers
                SerializableDictionary <int, Collection <string> > objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlock.GetAssignedMetaClass(), idList.ToArray());
                foreach (KeyValuePair <int, Collection <string> > item in objectRights)
                {
                    int id = item.Key;
                    Collection <string> allowedRights = item.Value;

                    TimeTrackingBlock block = allblocks[id];
                    int ownerId             = block.OwnerId;

                    if (!allowedRights.Contains(Mediachase.Ibn.Data.Services.Security.RightWrite))
                    {
                        allUsers.Remove(ownerId);
                    }
                }
                #endregion

                #region 4. Fill in the dropdown
                foreach (KeyValuePair <int, string> item in allUsers)
                {
                    UserList.Items.Add(new ListItem(item.Value, item.Key.ToString()));
                }
                #endregion
            }
            else
            {
                Mediachase.IBN.Business.UserLight usr = Mediachase.IBN.Business.Security.CurrentUser;
                UserList.Items.Add(new ListItem(usr.LastName + ", " + usr.FirstName, usr.UserID.ToString()));
            }

            if (savedValue != null)
            {
                CHelper.SafeSelect(UserList, savedValue);
            }
        }
Beispiel #12
0
        public static void DeclineResource(int todoId)
        {
            UserLight cu      = Security.CurrentUser;
            int       UserId  = cu.UserID;
            DateTime  utc_now = DateTime.UtcNow;

            int    CompletionTypeId;
            bool   IsManagerConfirmed;
            bool   IsCompleted;
            int    ReasonId;
            int    IncidentId          = -1;
            int    DocumentId          = -1;
            int    TaskId              = -1;
            bool   CompleteIncident    = false;
            bool   CompleteTask        = false;
            bool   CompleteDocument    = false;
            int    oldPercentCompleted = 0;
            string title = "";

            using (IDataReader reader = DBToDo.GetToDo(todoId, cu.TimeZoneId, cu.LanguageId))
            {
                reader.Read();
                CompletionTypeId   = (int)reader["CompletionTypeId"];
                IsManagerConfirmed = (bool)reader["MustBeConfirmed"];
                IsCompleted        = (bool)reader["IsCompleted"];
                ReasonId           = (int)reader["ReasonId"];
                if (reader["IncidentId"] != DBNull.Value)
                {
                    IncidentId = (int)reader["IncidentId"];
                }
                if (reader["DocumentId"] != DBNull.Value)
                {
                    DocumentId = (int)reader["DocumentId"];
                }
                if (reader["TaskId"] != DBNull.Value)
                {
                    TaskId = (int)reader["TaskId"];
                }
                if (reader["CompleteIncident"] != DBNull.Value)
                {
                    CompleteIncident = (bool)reader["CompleteIncident"];
                }
                if (reader["CompleteTask"] != DBNull.Value)
                {
                    CompleteTask = (bool)reader["CompleteTask"];
                }
                if (reader["CompleteDocument"] != DBNull.Value)
                {
                    CompleteDocument = (bool)reader["CompleteDocument"];
                }
                oldPercentCompleted = (int)reader["PercentCompleted"];
                title = reader["Title"].ToString();
            }

            using (DbTransaction tran = DbTransaction.Begin())
            {
                DbTodo2.ResourceReply(todoId, UserId, false);

                // O.R. [2009-02-12]
                DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, todoId, UserId);

                SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_RequestDenied, todoId, UserId);

                if (CompletionTypeId == (int)CompletionType.All)
                {
                    int OverallPercent = ToDo.RecalculateOverallPercent(todoId);

                    if (oldPercentCompleted != OverallPercent)
                    {
                        DBToDo.UpdatePercent(todoId, OverallPercent);
                        SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Percent, todoId);
                    }

                    if (!IsCompleted && !IsManagerConfirmed && OverallPercent == 100)
                    {
                        DBToDo.UpdateCompletion(todoId, true, (int)CompletionReason.CompletedAutomatically);

                        if (TaskId > 0 && CompleteTask)
                        {
                            ToDo.UpdateTaskCompletion(TaskId);
                        }

                        if (DocumentId > 0 && CompleteDocument)
                        {
                            ToDo.UpdateDocumentCompletion(DocumentId);
                        }

                        if (IncidentId > 0 && CompleteIncident)
                        {
                            ToDo.CompleteIncidentIfNeed(IncidentId);
                        }

                        ToDo.RecalculateState(todoId);
                    }
                }

                tran.Commit();
            }
        }
Beispiel #13
0
        static UserLight Load(IDataReader reader)
        {
            UserLight u = null;

            if(reader.Read())
            {
                u = new UserLight();

                u.m_UserID = (int)reader["UserId"];
                u.m_Login = reader["Login"].ToString();
                u.m_FirstName = reader["FirstName"].ToString();
                u.m_LastName = reader["LastName"].ToString();
                u.m_Email = reader["Email"].ToString();
                u.m_IsExternal = (bool)reader["IsExternal"];
                u.m_IsPending = (bool)reader["IsPending"];
                u.m_IsAlertService = (u.m_Login.ToLower() == "alert" || u.m_Login.ToLower().StartsWith("alert@"));

                reader.Close();

                using(IDataReader prefReader = DBUser.GetUserPreferences(u.m_UserID))
                {
                    if(prefReader.Read())
                    {
                        u.m_TimeZoneId = (int)prefReader["TimeZoneId"];
                        u.m_Culture = (string)prefReader["Locale"];
                        u.m_LanguageId = (int)prefReader["LanguageId"];
                    }
                    else
                    {
                        u.m_TimeZoneId = User.GetTimeZoneByBias(-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours);
                    }
                }
            }
            return u;
        }
Beispiel #14
0
        /// <summary>
        /// Returns previous user.
        /// </summary>
        internal static UserLight SetCurrentUser(string login, out UserLight currentUser)
        {
            // TODO: for testing stage only
            if (login.IndexOf("@") >= 0)
                login = login.Substring(0, login.IndexOf("@"));

            UserLight ret = null;
            currentUser = null;

            UserLight u = UserLight.Load(login);

            HttpContext context = HttpContext.Current;
            if(context != null)
            {
                if(context.Items.Contains(sUserLight))
                {
                    ret = (UserLight)context.Items[sUserLight];
                    currentUser = ret;
                }

                if(u != null)
                {
                    context.Items[sUserLight] = u;
                    context.User = new GenericPrincipal(new GenericIdentity(login), null);
                    currentUser = u;
                }
            }
            else
            {
                ret = m_CurrentUser;
                currentUser = u;
                m_CurrentUser = currentUser;
            }
            return ret;
        }
Beispiel #15
0
        /// <summary>
        /// Returns previous user.
        /// </summary>
        internal static UserLight SetCurrentUser(UserLight user)
        {
            UserLight ret = null;

            HttpContext context = HttpContext.Current;
            if(context != null)
            {
                if(context.Items.Contains(sUserLight))
                {
                    ret = (UserLight)context.Items[sUserLight];
                    context.Items.Remove(sUserLight);
                }
                context.Items.Add(sUserLight, user);
                context.User = user == null ? null : new GenericPrincipal(new GenericIdentity(user.Login), null);
            }
            else
            {
                ret = m_CurrentUser;
                m_CurrentUser = user;
            }

            return ret;
        }