creates a user 0 for unknown to keep ref integrity
This commit is contained in:
@@ -12,6 +12,14 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
public const int SuperId = -1;
|
||||
|
||||
/// <summary>
|
||||
/// The id for the 'unknown' user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a user row that exists in the DB only for referential integrity but the user is never returned from any of the services
|
||||
/// </remarks>
|
||||
public const int UnknownId = 0;
|
||||
|
||||
public const string AdminGroupAlias = "admin";
|
||||
public const string SensitiveDataGroupAlias = "sensitiveData";
|
||||
public const string TranslatorGroupAlias = "translator";
|
||||
|
||||
@@ -144,6 +144,7 @@ namespace Umbraco.Core.Migrations.Install
|
||||
|
||||
private void CreateUserData()
|
||||
{
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.User, "id", false, new UserDto { Id = Constants.Security.UnknownId, Disabled = true, NoConsole = true, UserName = "$UMB_UNKNOWN_USER$", Login = "$UMB_UNKNOWN_USER$", Password = "$UMB_UNKNOWN_USER$", Email = "", UserLanguage = "en-US", CreateDate = DateTime.Now, UpdateDate = DateTime.Now });
|
||||
_database.Insert(Constants.DatabaseSchema.Tables.User, "id", false, new UserDto { Id = Constants.Security.SuperId, Disabled = false, NoConsole = false, UserName = "Administrator", Login = "admin", Password = "default", Email = "", UserLanguage = "en-US", CreateDate = DateTime.Now, UpdateDate = DateTime.Now });
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace Umbraco.Core.Migrations.Install
|
||||
// all tables, in order
|
||||
public static readonly List<Type> OrderedTables = new List<Type>
|
||||
{
|
||||
typeof (UserDto),
|
||||
typeof (NodeDto),
|
||||
typeof (ContentTypeDto),
|
||||
typeof (TemplateDto),
|
||||
@@ -58,7 +59,6 @@ namespace Umbraco.Core.Migrations.Install
|
||||
typeof (RelationDto),
|
||||
typeof (TagDto),
|
||||
typeof (TagRelationshipDto),
|
||||
typeof (UserDto),
|
||||
typeof (TaskTypeDto),
|
||||
typeof (TaskDto),
|
||||
typeof (ContentType2ContentTypeDto),
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace Umbraco.Core.Persistence.Dtos
|
||||
|
||||
// fixme want?
|
||||
[Column("availableUserId")]
|
||||
// [ForeignKey(typeof(UserDto))] -- there is no foreign key so we can delete users without deleting associated content
|
||||
//[NullSetting(NullSetting = NullSettings.Null)]
|
||||
[ForeignKey(typeof(UserDto))]
|
||||
public int PublishedUserId { get; set; }
|
||||
|
||||
[Column("edited")]
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Umbraco.Core.Persistence.Dtos
|
||||
public DateTime VersionDate { get; set; }
|
||||
|
||||
[Column("userId")]
|
||||
[ForeignKey(typeof(UserDto))]
|
||||
public int UserId { get; set; }
|
||||
|
||||
[Column("current")]
|
||||
|
||||
@@ -83,6 +83,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
protected override IUser PerformGet(int id)
|
||||
{
|
||||
if (id == Constants.Security.UnknownId)
|
||||
return null;
|
||||
|
||||
var sql = SqlContext.Sql()
|
||||
.Select<UserDto>()
|
||||
.From<UserDto>()
|
||||
@@ -282,7 +285,8 @@ ORDER BY colName";
|
||||
{
|
||||
var sql = SqlContext.Sql()
|
||||
.Select<UserDto>()
|
||||
.From<UserDto>();
|
||||
.From<UserDto>()
|
||||
.Where<UserDto>(x => x.Id != Constants.Security.UnknownId);
|
||||
|
||||
with?.Invoke(sql);
|
||||
|
||||
@@ -616,7 +620,9 @@ ORDER BY colName";
|
||||
|
||||
public int GetCountByQuery(IQuery<IUser> query)
|
||||
{
|
||||
var sqlClause = GetBaseQuery("umbracoUser.id");
|
||||
var sqlClause = GetBaseQuery("umbracoUser.id")
|
||||
.Where<UserDto>(x => x.Id != Constants.Security.UnknownId);
|
||||
|
||||
var translator = new SqlTranslator<IUser>(sqlClause, query);
|
||||
var subquery = translator.Translate();
|
||||
//get the COUNT base query
|
||||
@@ -631,7 +637,7 @@ ORDER BY colName";
|
||||
var sql = SqlContext.Sql()
|
||||
.SelectCount()
|
||||
.From<UserDto>()
|
||||
.Where<UserDto>(x => x.UserName == username);
|
||||
.Where<UserDto>(x => x.Id != Constants.Security.UnknownId && x.UserName == username);
|
||||
|
||||
return Database.ExecuteScalar<int>(sql) > 0;
|
||||
}
|
||||
@@ -670,6 +676,8 @@ ORDER BY colName";
|
||||
else
|
||||
sql.WhereNotIn<UserDto>(x => x.Id, inSql);
|
||||
|
||||
sql.Where<UserDto>(x => x.Id != Constants.Security.UnknownId);
|
||||
|
||||
return ConvertFromDtos(Database.Fetch<UserDto>(sql));
|
||||
}
|
||||
|
||||
@@ -800,7 +808,7 @@ ORDER BY colName";
|
||||
sql = new SqlTranslator<IUser>(sql, query).Translate();
|
||||
|
||||
// get sorted and filtered sql
|
||||
var sqlNodeIdsWithSort = ApplySort(ApplyFilter(sql, filterSql), orderDirection, orderBy);
|
||||
var sqlNodeIdsWithSort = ApplySort(ApplyFilter(sql, filterSql), orderDirection, orderBy);
|
||||
|
||||
// get a page of results and total count
|
||||
var pagedResult = Database.Page<UserDto>(pageIndex + 1, pageSize, sqlNodeIdsWithSort);
|
||||
@@ -813,9 +821,11 @@ ORDER BY colName";
|
||||
|
||||
private Sql<ISqlContext> ApplyFilter(Sql<ISqlContext> sql, Sql<ISqlContext> filterSql)
|
||||
{
|
||||
if (filterSql == null) return sql;
|
||||
if (filterSql == null)
|
||||
return sql.Where<UserDto>(x => x.Id != Constants.Security.UnknownId);
|
||||
|
||||
sql.Append(SqlContext.Sql(" WHERE " + filterSql.SQL.TrimStart("AND "), filterSql.Arguments));
|
||||
sql.Append($" AND umbracoUser.id <> {Constants.Security.UnknownId}");
|
||||
|
||||
return sql;
|
||||
}
|
||||
@@ -837,7 +847,7 @@ ORDER BY colName";
|
||||
var idsQuery = SqlContext.Sql()
|
||||
.Select<UserDto>(x => x.Id)
|
||||
.From<UserDto>()
|
||||
.Where<UserDto>(x => x.Id >= id)
|
||||
.Where<UserDto>(x => x.Id != Constants.Security.UnknownId && x.Id >= id)
|
||||
.OrderBy<UserDto>(x => x.Id);
|
||||
|
||||
// first page is index 1, not zero
|
||||
|
||||
Reference in New Issue
Block a user