示例#1
0
        private List <HqUser> UserTableToList(DataTable input)
        {
            List <HqUser> users = new List <HqUser>();

            foreach (DataRow row in input.Rows)
            {
                HqUser user = new HqUser();

                user.company_id        = Util.GetStringOrNull(row["company_id"]);
                user.email             = Util.GetStringOrNull(row["email"]);
                user.nickname          = Util.GetStringOrNull(row["nickname"]);
                user.first_name        = Util.GetStringOrNull(row["first_name"]);
                user.last_name         = Util.GetStringOrNull(row["last_name"]);
                user.image_url         = Util.GetStringOrNull(row["image_url"]);
                user.address_line_1    = Util.GetStringOrNull(row["address_line_1"]);
                user.address_line_2    = Util.GetStringOrNull(row["address_line_2"]);
                user.city              = Util.GetStringOrNull(row["city"]);
                user.state_or_province = Util.GetStringOrNull(row["state_or_province"]);
                user.postal_code       = Util.GetStringOrNull(row["postal_code"]);
                user.country           = Util.GetStringOrNull(row["country"]);
                user.phone             = Util.GetStringOrNull(row["phone"]);
                user.company           = Util.GetStringOrNull(row["company"]);
                user.job_title         = Util.GetStringOrNull(row["job_title"]);
                user.industry          = Util.GetStringOrNull(row["industry"]);
                user.about_me          = Util.GetStringOrNull(row["about_me"]);

                users.Add(user);
            }
            return(users);
        }
        public void CopyProjectToTargetHubProcess(BimProject orgProj, string targetAccountId, string adminEmail, List <string> roles = null)
        {
            Log.Info("");
            Log.Info("============================================================");
            Log.Info("HUB2HUB PROJECT COPY WORKFLOW started for " + orgProj.name);
            Log.Info("============================================================");
            Log.Info("");

            Log.Info($"Creating project by copying data from original project '{orgProj.name}'");

            List <string> roleIds = new List <string>();
            HqUser        admin   = new HqUser();

            // Get service activated in the original project
            if (orgProj.service_types == null || orgProj.service_types == "")
            {
                orgProj = DataController.GetProjectWithServiceById(orgProj.id);
                if (orgProj.service_types.Contains("insight"))
                {
                    orgProj.service_types = orgProj.service_types.Replace("insight,", "");
                }
            }

            // Check if target hub supports the services
            // Make sure the target hub is allowing same service types.

            // Create project to the target hub
            try
            {
                ExtractFolderStructure(orgProj);
                bool result = CreateProjectFromTargetHub(orgProj, targetAccountId, out string newProjId);
                if (result)
                {
                    IRestResponse res     = _projectApi.GetProject(newProjId, targetAccountId);
                    BimProject    newProj = DataController.HandleGetProjectResponse(res);
                    roleIds = GetIndustryRoleIds(newProj, roles, targetAccountId);
                    admin   = GetAdminUserFromTargetHub(adminEmail, targetAccountId);

                    bool status = false;
                    do
                    {
                        status = ActivateProject(newProjId, admin, roleIds, targetAccountId);
                    } while (status == false);
                    if (status)
                    {
                        if (folderStructures.ContainsKey(orgProj.name))
                        {
                            CopyProjectFolders(orgProj, newProjId, admin.uid);
                        }
                    }
                }
                Log.Info("");
                Log.Info("HUB2HUB PROJECT COPY WORKFLOW finished for " + orgProj.name);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
示例#3
0
 private bool CheckAdminEmail(string adminEmail, out HqUser HqAdmin)
 {
     HqAdmin = DataController.AccountUsers.FirstOrDefault(u => u.email != null && u.email.Equals(adminEmail, StringComparison.InvariantCultureIgnoreCase));
     if (HqAdmin == null)
     {
         Log.Error($"Error initializing account admin user {adminEmail}");
         return(false);
     }
     return(true);
 }
        private bool ActivateProject(string newProjId, HqUser admin, List <string> roleIds = null,
                                     string accountId = null)
        {
            Log.Info("");
            Log.Info("Project activation process started.");

            List <ProjectUser> users = new List <ProjectUser>();
            ProjectUser        user  = new ProjectUser();

            user.services.document_management = new DocumentManagement();
            user.services.document_management.access_level = AccessLevel.admin;

            user.services.project_administration = new ProjectAdministration();
            user.services.project_administration.access_level = AccessLevel.admin;

            user.industry_roles = roleIds;
            user.company_id     = admin.company_id;
            user.email          = admin.email;

            users.Add(user);
            IRestResponse res = _projectApi.PostUsersImport(newProjId, admin.uid, users, accountId);

            if (res.StatusCode == System.Net.HttpStatusCode.OK)
            {
                ProjectUserResponse r = JsonConvert.DeserializeObject <ProjectUserResponse>(res.Content);
                if (r != null)
                {
                    if (r.failure_items.Count() > 0)
                    {
                        Log.Error($"- project activation failed.");
                        foreach (var item in r.failure_items)
                        {
                            foreach (var error in item.errors)
                            {
                                Log.Error("\t" + error.message);
                            }
                        }
                        return(false);
                    }
                }

                // If the function is not used for the hub 2 hub copy
                if (accountId == null)
                {
                    DataController.AllProjects.Find(x => x.id == newProjId).status = Status.active;
                }

                Log.Info($"- project activation succeed.");
                return(true);
            }

            Log.Error($"- project activation failed. Code: {res.StatusCode}\t message: {res.ErrorMessage}");
            return(false);
        }
        private void AddUsers(List <ProjectUser> _projectUsers)
        {
            if (_projectUsers == null || _projectUsers.Count < 1)
            {
                return;
            }

            HqUser hqAdmin = new HqUser();

            if (!CheckAdminEmail(_options.HqAdmin, out hqAdmin))
            {
                return;
            }

            Log.Info($"");
            Log.Info($"Start adding users to projects");
            var projectNames = _projectUsers.Select(u => u.project_name).Distinct();

            foreach (string name in projectNames)
            {
                Log.Info($"- add users to project {name}");
                var users = _projectUsers.Where(u => u.project_name.Equals(name));
                if (users == null || users.Any() == false)
                {
                    Log.Warn(
                        $"- no valid users found for project {name} - skipping this project and continue with next");
                    continue;
                }

                var project = DataController.AllProjects.FirstOrDefault(p => p.name != null && p.name.Equals(name));

                if (users.Count() < 50)
                {
                    IRestResponse response = _projectsApi.PostUsersImport(project.id, hqAdmin.uid, users.ToList());
                    ProjectUserResponseHandler(response);
                }
                else if (users.Count() >= 50)
                {
                    List <IRestResponse> responses           = new List <IRestResponse>();
                    IEnumerable <List <ProjectUser> > chunks = Util.SplitList(users.ToList());
                    foreach (List <ProjectUser> list in chunks)
                    {
                        IRestResponse response = _projectsApi.PostUsersImport(project.id, hqAdmin.uid, list);
                        ProjectUserResponseHandler(response);
                    }
                }
            }
        }
        private void PatchUser(List <ProjectUser> _projectUsers)
        {
            if (_projectUsers == null || _projectUsers.Count < 1)
            {
                return;
            }

            HqUser hqAdmin = new HqUser();

            if (!CheckAdminEmail(_options.HqAdmin, out hqAdmin))
            {
                return;
            }

            Log.Info($"");
            Log.Info($"Start updating users in projects");
            var projectNames = _projectUsers.Select(u => u.project_name).Distinct();

            foreach (string name in projectNames)
            {
                Log.Info($"- update users to project {name}");
                var users = _projectUsers.Where(u => u.project_name.Equals(name));
                if (users == null || users.Any() == false)
                {
                    Log.Warn(
                        $"- no valid users found for project {name} - skipping this project and continue with next");
                    continue;
                }

                var project = DataController.AllProjects.FirstOrDefault(p => p.name != null && p.name.Equals(name));
                foreach (ProjectUser projectUser in users)
                {
                    HqUser hqUser = new HqUser();
                    if (CheckUserId(projectUser.email, out hqUser))
                    {
                        Log.Info($"- updating user {projectUser.email}");
                        IRestResponse response =
                            _projectsApi.PatchUser(project.id, hqAdmin.uid, hqUser.id, projectUser);
                        ProjectUserPatchResponseHandler(response);
                    }
                    else
                    {
                        Log.Error($"User {projectUser.email} not in account. Add them to a project first.");
                    }
                }
            }
        }
        public void CopyFoldersProcess(BimProject orgProj, BimProject newProj, string adminEmail,
                                       List <string> roles = null)
        {
            List <string> roleIds = new List <string>();
            HqUser        admin   = new HqUser();

            Log.Info("");
            Log.Info("============================================================");
            Log.Info("FOLDER COPY WORKFLOW started for " + newProj.name);
            Log.Info("============================================================");
            Log.Info("");

            Log.Info($"Creating project by copying data from original project '{orgProj.name}'");

            try
            {
                if (false == CheckRequiredParams(newProj))
                {
                    Log.Error(
                        "One of the required parameters is missing. Required are: Name, Project Type, Value, Currency, Start date, End date");
                    Log.Error("End procesing for this project");
                }

                ExtractFolderStructure(orgProj);
                newProj.include_name_to_request_body = true;

                bool result = CreateProject(orgProj, newProj, out string newProjId);
                if (result)
                {
                    roleIds = GetIndustryRoleIds(newProj.name, roles);
                    admin   = GetAdminUser(adminEmail);
                    if (true == ActivateProject(newProjId, admin, roleIds))
                    {
                        CopyProjectFolders(orgProj, newProjId, admin.uid);
                    }
                }

                Log.Info("");
                Log.Info("FOLDER COPY WORKFLOW finished for " + newProj.name);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
示例#8
0
        internal static void AssignPermission(DataTable table, int rowIndex, List <HqUser> projectUsers, FolderWorkflow folderProcess, NestedFolder folder, BimProject project, ProjectUserWorkflow projectUserProcess)
        {
            // Add role permission
            string roleName = table.Rows[rowIndex]["role_permission"].ToString();

            if (!string.IsNullOrEmpty(roleName))
            {
                List <IndustryRole> roles = projectUserProcess.GetRolesForProject(project.name);
                IndustryRole        role  = roles.Find(x => x.name.ToLower() == roleName.ToLower());
                if (role != null)
                {
                    string letterPermission = table.Rows[rowIndex]["permission"].ToString();
                    AssignRolePermissionToFolder(folderProcess, folder, role, letterPermission, project.id);
                }
                else
                {
                    Util.LogImportant($"No role found with name: {roleName}. No permission for this role for folder '{folder.name}' will be assigned. See row number {rowIndex + 2} in the CSV-File.");
                }
            }

            // Add user permission
            string userEmail = table.Rows[rowIndex]["user_email"].ToString();

            if (!string.IsNullOrEmpty(userEmail))
            {
                HqUser existingUser = projectUsers.Find(x => x.email == userEmail);

                // Check if user exists
                if (existingUser != null)
                {
                    string letterPermission = table.Rows[rowIndex]["permission"].ToString();
                    AssignUserPermissionToFolder(folderProcess, folder, existingUser, letterPermission, project.id);
                }
                else
                {
                    Util.LogImportant($"No user found with email: {userEmail}. No permission for this user for folder '{folder.name}' will be assigned. See row number {rowIndex + 2} in the CSV-File.");
                }
            }
        }
示例#9
0
        internal static void AssignUserPermissionToFolder(FolderWorkflow folderProcess, NestedFolder folder, HqUser user, string letterPermission, string ProjectId)
        {
            Util.LogInfo($"Assigning permission '{letterPermission}' to folder '{folder.name}' for user '{user.email}'.");

            List <string> permissionLevel = GetPermission(letterPermission);

            if (permissionLevel == null)
            {
                permissionLevel = new List <string> {
                    "VIEW", "COLLABORATE"
                };
                Util.LogImportant($"Permission '{letterPermission}' for user '{user.email}' for folder '{folder.name}' was not recognized. Default permission 'V' is taken for this folder.");
            }
            List <FolderPermission> curr_permissions = new List <FolderPermission>();

            curr_permissions.Add(new FolderPermission()
            {
                subjectId      = user.id,
                subjectType    = "USER",
                actions        = permissionLevel,
                inheritActions = permissionLevel
            });

            folderProcess.CustomAssignPermissionToFolder(ProjectId, folder.id, curr_permissions);
        }