Пример #1
0
        /// <summary>
        /// Creates the role.
        /// </summary>
        /// <param name="roleName">Name of the role.</param>
        /// <param name="projectId">The project id.</param>
        /// <param name="description">The description.</param>
        /// <param name="autoAssign">if set to <c>true</c> [auto assign].</param>
        /// <returns></returns>
        public static int CreateRole(string roleName,int projectId,string description, bool autoAssign)
        {
            if (!Role.RoleExists(roleName,projectId))
                {
                    Role r = new Role(projectId,roleName,description,autoAssign);
                    r.Save();
                    return r.Id;
                }

                return 0;
        }
Пример #2
0
        /// <summary>
        /// Associates the default roles created at installation to a project.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        public static void CreateDefaultProjectRoles(int projectId)
        {
            if (projectId <= Globals.NewId)
                    throw (new ArgumentOutOfRangeException("projectId"));

                foreach (string role in Globals.DefaultRoles)
                {
                   Role r = new Role(projectId,role,role,false);
                   int NewRoleId = DataProviderManager.Provider.CreateNewRole(r);

                   int[] Permissions = null;
                   //add permissions to roles
                   switch (role)
                   {
                       case "Project Administrators":
                           Permissions = Globals.AdministratorPermissions;
                           break;
                       case "Read Only":
                           Permissions = Globals.ReadOnlyPermissions;
                           break;
                       case "Reporter":
                           Permissions = Globals.ReporterPermissions;
                           break;
                       case "Developer":
                           Permissions = Globals.DeveloperPermissions;
                           break;
                       case "Quality Assurance":
                           Permissions = Globals.QualityAssurancePermissions;
                           break;
                   }

                   foreach (int i in Permissions)
                   {
                       Role.AddRolePermission(NewRoleId, i);
                   }
                }
        }