Merge pull request #5561 from barronpm/permissions-fix

pull/5580/head
Claus Vium 4 years ago committed by GitHub
commit e1c6bb0482
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -73,9 +73,6 @@ namespace Jellyfin.Data.Entities
PlayDefaultAudioTrack = true; PlayDefaultAudioTrack = true;
SubtitleMode = SubtitlePlaybackMode.Default; SubtitleMode = SubtitlePlaybackMode.Default;
SyncPlayAccess = SyncPlayUserAccessType.CreateAndJoinGroups; SyncPlayAccess = SyncPlayUserAccessType.CreateAndJoinGroups;
AddDefaultPermissions();
AddDefaultPreferences();
} }
/// <summary> /// <summary>
@ -483,18 +480,11 @@ namespace Jellyfin.Data.Entities
return Array.IndexOf(GetPreferenceValues<Guid>(PreferenceKind.GroupedFolders), id) != -1; return Array.IndexOf(GetPreferenceValues<Guid>(PreferenceKind.GroupedFolders), id) != -1;
} }
private static bool IsParentalScheduleAllowed(AccessSchedule schedule, DateTime date) /// <summary>
{ /// Initializes the default permissions for a user. Should only be called on user creation.
var localTime = date.ToLocalTime(); /// </summary>
var hour = localTime.TimeOfDay.TotalHours;
return DayOfWeekHelper.GetDaysOfWeek(schedule.DayOfWeek).Contains(localTime.DayOfWeek)
&& hour >= schedule.StartHour
&& hour <= schedule.EndHour;
}
// TODO: make these user configurable? // TODO: make these user configurable?
private void AddDefaultPermissions() public void AddDefaultPermissions()
{ {
Permissions.Add(new Permission(PermissionKind.IsAdministrator, false)); Permissions.Add(new Permission(PermissionKind.IsAdministrator, false));
Permissions.Add(new Permission(PermissionKind.IsDisabled, false)); Permissions.Add(new Permission(PermissionKind.IsDisabled, false));
@ -519,12 +509,25 @@ namespace Jellyfin.Data.Entities
Permissions.Add(new Permission(PermissionKind.EnableRemoteControlOfOtherUsers, false)); Permissions.Add(new Permission(PermissionKind.EnableRemoteControlOfOtherUsers, false));
} }
private void AddDefaultPreferences() /// <summary>
/// Initializes the default preferences. Should only be called on user creation.
/// </summary>
public void AddDefaultPreferences()
{ {
foreach (var val in Enum.GetValues(typeof(PreferenceKind)).Cast<PreferenceKind>()) foreach (var val in Enum.GetValues(typeof(PreferenceKind)).Cast<PreferenceKind>())
{ {
Preferences.Add(new Preference(val, string.Empty)); Preferences.Add(new Preference(val, string.Empty));
} }
} }
private static bool IsParentalScheduleAllowed(AccessSchedule schedule, DateTime date)
{
var localTime = date.ToLocalTime();
var hour = localTime.TimeOfDay.TotalHours;
return DayOfWeekHelper.GetDaysOfWeek(schedule.DayOfWeek).Contains(localTime.DayOfWeek)
&& hour >= schedule.StartHour
&& hour <= schedule.EndHour;
}
} }
} }

@ -190,6 +190,9 @@ namespace Jellyfin.Server.Implementations.Users
InternalId = max + 1 InternalId = max + 1
}; };
user.AddDefaultPermissions();
user.AddDefaultPreferences();
_users.Add(user.Id, user); _users.Add(user.Id, user);
return user; return user;

@ -128,6 +128,8 @@ namespace Jellyfin.Api.Tests.Auth
{ {
var authorizationInfo = _fixture.Create<AuthorizationInfo>(); var authorizationInfo = _fixture.Create<AuthorizationInfo>();
authorizationInfo.User = _fixture.Create<User>(); authorizationInfo.User = _fixture.Create<User>();
authorizationInfo.User.AddDefaultPermissions();
authorizationInfo.User.AddDefaultPreferences();
authorizationInfo.User.SetPermission(PermissionKind.IsAdministrator, isAdmin); authorizationInfo.User.SetPermission(PermissionKind.IsAdministrator, isAdmin);
authorizationInfo.IsApiKey = false; authorizationInfo.IsApiKey = false;

@ -29,6 +29,9 @@ namespace Jellyfin.Api.Tests
typeof(DefaultAuthenticationProvider).FullName!, typeof(DefaultAuthenticationProvider).FullName!,
typeof(DefaultPasswordResetProvider).FullName!); typeof(DefaultPasswordResetProvider).FullName!);
user.AddDefaultPermissions();
user.AddDefaultPreferences();
// Set administrator flag. // Set administrator flag.
user.SetPermission(PermissionKind.IsAdministrator, role.Equals(UserRoles.Administrator, StringComparison.OrdinalIgnoreCase)); user.SetPermission(PermissionKind.IsAdministrator, role.Equals(UserRoles.Administrator, StringComparison.OrdinalIgnoreCase));

Loading…
Cancel
Save