Skip to content

Commit

Permalink
Update tables\code so that were not using Guid indexes unless neccessary
Browse files Browse the repository at this point in the history
  • Loading branch information
azturner committed Apr 14, 2012
1 parent 736f1ec commit bf7a6d7
Show file tree
Hide file tree
Showing 44 changed files with 415 additions and 387 deletions.
27 changes: 27 additions & 0 deletions ConvertAuth.sql
@@ -0,0 +1,27 @@
WITH CTE
AS
(
SELECT
Id,
CASE UserOrRoleName
WHEN '*AU' THEN 1
WHEN '*AAU' THEN 2
WHEN '*AUU' THEN 3
ELSE 0 END as SpecialRole,
CASE WHEN UserOrRoleName not like '*%' AND UserOrRole = 'U' THEN UserOrRoleName ELSE null END as PersonGuid,
CASE WHEN UserOrRoleName not like '*%' AND UserOrRole = 'R' THEN UserOrRoleName ELSE null END as GroupGuid
from cmsAuth
)

UPDATE A SET
SpecialRole = CTE.SpecialRole,
PersonId = P.Id,
GroupId = G.Id
FROM CTE
INNER JOIN cmsAuth A
ON A.Id = CTE.Id
LEFT OUTER JOIN crmPerson P
ON P.Guid = CTE.PersonGuid
LEFT OUTER JOIN GroupsGroup G
ON G.Guid = CTE.GroupGuid

26 changes: 17 additions & 9 deletions Rock.DataTransferObjects/Cms/Auth.cs
Expand Up @@ -60,6 +60,14 @@ public partial class Auth
/// </value>
public int Order { get; set; }

/// <summary>
/// Gets or sets the Action.
/// </summary>
/// <value>
/// Action.
/// </value>
public string Action { get; set; }

/// <summary>
/// Gets or sets the Allow Or Deny.
/// </summary>
Expand All @@ -69,28 +77,28 @@ public partial class Auth
public string AllowOrDeny { get; set; }

/// <summary>
/// Gets or sets the User Or Role.
/// Gets or sets the Special Role.
/// </summary>
/// <value>
/// U = User, R = Role.
/// Enum[SpecialRole].
/// </value>
public string UserOrRole { get; set; }
public int SpecialRole { get; set; }

/// <summary>
/// Gets or sets the Action.
/// Gets or sets the Person Id.
/// </summary>
/// <value>
/// Action.
/// Person Id.
/// </value>
public string Action { get; set; }
public int? PersonId { get; set; }

/// <summary>
/// Gets or sets the User Or Role Name.
/// Gets or sets the Group Id.
/// </summary>
/// <value>
/// User Or Role Name.
/// Group Id.
/// </value>
public string UserOrRoleName { get; set; }
public int? GroupId { get; set; }

/// <summary>
/// Gets or sets the Created Date Time.
Expand Down
2 changes: 1 addition & 1 deletion Rock/Attribute/Helper.cs
Expand Up @@ -83,7 +83,7 @@ private static bool UpdateAttribute( Rock.Attribute.PropertyAttribute property,
Core.FieldTypeService fieldTypeService = new Core.FieldTypeService();

// Look for an existing attribute record based on the entity, entityQualifierColumn and entityQualifierValue
Core.Attribute attribute = attributeService.GetAttributeByEntityQualifierAndKey(
Core.Attribute attribute = attributeService.GetByEntityAndEntityQualifierColumnAndEntityQualifierValueAndKey(
entity, entityQualifierColumn, entityQualifierValue, property.Key );

if ( attribute == null )
Expand Down
26 changes: 26 additions & 0 deletions Rock/CMS/Auth.Partial.cs
Expand Up @@ -18,4 +18,30 @@ public override bool DefaultAuthorization( string action )
return false;
}
}

/// <summary>
/// Authorization for a special group of users not defined by a specific role or person
/// </summary>
public enum SpecialRole
{
/// <summary>
/// No special role
/// </summary>
None = 0,

/// <summary>
/// Authorize all users
/// </summary>
AllUsers = 1,

/// <summary>
/// Authorize all authenticated users
/// </summary>
AllAuthenticatedUsers = 2,

/// <summary>
/// Authorize all un-authenticated users
/// </summary>
AllUnAuthenticatedUsers = 3,
}
}
69 changes: 55 additions & 14 deletions Rock/CMS/Auth.cs
Expand Up @@ -54,6 +54,16 @@ public partial class Auth : ModelWithAttributes<Auth>, IAuditable, IOrdered
[DataMember]
public int Order { get; set; }

/// <summary>
/// Gets or sets the Action.
/// </summary>
/// <value>
/// Action.
/// </value>
[MaxLength( 50 )]
[DataMember]
public string Action { get; set; }

/// <summary>
/// Gets or sets the Allow Or Deny.
/// </summary>
Expand All @@ -64,33 +74,44 @@ public partial class Auth : ModelWithAttributes<Auth>, IAuditable, IOrdered
public string AllowOrDeny { get; set; }

/// <summary>
/// Gets or sets the User Or Role.
/// Gets or sets the Special Role.
/// </summary>
/// <value>
/// U = User, R = Role.
/// Enum[SpecialRole].
/// </value>
[DataMember]
public string UserOrRole { get; set; }
internal int SpecialRoleInternal { get; set; }

/// <summary>
/// Gets or sets the Special Role.
/// </summary>
/// <value>
/// Enum[SpecialRole].
/// </value>
[NotMapped]
public SpecialRole SpecialRole
{
get { return (SpecialRole)this.SpecialRoleInternal; }
set { this.SpecialRoleInternal = (int)value; }
}

/// <summary>
/// Gets or sets the Action.
/// Gets or sets the Person Id.
/// </summary>
/// <value>
/// Action.
/// Person Id.
/// </value>
[MaxLength( 50 )]
[DataMember]
public string Action { get; set; }
public int? PersonId { get; set; }

/// <summary>
/// Gets or sets the User Or Role Name.
/// Gets or sets the Group Id.
/// </summary>
/// <value>
/// User Or Role Name.
/// Group Id.
/// </value>
[MaxLength( 100 )]
[DataMember]
public string UserOrRoleName { get; set; }
public int? GroupId { get; set; }

/// <summary>
/// Gets or sets the Created Date Time.
Expand Down Expand Up @@ -144,10 +165,11 @@ public Rock.CMS.DTO.Auth DataTransferObject
dto.EntityType = this.EntityType;
dto.EntityId = this.EntityId;
dto.Order = this.Order;
dto.AllowOrDeny = this.AllowOrDeny;
dto.UserOrRole = this.UserOrRole;
dto.Action = this.Action;
dto.UserOrRoleName = this.UserOrRoleName;
dto.AllowOrDeny = this.AllowOrDeny;
dto.SpecialRole = this.SpecialRoleInternal;
dto.PersonId = this.PersonId;
dto.GroupId = this.GroupId;
dto.CreatedDateTime = this.CreatedDateTime;
dto.ModifiedDateTime = this.ModifiedDateTime;
dto.CreatedByPersonId = this.CreatedByPersonId;
Expand Down Expand Up @@ -177,6 +199,22 @@ public Rock.CMS.DTO.Auth DataTransferObject
/// A <see cref="CRM.Person"/> object.
/// </value>
public virtual CRM.Person ModifiedByPerson { get; set; }

/// <summary>
/// Gets or sets the Group.
/// </summary>
/// <value>
/// A <see cref="Groups.Group"/> object.
/// </value>
public virtual Groups.Group Group { get; set; }

/// <summary>
/// Gets or sets the Person.
/// </summary>
/// <value>
/// A <see cref="CRM.Person"/> object.
/// </value>
public virtual CRM.Person Person { get; set; }

}
/// <summary>
Expand All @@ -189,8 +227,11 @@ public partial class AuthConfiguration : EntityTypeConfiguration<Auth>
/// </summary>
public AuthConfiguration()
{
this.Property( p => p.SpecialRoleInternal ).HasColumnName( "SpecialRole" );
this.HasOptional( p => p.CreatedByPerson ).WithMany().HasForeignKey( p => p.CreatedByPersonId ).WillCascadeOnDelete(false);
this.HasOptional( p => p.ModifiedByPerson ).WithMany().HasForeignKey( p => p.ModifiedByPersonId ).WillCascadeOnDelete(false);
this.HasOptional( p => p.Group ).WithMany().HasForeignKey( p => p.GroupId ).WillCascadeOnDelete(true);
this.HasOptional( p => p.Person ).WithMany().HasForeignKey( p => p.PersonId ).WillCascadeOnDelete(true);
}
}
}
10 changes: 0 additions & 10 deletions Rock/CMS/AuthService.cs
Expand Up @@ -34,15 +34,5 @@ public IEnumerable<Rock.CMS.Auth> GetByEntityTypeAndEntityId( string entityType,
return Repository.Find( t => t.EntityType == entityType && ( t.EntityId == entityId || ( entityId == null && t.EntityId == null ) ) ).OrderBy( t => t.Order );
}

/// <summary>
/// Gets Auths by Guid
/// </summary>
/// <param name="guid">Guid.</param>
/// <returns>An enumerable list of Auth objects.</returns>
public IEnumerable<Rock.CMS.Auth> GetByGuid( Guid guid )
{
return Repository.Find( t => t.Guid == guid ).OrderBy( t => t.Order );
}

}
}
10 changes: 0 additions & 10 deletions Rock/CMS/BlockService.cs
Expand Up @@ -23,16 +23,6 @@ namespace Rock.CMS
/// </summary>
public partial class BlockService : Service<Rock.CMS.Block>
{
/// <summary>
/// Gets Blocks by Guid
/// </summary>
/// <param name="guid">Guid.</param>
/// <returns>An enumerable list of Block objects.</returns>
public IEnumerable<Rock.CMS.Block> GetByGuid( Guid guid )
{
return Repository.Find( t => t.Guid == guid );
}

/// <summary>
/// Gets Blocks by Name
/// </summary>
Expand Down
24 changes: 0 additions & 24 deletions Rock/CMS/FileService.partial.cs

This file was deleted.

10 changes: 0 additions & 10 deletions Rock/CMS/PageRouteService.cs
Expand Up @@ -23,16 +23,6 @@ namespace Rock.CMS
/// </summary>
public partial class PageRouteService : Service<Rock.CMS.PageRoute>
{
/// <summary>
/// Gets Page Routes by Guid
/// </summary>
/// <param name="guid">Guid.</param>
/// <returns>An enumerable list of PageRoute objects.</returns>
public IEnumerable<Rock.CMS.PageRoute> GetByGuid( Guid guid )
{
return Repository.Find( t => t.Guid == guid );
}

/// <summary>
/// Gets Page Routes by Page Id
/// </summary>
Expand Down
10 changes: 0 additions & 10 deletions Rock/CMS/PageService.cs
Expand Up @@ -23,16 +23,6 @@ namespace Rock.CMS
/// </summary>
public partial class PageService : Service<Rock.CMS.Page>
{
/// <summary>
/// Gets Pages by Guid
/// </summary>
/// <param name="guid">Guid.</param>
/// <returns>An enumerable list of Page objects.</returns>
public IEnumerable<Rock.CMS.Page> GetByGuid( Guid guid )
{
return Repository.Find( t => t.Guid == guid ).OrderBy( t => t.Order );
}

/// <summary>
/// Gets Pages by Parent Page Id
/// </summary>
Expand Down
10 changes: 0 additions & 10 deletions Rock/CMS/SiteDomainService.cs
Expand Up @@ -33,16 +33,6 @@ public Rock.CMS.SiteDomain GetByDomain( string domain )
return Repository.FirstOrDefault( t => t.Domain == domain );
}

/// <summary>
/// Gets Site Domains by Guid
/// </summary>
/// <param name="guid">Guid.</param>
/// <returns>An enumerable list of SiteDomain objects.</returns>
public IEnumerable<Rock.CMS.SiteDomain> GetByGuid( Guid guid )
{
return Repository.Find( t => t.Guid == guid );
}

/// <summary>
/// Gets Site Domains by Site Id And Domain
/// </summary>
Expand Down
10 changes: 0 additions & 10 deletions Rock/CMS/SiteService.cs
Expand Up @@ -23,15 +23,5 @@ namespace Rock.CMS
/// </summary>
public partial class SiteService : Service<Rock.CMS.Site>
{
/// <summary>
/// Gets Sites by Guid
/// </summary>
/// <param name="guid">Guid.</param>
/// <returns>An enumerable list of Site objects.</returns>
public IEnumerable<Rock.CMS.Site> GetByGuid( Guid guid )
{
return Repository.Find( t => t.Guid == guid );
}

}
}
2 changes: 1 addition & 1 deletion Rock/CMS/User.Partial.cs
Expand Up @@ -32,7 +32,7 @@ public string ConfirmationCode
{
get
{
string identifier = string.Format( "ROCK|{0}|{1}|{2}", this.Guid.ToString(), this.UserName, DateTime.Now.Ticks );
string identifier = string.Format( "ROCK|{0}|{1}|{2}", this.PublicKey.ToString(), this.UserName, DateTime.Now.Ticks );
string encryptionPhrase = ConfigurationManager.AppSettings["EncryptionPhrase"];
if ( String.IsNullOrWhiteSpace( encryptionPhrase ) )
encryptionPhrase = "Rock Rocks!";
Expand Down
10 changes: 0 additions & 10 deletions Rock/CMS/UserService.cs
Expand Up @@ -33,16 +33,6 @@ public IEnumerable<Rock.CMS.User> GetByApiKey( string apiKey )
return Repository.Find( t => ( t.ApiKey == apiKey || ( apiKey == null && t.ApiKey == null ) ) );
}

/// <summary>
/// Gets User by Guid
/// </summary>
/// <param name="guid">Guid.</param>
/// <returns>User object.</returns>
public Rock.CMS.User GetByGuid( Guid guid )
{
return Repository.FirstOrDefault( t => t.Guid == guid );
}

/// <summary>
/// Gets Users by Person Id
/// </summary>
Expand Down

0 comments on commit bf7a6d7

Please sign in to comment.