IsSameUser() public méthode

public IsSameUser ( string user ) : bool
user string
Résultat bool
Exemple #1
0
        public TfsTeamProjectCollection Impersonate(User userToImpersonate)
        {
            TfsTeamProjectCollection impersonated_User = null;

            try
            {
                if (canImpersonate)
                {
                    if (userToImpersonate.IsSameUser(tfsProject.Tfs.AuthorizedIdentity.DisplayName) == false)
                    {
                        impersonated_Users.TryGetValue(userToImpersonate, out impersonated_User);
                        if (impersonated_User == null)
                        {
                            var tfsUser = defaultCreator;
                            foreach (var user in tfsUsers)
                            {
                                if (userToImpersonate.IsSameUser(user.GetAttribute("Mail", "")) ||
                                    userToImpersonate.IsSameUser(user.DisplayName))
                                {
                                    tfsUser = user.DisplayName;
                                    break;
                                }
                            }

                            var toImpersonate = getId(tfsUser);
                            if (toImpersonate != null)
                            {
                                impersonated_User = new TfsTeamProjectCollection(tfsProject.Tfs.Uri, toImpersonate.Descriptor);
                                var workItemStore = (WorkItemStore)impersonated_User.GetService(typeof(WorkItemStore));

                                if (workItemStore.Projects[tfsProject.Project].HasWorkItemWriteRights == true)
                                {
                                    impersonated_Users[userToImpersonate] = impersonated_User;
                                }
                                else if (OnFailedToImpersonate != null)
                                {
                                    OnFailedToImpersonate(
                                        string.Format("Failed to impersonate '{0}'. (This person does not have rights to create work items in TFS.)", userToImpersonate.DisplayName));
                                    return(tfsProject.Tfs);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (OnFailedToImpersonate != null)
                {
                    OnFailedToImpersonate(
                        string.Format("Failed to impersonate '{0}'. ({1})", userToImpersonate.DisplayName, ex.Message));
                    return(tfsProject.Tfs);
                }
            }
            return(impersonated_User ?? tfsProject.Tfs);
        }
Exemple #2
0
        public void AssignUser(User toAssign, WorkItem workItem)
        {
            if (toAssign.HasIdentity)
            {
                var assignedUser = (string)workItem[CoreField.AssignedTo];

                var matched = false;
                foreach (string tfsUser in workItem.Fields[CoreField.AssignedTo].AllowedValues)
                {
                    matched = toAssign.IsSameUser(tfsUser);
                    if (matched)
                    {
                        assignedUser = tfsUser;
                        break;
                    }
                }

                if (matched == false)
                {
                    if (String.IsNullOrWhiteSpace(defaultAsignee) == false)
                    {
                        assignedUser = defaultAsignee;
                    }
                    failedImpersonations.Add(toAssign);
                }
                workItem[CoreField.AssignedTo] = assignedUser;
            }
        }
Exemple #3
0
        public void AssignUser(User toAssign, WorkItem workItem)
        {
            if (toAssign.HasIdentity)
            {
                var assignedUser = (string)workItem[CoreField.AssignedTo];

                var matched = false;
                foreach (string tfsUser in workItem.Fields[CoreField.AssignedTo].AllowedValues)
                {
                    matched = toAssign.IsSameUser(tfsUser);
                    if (matched)
                    {
                        assignedUser = tfsUser;
                        break;
                    }
                }

                if (matched == false)
                {
                    // Find the TFS User using the email as matching data
                    foreach (var user in this.tfsUsers)
                    {
                        var email = user.GetAttribute("Mail", null);

                        // Check if both email match
                        if (string.Compare(email, toAssign.eMail, StringComparison.CurrentCultureIgnoreCase) == 0)
                        {
                            assignedUser = user.DisplayName;
                            matched      = true;
                            break;
                        }
                    }
                }

                if (matched == false)
                {
                    if (String.IsNullOrWhiteSpace(defaultAsignee) == false)
                    {
                        assignedUser = defaultAsignee;
                    }
                    failedImpersonations.Add(toAssign);
                }
                workItem[CoreField.AssignedTo] = assignedUser;
            }
        }
Exemple #4
0
        public TfsTeamProjectCollection Impersonate(User userToImpersonate)
        {
            TfsTeamProjectCollection impersonated_User = null;
            try
            {
                if (canImpersonate)
                {
                    if (userToImpersonate.IsSameUser(tfsProject.Tfs.AuthorizedIdentity.DisplayName) == false)
                    {
                        impersonated_Users.TryGetValue(userToImpersonate, out impersonated_User);
                        if (impersonated_User == null)
                        {
                            var tfsUser = defaultCreator;
                            foreach (var user in tfsUsers)
                            {
                                if (userToImpersonate.IsSameUser(user.GetAttribute("Mail", ""))
                                    || userToImpersonate.IsSameUser(user.DisplayName))
                                {
                                    tfsUser = user.DisplayName;
                                    break;
                                }
                            }

                            var toImpersonate = getId(tfsUser);
                            if (toImpersonate != null)
                            {
                                impersonated_User = new TfsTeamProjectCollection(tfsProject.Tfs.Uri, toImpersonate.Descriptor);
                                var workItemStore = (WorkItemStore)impersonated_User.GetService(typeof(WorkItemStore));

                                if (workItemStore.Projects[tfsProject.Project].HasWorkItemWriteRights == true)
                                {
                                    impersonated_Users[userToImpersonate] = impersonated_User;
                                }
                                else if (OnFailedToImpersonate != null)
                                {
                                    OnFailedToImpersonate(
                                        string.Format("Failed to impersonate '{0}'. (This person does not have rights to create work items in TFS.)", userToImpersonate.DisplayName));
                                    return tfsProject.Tfs;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (OnFailedToImpersonate != null)
                {
                    OnFailedToImpersonate(
                        string.Format("Failed to impersonate '{0}'. ({1})", userToImpersonate.DisplayName, ex.Message));
                    return tfsProject.Tfs;
                }
            }
            return (impersonated_User?? tfsProject.Tfs);
        }
Exemple #5
0
        public void AssignUser(User toAssign, WorkItem workItem)
        {
            if (toAssign.HasIdentity)
            {
                var assignedUser = (string) workItem[CoreField.AssignedTo];

                var matched = false;
                foreach (string tfsUser in workItem.Fields[CoreField.AssignedTo].AllowedValues)
                {
                    matched = toAssign.IsSameUser(tfsUser);
                    if (matched)
                    {
                        assignedUser = tfsUser;
                        break;
                    }
                }

                if (matched == false)
                {
                    if (String.IsNullOrWhiteSpace(defaultAsignee) == false)
                    {
                        assignedUser = defaultAsignee;
                    }
                    failedImpersonations.Add(toAssign);
                }
                workItem[CoreField.AssignedTo] = assignedUser;
            }
        }