private List <string> GetIndustryRoleIds(string projectName, object userRoles) { List <IndustryRole> roles = GetRolesForProject(projectName); if (roles == null || roles.Any() == false) { Log.Warn($"Couldn't get any project industry roles for project '{projectName}'"); } List <string> result = new List <string>(); string s = Convert.ToString(userRoles); if (roles != null && false == string.IsNullOrWhiteSpace(s)) { string[] roleNames = Array.ConvertAll(s.Split(','), p => p.Trim()); foreach (string name in roleNames) { string n = name.Trim(); IndustryRole role = roles.FirstOrDefault(r => r.name != null && r.name.Equals(name)); if (role != null) { result.Add(role.id); } } } return(result != null ? result : null); }
private ProjectUser CustomGetUserForRow(DataRow row, string projectName, BimCompany company) { ProjectUser user = new ProjectUser(); user.project_name = projectName; user.email = Util.GetStringOrNull(row["user_email"]); if (company != null) { user.company_id = company.id; } else { Util.LogImportant($"No company assigned to user with email: {user.email}."); } List <IndustryRole> currRole = new List <IndustryRole>(); if (Util.GetStringOrNull(row["industry_role"]) != null) { user.industry_roles = GetIndustryRoleIds(projectName, Util.GetStringOrNull(row["industry_role"])); List <IndustryRole> roles = GetRolesForProject(projectName); List <string> industryRoles = GetIndustryRoleNames(projectName, Util.GetStringOrNull(row["industry_role"])); foreach (string userRole in industryRoles) { IndustryRole role = roles.Find(x => x.name.ToLower() == userRole.ToLower()); if (role != null) { currRole.Add(role); } else { Util.LogImportant( $"Industry role '{userRole}' was not found in project! Skipping this role for user '{user.email}'."); } } } CustomAddServicesFromIndustryRole(user, currRole); if (string.IsNullOrWhiteSpace(user.email)) { Util.LogImportant($"No email available for user - something went wrong!"); } return(user); }
private List <string> GetIndustryRoleIds(string projectName, List <string> userRoles) { List <IndustryRole> roles = GetRolesForProject(projectName); if (roles == null || roles.Any() == false) { Log.Warn($"Couldn't get any project industry roles for project '{projectName}'"); } List <string> result = new List <string>(); foreach (string userRole in userRoles) { IndustryRole role = roles.Find(x => x.name == userRole); if (role != null) { result.Add(role.id); } } return(result != null ? result : null); }
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."); } } }
internal static void AssignRolePermissionToFolder(FolderWorkflow folderProcess, NestedFolder folder, IndustryRole role, string letterPermission, string ProjectId) { Util.LogInfo($"Assigning permission '{letterPermission}' to folder '{folder.name}' for role '{role.name}'."); List <string> permissionLevel = GetPermission(letterPermission); if (permissionLevel == null) { permissionLevel = new List <string> { "VIEW", "COLLABORATE" }; Util.LogImportant($"Permission '{letterPermission}' for role '{role.name}' 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 = role.id, subjectType = "ROLE", actions = permissionLevel, inheritActions = permissionLevel }); folderProcess.CustomAssignPermissionToFolder(ProjectId, folder.id, curr_permissions); }