示例#1
0
        private void GetProjects()
        {
            var getParentIdjsonUrl =
                string.Format(
                    "{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=getprojects&startIndex=0&fetchSize=1&sortBy=sequence&sortOrder=ascend&action=1&solutionId=-1&filterOption=1",
                    _protocol, Params.SBMHostPort);

            var     getParentIdresponse    = WebReq.Make(getParentIdjsonUrl, ssoBase64: _ssoBase64, contentLength: 0);
            JObject getParentIdjObject     = JObject.Parse(getParentIdresponse);
            JToken  getParentIdprojectList = getParentIdjObject["projectList"];
            var     parentId = getParentIdprojectList.First["id"].Value <string>();

            var jsonUrl =
                string.Format(
                    "{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=getprojects&startIndex=0&fetchSize=99999&sortBy=sequence&sortOrder=ascend&searchString=&action=1&solutionId=-1&parentId={2}&projectId=-1",
                    _protocol, Params.SBMHostPort, parentId);

            var response = WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, contentLength: 0);

            JObject jObject     = JObject.Parse(response);
            JToken  projectList = jObject["projectList"];

            _objectExcahnge.Add("SBM.RolesPerProject", new Dictionary <string, SBMRolesPerProject>());
            foreach (var project in projectList)
            {
                var ids = new SBMRolesPerProject {
                    id = project["id"].Value <int>(), solutionId = project["solutionId"].Value <string>()
                };
                ((Dictionary <string, SBMRolesPerProject>)_objectExcahnge["SBM.RolesPerProject"]).Add(project["name"].Value <string>(), ids);
            }
        }
示例#2
0
        private void SetRolesHelper(Dictionary <string, int> inputRoles, byte userOrGroup, int userOrGroupId, SBMRolesPerProject project, string proj)
        {
            var jsonUrl = string.Format("{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=updatesecuritycontrols&timestamp=-1", _protocol, Params.SBMHostPort);

            //get roles ids and grants to lists
            var permissionIds = new List <int>();
            var grantList     = new List <int>();
            //set all roles for group/user
            int firstRoleGranted;

            if (inputRoles.Count == 1 && inputRoles.TryGetValue("*", out firstRoleGranted))
            {
                foreach (var role in project.Roles)
                {
                    UpdatePermissionsGrantLists(role.Value, firstRoleGranted, role.Key, proj, ref permissionIds, ref grantList);
                }
            }
            else
            {
                foreach (var role in inputRoles)
                {
                    int tmpRole;
                    if (project.Roles.TryGetValue(role.Key, out tmpRole))
                    {
                        UpdatePermissionsGrantLists(tmpRole, role.Value, role.Key, proj, ref permissionIds, ref grantList);
                    }
                    else
                    {
                        Log.Warn(string.Format("Role '{0}' not found for project '{1}'", role.Key, proj));
                    }
                }
            }
            //prepare json struct
            int count = permissionIds.Count;

            if (count > 0)
            {
                var jsonStruct = new SBMSetRole[count];
                for (int i = 0; i < count; i++)
                {
                    jsonStruct[i] = new SBMSetRole(project.id, userOrGroupId, userOrGroup)
                    {
                        permissionId = permissionIds[i], granted = grantList[i]
                    }
                }
                ;

                var data = JsonConvert.SerializeObject(jsonStruct);
                WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, data: data);
            }
            else
            {
                Log.Warn(string.Format("No following roles found for '" + proj + "': "));
                foreach (var inputRole in inputRoles)
                {
                    Log.Warn(" - " + inputRole.Key);
                }
            }
        }