private PermissionPolicyRole CreateDefaultRole() { PermissionPolicyRole defaultRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Default")); if (defaultRole == null) { defaultRole = ObjectSpace.CreateObject <PermissionPolicyRole>(); defaultRole.Name = "Default"; defaultRole.AddObjectPermission <PermissionPolicyUser>(SecurityOperations.Read, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow); defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Default/Items/MyDetails", SecurityPermissionState.Allow); defaultRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow); defaultRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "StoredPassword", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow); defaultRole.AddTypePermissionsRecursively <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Deny); defaultRole.AddTypePermissionsRecursively <ModelDifference>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow); defaultRole.AddTypePermissionsRecursively <ModelDifferenceAspect>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow); defaultRole.AddTypePermissionsRecursively <ModelDifference>(SecurityOperations.Create, SecurityPermissionState.Allow); defaultRole.AddTypePermissionsRecursively <ModelDifferenceAspect>(SecurityOperations.Create, SecurityPermissionState.Allow); } return(defaultRole); }
//Managers can access and fully edit (including create and delete capabilities) data from their own department. However, they cannot access data from other departments. private PermissionPolicyRole GetManagerRole() { PermissionPolicyRole managerRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Managers")); if (managerRole == null) { managerRole = ObjectSpace.CreateObject <PermissionPolicyRole>(); managerRole.Name = "Managers"; managerRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/MyDetails", SecurityPermissionState.Allow); managerRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/Department_ListView", SecurityPermissionState.Allow); managerRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/Employee_ListView", SecurityPermissionState.Allow); managerRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/EmployeeTask_ListView", SecurityPermissionState.Allow); managerRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/Customer_ListView", SecurityPermissionState.Allow); managerRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/Invoice_ListView", SecurityPermissionState.Allow); managerRole.AddObjectPermission <Department>(SecurityOperations.FullObjectAccess, "Employees[Oid=CurrentUserId()]", SecurityPermissionState.Allow); managerRole.SetTypePermission <Employee>(SecurityOperations.Create, SecurityPermissionState.Allow); managerRole.AddObjectPermission <Employee>(SecurityOperations.FullObjectAccess, "IsNull(Department) || Department.Employees[Oid=CurrentUserId()]", SecurityPermissionState.Allow); managerRole.SetTypePermission <EmployeeTask>(SecurityOperations.Create, SecurityPermissionState.Allow); managerRole.AddObjectPermission <EmployeeTask>(SecurityOperations.FullObjectAccess, "IsNull(AssignedTo) || IsNull(AssignedTo.Department) || AssignedTo.Department.Employees[Oid=CurrentUserId()]", SecurityPermissionState.Allow); managerRole.SetTypePermission <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Allow); managerRole.SetTypePermission <Department>(SecurityOperations.Read, SecurityPermissionState.Allow); managerRole.SetTypePermission <InvoiceItem>(SecurityOperations.Read, SecurityPermissionState.Allow); managerRole.SetTypePermission <Product>(SecurityOperations.Read, SecurityPermissionState.Allow); managerRole.AddObjectPermission <Invoice>(SecurityOperations.ReadWriteAccess, "[Klient] Is Null Or [Klient.Consultant] Is Null Or [Klient.Consultant.Department.Employees][[Oid] = CurrentUserId()]", SecurityPermissionState.Allow); managerRole.AddObjectPermission <Customer>(SecurityOperations.ReadWriteAccess, "[Consultant] Is Null Or [Consultant.Department.Employees][[Oid] = CurrentUserId()]", SecurityPermissionState.Allow); } return(managerRole); }
public override void UpdateDatabaseAfterUpdateSchema() { base.UpdateDatabaseAfterUpdateSchema(); UpdateStatus("CreateContacts", "", "Creating contacts, departments and positions in the database..."); ObjectSpace.CommitChanges(); try { CreateDepartments(); CreateContacts(); } catch (Exception e) { Tracing.Tracer.LogText("Cannot initialize contacts, departments and positions from the XML file."); Tracing.Tracer.LogError(e); } InitContactsLocation(); UpdateStatus("CreatePayments", "", "Creating payments, resumes and scheduler events in the database..."); IList <Contact> topTenContacts = ObjectSpace.GetObjects <Contact>(); ObjectSpace.SetCollectionSorting(topTenContacts, new DevExpress.Xpo.SortProperty[] { new DevExpress.Xpo.SortProperty("LastName", DevExpress.Xpo.DB.SortingDirection.Ascending) }); ObjectSpace.SetTopReturnedObjectsCount(topTenContacts, 10); string[] notes = { "works with customers until their problems are resolved and often goes an extra step to help upset customers be completely surprised by how far we will go to satisfy customers", "is very good at making team members feel included. The inclusion has improved the team's productivity dramatically", "is very good at sharing knowledge and information during a problem to increase the chance it will be resolved quickly", "actively elicits feedback from customers and works to resolve their problems", "creates an inclusive work environment where everyone feels they are a part of the team", "consistently keeps up on new trends in the industry and applies these new practices to every day work", "is clearly not a short term thinker - the ability to set short and long term business goals is a great asset to the company", "seems to want to achieve all of the goals in the last few weeks before annual performance review time, but does not consistently work towards the goals throughout the year", "does not yet delegate effectively and has a tendency to be overloaded with tasks which should be handed off to subordinates", "to be discussed with the top management..." }; for (int i = 0; i < topTenContacts.Count; i++) { Contact contact = topTenContacts[i]; if (ObjectSpace.FindObject <Paycheck>(CriteriaOperator.Parse("Contact=?", contact)) == null) { PayrollSampleDataGenerator.GenerateContactPaychecks(ObjectSpace, contact); ObjectSpace.CommitChanges(); } Resume resume = ObjectSpace.FindObject <Resume>(CriteriaOperator.Parse("Contact=?", contact)); if (resume == null) { resume = ObjectSpace.CreateObject <Resume>(); FileData file = ObjectSpace.CreateObject <FileData>(); try { Stream stream = FindContactResume(contact); if (stream != null) { file.LoadFromStream(string.Format("{0}.pdf", contact.FullName), stream); } } catch (Exception e) { Tracing.Tracer.LogText("Cannot initialize FileData for the contact {0}.", contact.FullName); Tracing.Tracer.LogError(e); } resume.File = file; resume.Contact = contact; } Contact reviewerContact = i < 5 ? FindTellitson() : FindJanete(); Note note = ObjectSpace.FindObject <Note>(CriteriaOperator.Parse("Contains(Text, ?)", contact.FullName)); if (note == null) { note = ObjectSpace.CreateObject <Note>(); note.Author = reviewerContact.FullName; note.Text = string.Format("<span style='color:#000000;font-family:Tahoma;font-size:8pt;'><b>{0}</b> \r\n{1}</span>", contact.FullName, notes[i]); note.DateTime = DateTime.Now.AddDays(i * (-1)); } } ObjectSpace.CommitChanges(); UpdateStatus("CreateTasks", "", "Creating demo tasks in the database..."); #if !EASYTEST IList <Contact> contacts = ObjectSpace.GetObjects <Contact>(); IList <DemoTask> taskList = GenerateTask(contacts); if (taskList.Count > 0) { Random rndGenerator = new Random(); foreach (Contact contact in contacts) { if (taskList.Count == 1) { contact.Tasks.Add(taskList[0]); } else if (taskList.Count == 2) { contact.Tasks.Add(taskList[0]); contact.Tasks.Add(taskList[1]); } else { int index = rndGenerator.Next(1, taskList.Count - 2); contact.Tasks.Add(taskList[index]); contact.Tasks.Add(taskList[index - 1]); contact.Tasks.Add(taskList[index + 1]); } } } #endif UpdateStatus("CreateAnalysis", "", "Creating analysis reports in the database..."); UpdateStatus("CreateSecurityData", "", "Creating users and roles in the database..."); #region Create a User for the Simple Security Strategy //// If a simple user named 'Sam' doesn't exist in the database, create this simple user //SecuritySimpleUser adminUser = ObjectSpace.FindObject<SecuritySimpleUser>(new BinaryOperator("UserName", "Sam")); //if(adminUser == null) { // adminUser = ObjectSpace.CreateObject<SecuritySimpleUser>(); // adminUser.UserName = "******"; //} //// Make the user an administrator //adminUser.IsAdministrator = true; //// Set a password if the standard authentication type is used //adminUser.SetPassword(""); #endregion ObjectSpace.CommitChanges(); #region Create Users for the Complex Security Strategy // If a user named 'Sam' doesn't exist in the database, create this user PermissionPolicyUser user1 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Sam")); if (user1 == null) { user1 = ObjectSpace.CreateObject <PermissionPolicyUser>(); user1.UserName = "******"; // Set a password if the standard authentication type is used user1.SetPassword(""); } // If a user named 'John' doesn't exist in the database, create this user PermissionPolicyUser user2 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "John")); if (user2 == null) { user2 = ObjectSpace.CreateObject <PermissionPolicyUser>(); user2.UserName = "******"; // Set a password if the standard authentication type is used user2.SetPassword(""); } // If a role with the Administrators name doesn't exist in the database, create this role PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators")); if (adminRole == null) { adminRole = ObjectSpace.CreateObject <PermissionPolicyRole>(); adminRole.Name = "Administrators"; } adminRole.IsAdministrative = true; // If a role with the Users name doesn't exist in the database, create this role PermissionPolicyRole userRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Users")); if (userRole == null) { userRole = ObjectSpace.CreateObject <PermissionPolicyRole>(); userRole.Name = "Users"; userRole.PermissionPolicy = SecurityPermissionPolicy.AllowAllByDefault; userRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/PermissionPolicyRole_ListView", SecurityPermissionState.Deny); userRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/PermissionPolicyUser_ListView", SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.FullAccess, SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyUser>(SecurityOperations.FullAccess, SecurityPermissionState.Deny); userRole.AddObjectPermission <PermissionPolicyUser>(SecurityOperations.ReadOnlyAccess, "[ID] = CurrentUserId()", SecurityPermissionState.Allow); userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", null, SecurityPermissionState.Allow); userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "StoredPassword", null, SecurityPermissionState.Allow); userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Allow); userRole.AddTypePermission <PermissionPolicyTypePermissionObject>("Write;Delete;Create", SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyMemberPermissionsObject>("Write;Delete;Create", SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyObjectPermissionsObject>("Write;Delete;Create", SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyNavigationPermissionObject>("Write;Delete;Create", SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyActionPermissionObject>("Write;Delete;Create", SecurityPermissionState.Deny); } // Add the Administrators role to the user1 if (!user1.Roles.Contains(adminRole)) { user1.Roles.Add(adminRole); } // Add the Users role to the user2 if (!user2.Roles.Contains(userRole)) { user2.Roles.Add(userRole); } #endregion ObjectSpace.CommitChanges(); }
public override void UpdateDatabaseAfterUpdateSchema() { base.UpdateDatabaseAfterUpdateSchema(); UpdateAnalysisCriteriaColumn(); // PermissionPolicyRole defaultRole = CreateDefaultRole(); UpdateStatus("CreateContacts", "", "Creating contacts, departments and positions in the database..."); Position developerPosition = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title == 'Developer'")); if (developerPosition == null) { developerPosition = ObjectSpace.CreateObject <Position>(); developerPosition.Title = "Developer"; } Position managerPosition = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title == 'Manager'")); if (managerPosition == null) { managerPosition = ObjectSpace.CreateObject <Position>(); managerPosition.Title = "Manager"; } Department devDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'Development Department'")); if (devDepartment == null) { devDepartment = ObjectSpace.CreateObject <Department>(); devDepartment.Title = "Development Department"; devDepartment.Office = "205"; devDepartment.Positions.Add(developerPosition); devDepartment.Positions.Add(managerPosition); } Department seoDepartment = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title == 'SEO'")); if (seoDepartment == null) { seoDepartment = ObjectSpace.CreateObject <Department>(); seoDepartment.Title = "SEO"; seoDepartment.Office = "703"; seoDepartment.Positions.Add(developerPosition); seoDepartment.Positions.Add(managerPosition); } ObjectSpace.CommitChanges(); try { DataTable employeesTable = GetEmployeesDataTable(); foreach (DataRow employee in employeesTable.Rows) { string email = Convert.ToString(employee["EmailAddress"]); Contact contact = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("Email=?", email)); if (contact == null) { contact = ObjectSpace.CreateObject <Contact>(); contact.Email = email; contact.FirstName = Convert.ToString(employee["FirstName"]); contact.LastName = Convert.ToString(employee["LastName"]); contact.BirthDate = Convert.ToDateTime(employee["BirthDate"]); contact.Photo = Convert.FromBase64String(Convert.ToString(employee["ImageData"])); string titleOfCourtesyText = Convert.ToString(employee["Title"]).ToLower(); if (!string.IsNullOrEmpty(titleOfCourtesyText)) { titleOfCourtesyText = titleOfCourtesyText.Replace(".", ""); TitleOfCourtesy titleOfCourtesy; if (Enum.TryParse <TitleOfCourtesy>(titleOfCourtesyText, true, out titleOfCourtesy)) { contact.TitleOfCourtesy = titleOfCourtesy; } } PhoneNumber phoneNumber = ObjectSpace.CreateObject <PhoneNumber>(); phoneNumber.Party = contact; phoneNumber.Number = Convert.ToString(employee["Phone"]); phoneNumber.PhoneType = "Work"; Address address = ObjectSpace.CreateObject <Address>(); contact.Address1 = address; address.ZipPostal = Convert.ToString(employee["PostalCode"]); address.Street = Convert.ToString(employee["AddressLine1"]); address.City = Convert.ToString(employee["City"]); address.StateProvince = Convert.ToString(employee["StateProvinceName"]); string countryName = Convert.ToString(employee["CountryRegionName"]); Country country = ObjectSpace.FindObject <Country>(CriteriaOperator.Parse("Name=?", countryName), true); if (country == null) { country = ObjectSpace.CreateObject <Country>(); country.Name = countryName; } address.Country = country; string departmentTitle = Convert.ToString(employee["GroupName"]); Department department = ObjectSpace.FindObject <Department>(CriteriaOperator.Parse("Title=?", departmentTitle), true); if (department == null) { department = ObjectSpace.CreateObject <Department>(); department.Title = departmentTitle; Random rnd = new Random(); department.Office = string.Format("{0}0{0}", rnd.Next(1, 7), rnd.Next(9)); } contact.Department = department; string positionTitle = Convert.ToString(employee["JobTitle"]); Position position = ObjectSpace.FindObject <Position>(CriteriaOperator.Parse("Title=?", positionTitle), true); if (position == null) { position = ObjectSpace.CreateObject <Position>(); position.Title = positionTitle; position.Departments.Add(department); } contact.Position = position; } } ObjectSpace.CommitChanges(); } catch (Exception e) { Tracing.Tracer.LogText("Cannot initialize contacts, departments and positions from the XML file."); Tracing.Tracer.LogError(e); } Contact contactMary = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Mary' && LastName == 'Tellitson'")); if (contactMary != null && LocationIsEmpty(contactMary)) { if (contactMary.Location == null) { contactMary.Location = ObjectSpace.CreateObject <Location>(); } contactMary.Location.Contact = contactMary; contactMary.Location.Latitude = 40.620610; contactMary.Location.Longitude = -73.935242; } Contact contactJohn = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'John' && LastName == 'Nilsen'")); if (contactJohn != null && LocationIsEmpty(contactJohn)) { if (contactJohn.Location == null) { contactJohn.Location = ObjectSpace.CreateObject <Location>(); } contactJohn.Location.Contact = contactJohn; contactJohn.Location.Latitude = 40.711510; contactJohn.Location.Longitude = -73.845252; } Contact contactJanete = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Janete' && LastName == 'Limeira'")); if (contactJanete != null && LocationIsEmpty(contactJanete)) { if (contactJanete.Location == null) { contactJanete.Location = ObjectSpace.CreateObject <Location>(); } contactJanete.Location.Contact = contactJanete; contactJanete.Location.Latitude = 40.710410; contactJanete.Location.Longitude = -73.963262; } Contact contactKarl = ObjectSpace.FindObject <Contact>(CriteriaOperator.Parse("FirstName == 'Karl' && LastName == 'Jablonski'")); if (contactKarl != null && LocationIsEmpty(contactKarl)) { if (contactKarl.Manager == null) { contactKarl.Manager = contactJanete; } if (contactKarl.Location == null) { contactKarl.Location = ObjectSpace.CreateObject <Location>(); } contactKarl.Location.Contact = contactKarl; contactKarl.Location.Latitude = 40.792613; contactKarl.Location.Longitude = -73.925142; } ObjectSpace.CommitChanges(); UpdateStatus("CreatePayments", "", "Creating payments, resumes and scheduler events in the database..."); IList <Contact> topTenContacts = ObjectSpace.GetObjects <Contact>(); ObjectSpace.SetCollectionSorting(topTenContacts, new SortProperty[] { new SortProperty("LastName", DevExpress.Xpo.DB.SortingDirection.Ascending) }); ObjectSpace.SetTopReturnedObjectsCount(topTenContacts, 10); string[] notes = { "works with customers until their problems are resolved and often goes an extra step to help upset customers be completely surprised by how far we will go to satisfy customers", "is very good at making team members feel included. The inclusion has improved the team's productivity dramatically", "is very good at sharing knowledge and information during a problem to increase the chance it will be resolved quickly", "actively elicits feedback from customers and works to resolve their problems", "creates an inclusive work environment where everyone feels they are a part of the team", "consistently keeps up on new trends in the industry and applies these new practices to every day work", "is clearly not a short term thinker - the ability to set short and long term business goals is a great asset to the company", "seems to want to achieve all of the goals in the last few weeks before annual performance review time, but does not consistently work towards the goals throughout the year", "does not yet delegate effectively and has a tendency to be overloaded with tasks which should be handed off to subordinates", "to be discussed with the top management..." }; for (int i = 0; i < topTenContacts.Count; i++) { Contact contact = topTenContacts[i]; Payment payment = ObjectSpace.FindObject <Payment>(CriteriaOperator.Parse("Contact=?", contact)); if (payment == null) { payment = ObjectSpace.CreateObject <Payment>(); payment.Contact = contact; payment.Hours = new Random().Next(10, 40); payment.Rate = new Random().Next(30, 50) + new Random().Next(5, 20); } Resume resume = ObjectSpace.FindObject <Resume>(CriteriaOperator.Parse("Contact=?", contact)); if (resume == null) { resume = ObjectSpace.CreateObject <Resume>(); FileData file = ObjectSpace.CreateObject <FileData>(); try { file.LoadFromStream(string.Format("{0}_Photo.png", contact.FullName), new MemoryStream(contact.Photo)); } catch (Exception e) { Tracing.Tracer.LogText("Cannot initialize FileData for the contact {0}.", contact.FullName); Tracing.Tracer.LogError(e); } resume.File = file; resume.Contact = contact; } Contact reviewerContact = i < 5 ? contactMary : contactJanete; Note note = ObjectSpace.FindObject <Note>(CriteriaOperator.Parse("Contains(Text, ?)", contact.FullName)); if (note == null) { note = ObjectSpace.CreateObject <Note>(); note.Author = reviewerContact.FullName; note.Text = string.Format("<span style='color:#000000;font-family:Tahoma;font-size:8pt;'><b>{0}</b> \r\n{1}</span>", contact.FullName, notes[i]); note.DateTime = DateTime.Now.AddDays(i * (-1)); } #if !EASYTEST Event appointment = ObjectSpace.FindObject <Event>(CriteriaOperator.Parse("Contains(Subject, ?)", contact.FullName)); if (appointment == null) { appointment = ObjectSpace.CreateObject <Event>(); appointment.Subject = string.Format("{0} - performance review", contact.FullName); appointment.Description = string.Format("{0} \r\n{1}", contact.FullName, notes[i]); appointment.StartOn = note.DateTime.AddDays(5).AddHours(12); appointment.EndOn = appointment.StartOn.AddHours(2); appointment.Location = "101"; appointment.AllDay = false; appointment.Status = 0; appointment.Label = i % 2 == 0 ? 2 : 5; Resource reviewerContactResource = ObjectSpace.FindObject <Resource>(CriteriaOperator.Parse("Contains(Caption, ?)", reviewerContact.FullName)); if (reviewerContactResource == null) { reviewerContactResource = ObjectSpace.CreateObject <Resource>(); reviewerContactResource.Caption = reviewerContact.FullName; reviewerContactResource.Color = reviewerContact == contactMary ? Color.AliceBlue : Color.LightCoral; } appointment.Resources.Add(reviewerContactResource); } #endif } ObjectSpace.CommitChanges(); UpdateStatus("CreateTasks", "", "Creating demo tasks in the database..."); #if EASYTEST if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Review reports'")) == null) { DemoTask task = ObjectSpace.CreateObject <DemoTask>(); task.Subject = "Review reports"; task.AssignedTo = contactJohn; task.StartDate = DateTime.Parse("May 03, 2008"); task.DueDate = DateTime.Parse("September 06, 2008"); task.Status = DevExpress.Persistent.Base.General.TaskStatus.InProgress; task.Priority = Priority.High; task.EstimatedWorkHours = 60; task.Description = "Analyse the reports and assign new tasks to employees."; } if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Fix breakfast'")) == null) { DemoTask task = ObjectSpace.CreateObject <DemoTask>(); task.Subject = "Fix breakfast"; task.AssignedTo = contactMary; task.StartDate = DateTime.Parse("May 03, 2008"); task.DueDate = DateTime.Parse("May 04, 2008"); task.Status = DevExpress.Persistent.Base.General.TaskStatus.Completed; task.Priority = Priority.Low; task.EstimatedWorkHours = 1; task.ActualWorkHours = 3; task.Description = "The Development Department - by 9 a.m.\r\nThe R&QA Department - by 10 a.m."; } if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Task1'")) == null) { DemoTask task = ObjectSpace.CreateObject <DemoTask>(); task.Subject = "Task1"; task.AssignedTo = contactJohn; task.StartDate = DateTime.Parse("June 03, 2008"); task.DueDate = DateTime.Parse("June 06, 2008"); task.Status = DevExpress.Persistent.Base.General.TaskStatus.Completed; task.Priority = Priority.High; task.EstimatedWorkHours = 10; task.ActualWorkHours = 15; task.Description = "A task designed specially to demonstrate the PivotChart module. Switch to the Reports navigation group to view the generated analysis."; } if (ObjectSpace.FindObject <DemoTask>(CriteriaOperator.Parse("Subject == 'Task2'")) == null) { DemoTask task = ObjectSpace.CreateObject <DemoTask>(); task.Subject = "Task2"; task.AssignedTo = contactJohn; task.StartDate = DateTime.Parse("July 03, 2008"); task.DueDate = DateTime.Parse("July 06, 2008"); task.Status = DevExpress.Persistent.Base.General.TaskStatus.Completed; task.Priority = Priority.Low; task.EstimatedWorkHours = 8; task.ActualWorkHours = 16; task.Description = "A task designed specially to demonstrate the PivotChart module. Switch to the Reports navigation group to view the generated analysis."; } #endif #if !EASYTEST IList <Contact> contacts = ObjectSpace.GetObjects <Contact>(); IList <DemoTask> taskList = GenerateTask(contacts); if (taskList.Count > 0) { Random rndGenerator = new Random(); foreach (Contact contact in contacts) { if (taskList.Count == 1) { contact.Tasks.Add(taskList[0]); } else if (taskList.Count == 2) { contact.Tasks.Add(taskList[0]); contact.Tasks.Add(taskList[1]); } else { int index = rndGenerator.Next(1, taskList.Count - 2); contact.Tasks.Add(taskList[index]); contact.Tasks.Add(taskList[index - 1]); contact.Tasks.Add(taskList[index + 1]); } } } #endif UpdateStatus("CreateAnalysis", "", "Creating analysis reports in the database..."); CreateDataToBeAnalysed(); UpdateStatus("CreateSecurityData", "", "Creating users and roles in the database..."); #region Create a User for the Simple Security Strategy //// If a simple user named 'Sam' doesn't exist in the database, create this simple user //SecuritySimpleUser adminUser = ObjectSpace.FindObject<SecuritySimpleUser>(new BinaryOperator("UserName", "Sam")); //if(adminUser == null) { // adminUser = ObjectSpace.CreateObject<SecuritySimpleUser>(); // adminUser.UserName = "******"; //} //// Make the user an administrator //adminUser.IsAdministrator = true; //// Set a password if the standard authentication type is used //adminUser.SetPassword(""); #endregion #region Create Users for the Complex Security Strategy // If a user named 'Sam' doesn't exist in the database, create this user PermissionPolicyUser user1 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "Sam")); if (user1 == null) { user1 = ObjectSpace.CreateObject <PermissionPolicyUser>(); user1.UserName = "******"; // Set a password if the standard authentication type is used user1.SetPassword(""); } // If a user named 'John' doesn't exist in the database, create this user PermissionPolicyUser user2 = ObjectSpace.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", "John")); if (user2 == null) { user2 = ObjectSpace.CreateObject <PermissionPolicyUser>(); user2.UserName = "******"; // Set a password if the standard authentication type is used user2.SetPassword(""); } // If a role with the Administrators name doesn't exist in the database, create this role PermissionPolicyRole adminRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Administrators")); if (adminRole == null) { adminRole = ObjectSpace.CreateObject <PermissionPolicyRole>(); adminRole.Name = "Administrators"; } adminRole.IsAdministrative = true; // If a role with the Users name doesn't exist in the database, create this role PermissionPolicyRole userRole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", "Users")); if (userRole == null) { userRole = ObjectSpace.CreateObject <PermissionPolicyRole>(); userRole.Name = "Users"; userRole.PermissionPolicy = SecurityPermissionPolicy.AllowAllByDefault; userRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/PermissionPolicyRole_ListView", SecurityPermissionState.Deny); userRole.AddNavigationPermission("Application/NavigationItems/Items/Default/Items/PermissionPolicyUser_ListView", SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.FullAccess, SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyUser>(SecurityOperations.FullAccess, SecurityPermissionState.Deny); userRole.AddObjectPermission <PermissionPolicyUser>(SecurityOperations.ReadOnlyAccess, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow); userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", null, SecurityPermissionState.Allow); userRole.AddMemberPermission <PermissionPolicyUser>(SecurityOperations.Write, "StoredPassword", null, SecurityPermissionState.Allow); userRole.AddTypePermission <PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Allow); userRole.AddTypePermission <PermissionPolicyTypePermissionObject>("Write;Delete;Create", SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyMemberPermissionsObject>("Write;Delete;Create", SecurityPermissionState.Deny); userRole.AddTypePermission <PermissionPolicyObjectPermissionsObject>("Write;Delete;Create", SecurityPermissionState.Deny); } // Add the Administrators role to the user1 user1.Roles.Add(adminRole); // Add the Users role to the user2 user2.Roles.Add(userRole); #endregion ObjectSpace.CommitChanges(); }
private void createportalroles() { PermissionPolicyRole newrole = null; string rolename = ""; string viewpricerole = GeneralValues.viewpricestring; rolename = GeneralValues.RejectRole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } rolename = GeneralValues.CloseRole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } rolename = GeneralValues.PostRole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } rolename = GeneralValues.ApprovalRole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } rolename = GeneralValues.ChangeApprovalRole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } #region PurchaseQuotation rolename = DocTypeCodes.PurchaseQuotation; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; newrole.AddNavigationPermission(@"Application/NavigationItems/Items/Purchasing/Items/PurchaseQuotation_ListView", SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotation>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotationApp>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotationAppStage>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotationAppStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotationAttachment>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotationDetail>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotationDetailUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotationDoc>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotationDocStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseQuotationUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); } createGeneralPermission(newrole); rolename = rolename + viewpricerole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } #endregion #region PurchaseReturn rolename = DocTypeCodes.PurchaseReturn; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; newrole.AddNavigationPermission(@"Application/NavigationItems/Items/Purchase Return/Items/PurchaseReturn_ListView", SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturn>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturnApp>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturnAppStage>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturnAppStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturnAttachment>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturnDetail>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturnDetailUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturnDoc>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturnDocStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseReturnUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); } createGeneralPermission(newrole); rolename = rolename + viewpricerole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } #endregion #region PurchaseDelivery rolename = DocTypeCodes.PurchaseDelivery; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; newrole.AddNavigationPermission(@"Application/NavigationItems/Items/Purchase GRN/Items/PurchaseDelivery_ListView", SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDelivery>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDeliveryApp>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDeliveryAppStage>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDeliveryAppStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDeliveryAttachment>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDeliveryDetail>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDeliveryDetailUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDeliveryDoc>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDeliveryDocStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseDeliveryUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); } createGeneralPermission(newrole); rolename = rolename + viewpricerole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } #endregion #region PurchaseOrder rolename = DocTypeCodes.PurchaseOrder; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; newrole.AddNavigationPermission(@"Application/NavigationItems/Items/Purchasing/Items/PurchaseOrder_ListView", SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrder>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrderApp>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrderAppStage>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrderAppStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrderAttachment>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrderDetail>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrderDetailUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrderDoc>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrderDocStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseOrderUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); } createGeneralPermission(newrole); rolename = rolename + viewpricerole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } #endregion #region PurchaseRequest rolename = DocTypeCodes.PurchaseRequest; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; newrole.AddNavigationPermission(@"Application/NavigationItems/Items/Purchasing/Items/PurchaseRequest_ListView", SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequest>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequestApp>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequestAppStage>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequestAppStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequestAttachment>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequestDetail>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequestDetailUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequestDoc>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequestDocStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <PurchaseRequestUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); } createGeneralPermission(newrole); rolename = rolename + viewpricerole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } #endregion #region StockTransferRequest rolename = DocTypeCodes.StockTransferRequest; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; newrole.AddNavigationPermission(@"Application/NavigationItems/Items/Inventory/Items/StockTransferRequest_ListView", SecurityPermissionState.Allow); newrole.AddNavigationPermission(@"Application/NavigationItems/Items/Inventory/Items/vwSAP_ITEM_AVAILABILITY_ListView", SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <StockTransferRequest>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <StockTransferRequestApp>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <StockTransferRequestAppStage>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <StockTransferRequestAppStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <StockTransferRequestDetail>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <StockTransferRequestDetailUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <StockTransferRequestDoc>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <StockTransferRequestDocStatus>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); newrole.AddTypePermissionsRecursively <StockTransferRequestUDF>(SecurityOperations.CRUDAccess, SecurityPermissionState.Allow); } createGeneralPermission(newrole); rolename = rolename + viewpricerole; newrole = ObjectSpace.FindObject <PermissionPolicyRole>(new BinaryOperator("Name", rolename)); if (newrole == null) { newrole = ObjectSpace.CreateObject <PermissionPolicyRole>(); newrole.Name = rolename; } #endregion }