Changeset 939


Ignore:
Timestamp:
12/10/08 14:10:52 (12 years ago)
Author:
svonolfe
Message:

Fixed referential integrity between user and user group (#372)

Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/PermissionOwner.cs

    r845 r939  
    3434    [DataMember]
    3535    public string Name { get; set; }
    36    
     36
     37    public override bool Equals(object obj) {
     38      if (obj is PermissionOwner)
     39        return this.PermissionOwnerId.Equals(
     40          (obj as PermissionOwner).PermissionOwnerId);
     41      else
     42        return base.Equals(obj);
     43    }
     44
     45    public override int GetHashCode() {
     46      return this.PermissionOwnerId.GetHashCode();
     47    }
    3748  }
    3849}
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/PermissionOwnerAdapter.cs

    r925 r939  
    152152          if(row != null) {
    153153            data.RemovePermissionOwnerRow(row);
    154 
     154         
    155155            return true;
    156156          }
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/UserAdapter.cs

    r925 r939  
    3939    private IPermissionOwnerAdapter permOwnerAdapter =
    4040       ServiceLocator.GetPermissionOwnerAdapter();
     41
     42    private IUserGroupAdapter userGroupAdapter = null;
    4143
    4244    public UserAdapter() {
     
    150152
    151153        if (row != null) {
     154          if (userGroupAdapter == null)
     155            userGroupAdapter =
     156              ServiceLocator.GetUserGroupAdapter();
     157
     158          ICollection<UserGroup> userGroups =
     159            userGroupAdapter.MemberOf(user);
     160
     161          foreach (UserGroup group in userGroups) {
     162            group.Members.Remove(user);
     163            userGroupAdapter.UpdateUserGroup(group);
     164          }
     165
    152166          data.RemoveHiveUserRow(row);
    153167
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/UserGroupAdapter.cs

    r936 r939  
    2828using HeuristicLab.Hive.Contracts.BusinessObjects;
    2929using System.Runtime.CompilerServices;
     30using System.Data;
    3031
    3132namespace HeuristicLab.Hive.Server.ADODataAccess {
     
    169170        foreach (dsHiveServer.PermissionOwner_UserGroupRow permOwnerUserGroupRow in
    170171          userGroupRows) {
    171           PermissionOwner permOwner = userGroup.Members.Single<PermissionOwner>(
    172             p => p.PermissionOwnerId == permOwnerUserGroupRow.PermissionOwnerId);
     172          PermissionOwner permOwner = null;
     173
     174          IEnumerable<PermissionOwner> permOwners =
     175            from p in
     176              userGroup.Members
     177            where p.PermissionOwnerId == permOwnerUserGroupRow.PermissionOwnerId
     178            select p;
     179
     180          if (permOwners.Count<PermissionOwner>() == 1)
     181            permOwner = permOwners.First<PermissionOwner>();
    173182
    174183          if (permOwner == null) {
     
    234243
    235244      return allUserGroups;
     245    }
     246
     247    public ICollection<UserGroup> MemberOf(PermissionOwner permOwner) {
     248      ICollection<UserGroup> userGroups =
     249        new List<UserGroup>();
     250     
     251      if (permOwner != null) {
     252        IEnumerable<dsHiveServer.PermissionOwner_UserGroupRow> userGroupRows =
     253         from userGroup in
     254           permOwnerUserGroupData.AsEnumerable<dsHiveServer.PermissionOwner_UserGroupRow>()
     255         where userGroup.PermissionOwnerId == permOwner.PermissionOwnerId
     256         select userGroup;
     257
     258        foreach (dsHiveServer.PermissionOwner_UserGroupRow userGroupRow in
     259          userGroupRows) {
     260          UserGroup userGroup =
     261            GetUserGroupById(userGroupRow.UserGroupId);
     262          userGroups.Add(userGroup);
     263        }
     264      }
     265
     266      return userGroups;
    236267    }
    237268
     
    249280            permOwnerUserGroupData) {
    250281            if (permOwnerUserGroupRow.UserGroupId == group.PermissionOwnerId ||
    251                 permOwnerUserGroupRow.PermissionOwnerId == group.PermissionOwnerId) {
     282              permOwnerUserGroupRow.PermissionOwnerId == group.PermissionOwnerId) {
    252283              deleted.Add(permOwnerUserGroupRow);
    253284            }
  • trunk/sources/HeuristicLab.Hive.Server.Core/DbTestApp.cs

    r936 r939  
    114114      user2.Name = "Martin";
    115115
     116      User user3 =
     117        new User();
     118      user3.Name = "Heinz";
     119
    116120      UserGroup group =
    117121        new UserGroup();
     
    121125      subGroup.Members.Add(user);
    122126
     127      group.Members.Add(user3);
    123128      group.Members.Add(user2);
    124129      group.Members.Add(subGroup);
     
    132137        userGroupAdapter.GetAllUserGroups();
    133138
     139      IUserAdapter userAdapter =
     140        ServiceLocator.GetUserAdapter();
     141
     142      userAdapter.DeleteUser(user3);
     143     
     144      read =
     145         userGroupAdapter.GetUserGroupById(group.PermissionOwnerId);
     146
    134147      userGroupAdapter.DeleteUserGroup(subGroup);
     148
     149      read =
     150         userGroupAdapter.GetUserGroupById(group.PermissionOwnerId);
    135151
    136152      userGroups =
    137153        userGroupAdapter.GetAllUserGroups();
    138 
    139       read =
    140         userGroupAdapter.GetUserGroupById(group.PermissionOwnerId);
    141154
    142155      userGroupAdapter.DeleteUserGroup(group);
     
    144157      userGroups =
    145158        userGroupAdapter.GetAllUserGroups();
    146 
    147       IUserAdapter userAdapter =
    148         ServiceLocator.GetUserAdapter();
    149159
    150160      userAdapter.DeleteUser(user);
  • trunk/sources/HeuristicLab.Hive.Server.Core/InternalInterfaces/DataAccess/IUserGroupAdapter.cs

    r910 r939  
    5151
    5252    /// <summary>
     53    /// Gets all user groups where the permission owner is member of
     54    /// </summary>
     55    /// <param name="permOwner"></param>
     56    /// <returns></returns>
     57    ICollection<UserGroup> MemberOf(PermissionOwner permOwner);
     58
     59    /// <summary>
    5360    /// Deletes the user group
    5461    /// </summary>
Note: See TracChangeset for help on using the changeset viewer.