-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adfd004
commit 2ec0dd7
Showing
5 changed files
with
231 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using Signum.Entities.Basics; | ||
using Signum.Utilities.Reflection; | ||
|
||
namespace Signum.Entities.DynamicQuery; | ||
|
||
|
||
public class EntityTypeToken : QueryToken | ||
{ | ||
QueryToken parent; | ||
public override QueryToken? Parent => parent; | ||
|
||
internal EntityTypeToken(QueryToken parent) | ||
{ | ||
this.parent = parent ?? throw new ArgumentNullException(nameof(parent)); | ||
|
||
this.Priority = 10; | ||
} | ||
|
||
public override Type Type | ||
{ | ||
get { return typeof(TypeEntity).BuildLite(); } | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return "[" + QueryTokenMessage.EntityType.NiceToString() + "]"; | ||
} | ||
|
||
public override string Key | ||
{ | ||
get { return "[EntityType]"; } | ||
} | ||
|
||
static MethodInfo miTypeEntity = ReflectionTools.GetMethodInfo(() => TypeEntityExtensions.ToTypeEntity(null!)); | ||
|
||
protected override Expression BuildExpressionInternal(BuildExpressionContext context) | ||
{ | ||
Expression baseExpression = parent.BuildExpression(context); | ||
|
||
Expression entityType = Expression.Property(baseExpression, "EntityType"); | ||
|
||
Expression typeEntity = Expression.Call(miTypeEntity, entityType); | ||
|
||
return typeEntity.BuildLite(); | ||
} | ||
|
||
protected override List<QueryToken> SubTokensOverride(SubTokensOptions options) | ||
{ | ||
return SubTokensBase(typeof(TypeEntity), options, GetImplementations()); | ||
} | ||
|
||
public override string? Format | ||
{ | ||
get { return null; } | ||
} | ||
|
||
public override string? Unit | ||
{ | ||
get { return null; } | ||
} | ||
|
||
public override Implementations? GetImplementations() | ||
{ | ||
return Implementations.By(typeof(TypeEntity)); | ||
} | ||
|
||
public override string? IsAllowed() | ||
{ | ||
var parentAllowed = this.parent.IsAllowed(); | ||
var routeAllowed = GetPropertyRoute()!.IsAllowed(); | ||
|
||
if (parentAllowed.HasText() && routeAllowed.HasText()) | ||
QueryTokenMessage.And.NiceToString().Combine(parentAllowed, routeAllowed); | ||
|
||
return parentAllowed ?? routeAllowed; | ||
} | ||
|
||
public override PropertyRoute? GetPropertyRoute() | ||
{ | ||
return PropertyRoute.Root(typeof(TypeEntity)); | ||
} | ||
|
||
public override string NiceName() | ||
{ | ||
return QueryTokenMessage._0Of1.NiceToString().FormatWith(QueryTokenMessage.EntityType.NiceToString(), parent.ToString()); | ||
} | ||
|
||
public override QueryToken Clone() | ||
{ | ||
return new EntityTypeToken(parent.Clone()); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2ec0dd7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presenting
EntityTypeToken
The QueryToken family (aka the DropdownList sequence that you use to create filters or columns in the
SearchControl
,Chart
,UserQuery
,WordTemplate
,EmailTemplate
, etc..) has a new member:EntityTypeToken
.This token, shown as
[Entity Type]
in english, is avalable in anyImplementedBy
andImplementedByAll
reference and points to theTypeEntity
associated to theSystem.Type
of the value stored in this reference.Since is a
TypeEntity
you can drill-down an access fields likeClassName
oNamespace
.If
[Entity Type]
is not in the available list of options of anImplementedBy
andImplementedByAll
, check your AuthRules! the user has to read access to theTypeEntity
type.2ec0dd7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! 👍