Skip to content

Commit

Permalink
Mailform association exception
Browse files Browse the repository at this point in the history
  • Loading branch information
apobekiaris committed Jan 19, 2013
1 parent 46a1281 commit aec83b1
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Demos/SecurityDemo/SecurityDemo.Module/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void UpdateDatabaseAfterUpdateSchema() {
}

XpandRole CreateSecurityDemoRole() {
var securityDemoRole = ObjectSpace.GetRole("Demo");
var securityDemoRole = (XpandRole)ObjectSpace.GetRole("Demo");
if (ObjectSpace.IsNewObject(securityDemoRole)) {
securityDemoRole.CreateTypePermission<FullAccessObject>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override void UpdateDatabaseAfterUpdateSchema() {
ObjectSpace.CommitChanges();
SequenceBaseObject.Updating = false;
}

void CreateDashboard() {
const string dashboardName = "Receipts";

Expand All @@ -68,7 +69,7 @@ void CreateDashboard() {
var reader = new StreamReader(manifestResourceStream);
dashboard.Xml = reader.ReadLine();
}
var dashboardRole = ObjectSpace.GetRole<XpandRole>("Dashboard View Role");
var dashboardRole = ObjectSpace.GetRole("Dashboard View Role");
var dashboardCollection = (XPBaseCollection)dashboardRole.GetMemberValue(typeof(DashboardDefinition).Name + "s");
dashboardCollection.BaseAdd(dashboard);
}
Expand Down Expand Up @@ -111,10 +112,10 @@ XpandRole CreateUserData() {
}

XpandRole InitVideoRentalSecurityData() {
var defaultRole = ObjectSpace.GetDefaultRole<XpandRole>();
var defaultRole = ObjectSpace.GetDefaultRole();
if (ObjectSpace.IsNewObject(defaultRole)) {
var employersRole = ObjectSpace.GetRole<XpandRole>("Employers");
var dashboardRole = ObjectSpace.GetRole<XpandRole>("Dashboard View Role");
var employersRole = ObjectSpace.GetRole("Employers");
var dashboardRole = ObjectSpace.GetRole("Dashboard View Role");

var user = employersRole.GetUser("User");
var dashboardUser = dashboardRole.GetUser("DashboardUser");
Expand All @@ -124,13 +125,13 @@ XpandRole InitVideoRentalSecurityData() {
dashboardUser.Roles.Add(dashboardRole);

employersRole.CreateFullPermissionAttributes();
return employersRole;
return (XpandRole)employersRole;
}
return null;
}

void InitAdminSecurityData() {
var securitySystemRole = ObjectSpace.GetAdminRole<XpandRole>("Administrator");
var securitySystemRole = ObjectSpace.GetAdminRole("Administrator");
securitySystemRole.GetUser("Admin");
}
}
Expand Down
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions Xpand/Xpand.ExpressApp.Modules/Dashboard/DashboardModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public override void Setup(XafApplication application) {
if (application != null && !DesignMode) {
application.SettingUp += ApplicationOnSetupComplete;
}
if (RuntimeMode) {
AddToAdditionalExportedTypes(typeof(DashboardDefinition).Namespace, GetType().Assembly);
}
}
void ApplicationOnSetupComplete(object sender, EventArgs eventArgs) {
if (((XafApplication)sender).Security is ISecurityComplex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public override void Setup(XafApplication application) {
if (application != null && !DesignMode) {
application.SetupComplete += ApplicationOnSetupComplete;
}
if (RuntimeMode) {
AddToAdditionalExportedTypes(typeof(SendEmailJobDataMap).Namespace, GetType().Assembly);
}
}

void ApplicationOnSetupComplete(object sender, EventArgs eventArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public override void Setup(ApplicationModulesManager moduleManager) {
base.Setup(moduleManager);
if (Application == null)
return;

if (RuntimeMode) {
AddToAdditionalExportedTypes("Xpand.Persistent.BaseImpl.JobScheduler");
Application.LoggedOn += ApplicationOnLoggedOn;
}

}


void ApplicationOnLoggedOn(object sender, LogonEventArgs logonEventArgs) {
ISchedulerFactory stdSchedulerFactory = new XpandSchedulerFactory(Application);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public override void CustomizeTypesInfo(ITypesInfo typesInfo) {
}
}


public override void Setup(XafApplication application) {
base.Setup(application);
if (application != null && !DesignMode) {
application.SettingUp += ApplicationOnSetupComplete;
}
if (RuntimeMode) {
AddToAdditionalExportedTypes(typeof(ModelDifferenceObject).Namespace, GetType().Assembly);
}
}

void ApplicationOnSetupComplete(object sender, EventArgs eventArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class Extensions {
typeof (PersistentApplication)
};

public static SecuritySystemRole GetDefaultModelRole(this IObjectSpace objectSpace, string roleName) {
public static SecuritySystemRoleBase GetDefaultModelRole(this IObjectSpace objectSpace, string roleName) {
var modelRole = objectSpace.GetRole(roleName);
if (objectSpace.IsNewObject(modelRole)) {
modelRole.CreateTypePermission<PersistentApplication>(o => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using DevExpress.ExpressApp.Security.Strategy.PermissionMatrix;
using DevExpress.ExpressApp.Xpo;
using DevExpress.Persistent.Base.Security;
using DevExpress.Xpo;
using Xpand.Utils.Helpers;

namespace Xpand.ExpressApp.Security.Core {
Expand All @@ -37,75 +38,62 @@ public string Name {
}
public static class SecuritySystemExtensions {

public static T GetDefaultRole<T>(this IObjectSpace objectSpace, string roleName) where T : SecuritySystemRole {
var defaultRole = objectSpace.GetRole<T>(roleName);
public static SecuritySystemRoleBase GetDefaultRole(this IObjectSpace objectSpace, string roleName) {
var defaultRole = objectSpace.GetRole(roleName);
if (objectSpace.IsNewObject(defaultRole)) {
defaultRole.AddObjectAccessPermission(SecuritySystem.UserType, "[Oid] = CurrentUserId()", SecurityOperations.ReadOnlyAccess);
defaultRole.AddMemberAccessPermission<SecuritySystemUser>("ChangePasswordOnFirstLogon,StoredPassword", SecurityOperations.Write);
defaultRole.AddMemberAccessPermission(XpandModuleBase.UserType, "ChangePasswordOnFirstLogon,StoredPassword", SecurityOperations.Write);
defaultRole.SetTypePermissions(((IRoleTypeProvider)SecuritySystem.Instance).RoleType, SecurityOperations.Read, SecuritySystemModifier.Allow);
}
return defaultRole;
}

public static SecuritySystemRole GetDefaultRole(this IObjectSpace objectSpace, string roleName) {
return GetDefaultRole<SecuritySystemRole>(objectSpace, roleName);
public static SecuritySystemRoleBase GetDefaultRole(this IObjectSpace objectSpace) {
return objectSpace.GetDefaultRole("Default");
}

public static T GetDefaultRole<T>(this IObjectSpace objectSpace) where T : SecuritySystemRole {
return objectSpace.GetDefaultRole<T>("Default");
}

public static SecuritySystemRole GetDefaultRole(this IObjectSpace objectSpace) {
return GetDefaultRole<SecuritySystemRole>(objectSpace);
}

public static SecuritySystemUser GetUser(this SecuritySystemRole systemRole, string userName, string passWord = "") {
public static ISecurityUserWithRoles GetUser(this SecuritySystemRoleBase systemRole, string userName, string passWord = "") {
var objectSpace = XPObjectSpace.FindObjectSpaceByObject(systemRole);
return GetUser(objectSpace, userName, passWord, systemRole);
}

public static SecuritySystemUser GetUser(this IObjectSpace objectSpace, string userName, string passWord = "", params SecuritySystemRole[] roles) {
var user2 = (SecuritySystemUser)objectSpace.FindObject(SecuritySystem.UserType, new BinaryOperator("UserName", userName)) ??
public static ISecurityUserWithRoles GetUser(this IObjectSpace objectSpace, string userName, string passWord = "", params SecuritySystemRoleBase[] roles) {
return (ISecurityUserWithRoles)objectSpace.FindObject(SecuritySystem.UserType, new BinaryOperator("UserName", userName)) ??
CreateUser(objectSpace, userName, passWord, roles);
return user2;
}

public static SecuritySystemUser CreateUser(IObjectSpace objectSpace, string userName, string passWord, IEnumerable<SecuritySystemRole> roles) {
var user2 = (SecuritySystemUser)objectSpace.CreateObject(SecuritySystem.UserType);
user2.UserName = userName;
user2.SetPassword(passWord + "");
user2.Roles.AddRange(roles);
public static ISecurityUserWithRoles CreateUser(IObjectSpace objectSpace, string userName, string passWord, IEnumerable<SecuritySystemRoleBase> roles) {
var user2 = (ISecurityUserWithRoles)objectSpace.CreateObject(SecuritySystem.UserType);
var typeInfo = objectSpace.TypesInfo.FindTypeInfo(user2.GetType());
typeInfo.FindMember("UserName").SetValue(user2, userName);
typeInfo.Type.GetMethod("SetPassword").Invoke(user2, new object[] { passWord });
var roleCollection = (XPBaseCollection)typeInfo.FindMember("Roles").GetValue(user2);
foreach (var role in roles) {
roleCollection.BaseAdd(role);
}
return user2;
}

public static T GetAdminRole<T>(this IObjectSpace objectSpace, string roleName) where T : SecuritySystemRole {
var administratorRole = objectSpace.FindObject<T>(new BinaryOperator("Name", roleName));
public static SecuritySystemRoleBase GetAdminRole(this IObjectSpace objectSpace, string roleName) {
var administratorRole = (SecuritySystemRoleBase)objectSpace.FindObject(XpandModuleBase.RoleType, new BinaryOperator("Name", roleName));
if (administratorRole == null) {
administratorRole = objectSpace.CreateObject<T>();
administratorRole = (SecuritySystemRoleBase)objectSpace.CreateObject(XpandModuleBase.RoleType);
administratorRole.Name = roleName;
administratorRole.IsAdministrative = true;
}
return administratorRole;
}

public static SecuritySystemRole GetAdminRole(this IObjectSpace objectSpace, string roleName) {
return GetAdminRole<XpandRole>(objectSpace, roleName);
}

public static T GetRole<T>(this IObjectSpace objectSpace, string roleName) where T : SecuritySystemRole {
var securityDemoRole = objectSpace.FindObject<T>(new BinaryOperator("Name", roleName));
public static SecuritySystemRoleBase GetRole(this IObjectSpace objectSpace, string roleName) {
var securityDemoRole = (SecuritySystemRoleBase)objectSpace.FindObject(XpandModuleBase.RoleType, new BinaryOperator("Name", roleName));
if (securityDemoRole == null) {
securityDemoRole = objectSpace.CreateObject<T>();
securityDemoRole = (SecuritySystemRoleBase)objectSpace.CreateObject(XpandModuleBase.RoleType);
securityDemoRole.Name = roleName;
}
return securityDemoRole;
}

public static XpandRole GetRole(this IObjectSpace objectSpace, string roleName) {
return GetRole<XpandRole>(objectSpace, roleName);
}

public static SecuritySystemTypePermissionObject CreateTypePermission<TObject>(this SecuritySystemRole systemRole, Action<SecuritySystemTypePermissionObject> action, bool defaultAllowValues = true) {
public static SecuritySystemTypePermissionObject CreateTypePermission<TObject>(this SecuritySystemRoleBase systemRole, Action<SecuritySystemTypePermissionObject> action, bool defaultAllowValues = true) {
var targetType = typeof(TObject);
var permission = systemRole.CreateTypePermission<TObject>();
permission.TargetType = targetType;
Expand All @@ -118,19 +106,19 @@ public static SecuritySystemTypePermissionObject CreateTypePermission<TObject>(t
return permission;
}

public static SecuritySystemTypePermissionObject CreateTypePermission<TObject>(this SecuritySystemRole systemRole) {
public static SecuritySystemTypePermissionObject CreateTypePermission<TObject>(this SecuritySystemRoleBase systemRole) {
return CreateTypePermission(systemRole, typeof(TObject));
}

public static SecuritySystemTypePermissionObject CreateTypePermission(this SecuritySystemRole systemRole, Type targetType) {
public static SecuritySystemTypePermissionObject CreateTypePermission(this SecuritySystemRoleBase systemRole, Type targetType) {
var objectSpace = XPObjectSpace.FindObjectSpaceByObject(systemRole);
var permissionObject = objectSpace.CreateObject<SecuritySystemTypePermissionObject>();
permissionObject.TargetType = targetType;
systemRole.TypePermissions.Add(permissionObject);
return permissionObject;
}

public static SecuritySystemTypePermissionObject CreateTypePermission(this SecuritySystemRole systemRole, Type targetType, Action<SecuritySystemTypePermissionObject> action,
public static SecuritySystemTypePermissionObject CreateTypePermission(this SecuritySystemRoleBase systemRole, Type targetType, Action<SecuritySystemTypePermissionObject> action,
bool defaultAllowValues = true) {
var permission = systemRole.CreateTypePermission(targetType);
permission.TargetType = targetType;
Expand Down Expand Up @@ -178,7 +166,7 @@ public static SecuritySystemObjectPermissionsObject CreateObjectPermission(this
return permission;
}

public static void CreatePermissionBehaviour(this SecuritySystemRole systemRole, Enum behaviourEnum, Action<SecuritySystemRole, ITypeInfo> action) {
public static void CreatePermissionBehaviour(this SecuritySystemRoleBase systemRole, Enum behaviourEnum, Action<SecuritySystemRoleBase, ITypeInfo> action) {
var typeInfos = XafTypesInfo.Instance.PersistentTypes.Where(info => {
var permissionBehaviorAttribute = info.FindAttribute<PermissionBehaviorAttribute>();
return permissionBehaviorAttribute != null && permissionBehaviorAttribute.Name.Equals(Enum.GetName(behaviourEnum.GetType(), behaviourEnum));
Expand All @@ -188,7 +176,7 @@ public static void CreatePermissionBehaviour(this SecuritySystemRole systemRole,
}
}

public static void CreateFullPermissionAttributes(this SecuritySystemRole systemRole, Action<SecuritySystemTypePermissionObject> action = null, bool defaultAllowValues = true) {
public static void CreateFullPermissionAttributes(this SecuritySystemRoleBase systemRole, Action<SecuritySystemTypePermissionObject> action = null, bool defaultAllowValues = true) {
var persistentTypes = XafTypesInfo.Instance.PersistentTypes.Where(info => info.FindAttribute<FullPermissionAttribute>() != null);
foreach (var typeInfo in persistentTypes) {
systemRole.CreateTypePermission(typeInfo.Type, action, defaultAllowValues);
Expand Down
11 changes: 8 additions & 3 deletions Xpand/Xpand.ExpressApp/Xpand.ExpressApp/XpandModuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ protected override IEnumerable<Type> GetDeclaredExportedTypes() {
}
return declaredExportedTypes;
}
return base.GetDeclaredExportedTypes();
var exportedTypes = base.GetDeclaredExportedTypes();
return !exportedTypes.Any() ? AdditionalExportedTypes : exportedTypes;
}

void AssignSecurityEntities() {
Expand Down Expand Up @@ -154,13 +155,17 @@ protected void AddToAdditionalExportedTypes(string[] types) {

}

protected void AddToAdditionalExportedTypes(string nameSpaceName) {
protected void AddToAdditionalExportedTypes(string nameSpaceName, Assembly assembly) {
if (RuntimeMode) {
var types = BaseImplAssembly.GetTypes().Where(type1 => (type1.Namespace + "").StartsWith(nameSpaceName));
var types = assembly.GetTypes().Where(type1 => string.Join("", new[] { type1.Namespace }).StartsWith(nameSpaceName));
AdditionalExportedTypes.AddRange(types);
}
}

protected void AddToAdditionalExportedTypes(string nameSpaceName) {
AddToAdditionalExportedTypes(nameSpaceName, BaseImplAssembly);
}

protected void CreateDesignTimeCollection(ITypesInfo typesInfo, Type classType, string propertyName) {
XPClassInfo info = XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary.GetClassInfo(classType);
if (info.FindMember(propertyName) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ public Assembly Build(IEnumerable<InterfaceBuilderData> builderDatas, string ass
if (LoadFromCurrentDomain)
return LoadFromDomain(assemblyFilePath);
_fileExistInPath = File.Exists(assemblyFilePath);
if (LoadFromPath && _fileExistInPath)
if (LoadFromPath && _fileExistInPath) {
return Assembly.LoadFile(assemblyFilePath);
}
if (!RuntimeMode && _assemblies.ContainsKey(_assemblyName + "")) {
return _assemblies[_assemblyName];
}
Expand Down

0 comments on commit aec83b1

Please sign in to comment.