pull/733/head
Jamie.Rees 8 years ago
parent 30a59c8a8b
commit 21f3131cb4

@ -44,10 +44,16 @@ namespace PlexRequests.Core.SettingModels
public bool SearchForMovies { get; set; }
public bool SearchForTvShows { get; set; }
public bool SearchForMusic { get; set; }
[Obsolete("Use the user management settings")]
public bool RequireMovieApproval { get; set; }
[Obsolete("Use the user management settings")]
public bool RequireTvShowApproval { get; set; }
[Obsolete("Use the user management settings")]
public bool RequireMusicApproval { get; set; }
[Obsolete("Use the user management settings")]
public bool UsersCanViewOnlyOwnRequests { get; set; }
[Obsolete("Use the user management settings")]
public bool UsersCanViewOnlyOwnIssues { get; set; }
public int MovieWeeklyRequestLimit { get; set; }
public int TvWeeklyRequestLimit { get; set; }

@ -35,6 +35,8 @@ namespace PlexRequests.Core.SettingModels
public bool AutoApproveTvShows { get; set; }
public bool AutoApproveMusic { get; set; }
public bool ReportIssues { get; set; }
public bool UsersCanViewOnlyOwnRequests { get; set; }
public bool UsersCanViewOnlyOwnIssues { get; set; }
// Features
public bool RecentlyAddedNotification { get; set; }

@ -50,7 +50,7 @@ namespace PlexRequests.Core
Db = new DbConfiguration(new SqliteFactory());
var created = Db.CheckDb();
TableCreation.CreateTables(Db.DbConnection());
if (created)
{
CreateDefaultSettingsPage(urlBase);
@ -60,27 +60,36 @@ namespace PlexRequests.Core
// Shrink DB
TableCreation.Vacuum(Db.DbConnection());
}
// Add the new 'running' item into the scheduled jobs so we can check if the cachers are running
Db.DbConnection().AlterTable("ScheduledJobs", "ADD", "Running", true, "INTEGER");
return Db.DbConnection().ConnectionString;
}
private void CreateDefaultSettingsPage(string baseUrl)
{
var defaultUserSettings = new UserManagementSettings
{
RequestMovies = true,
RequestTvShows = true,
ReportIssues = true,
};
var defaultSettings = new PlexRequestSettings
{
RequireTvShowApproval = true,
RequireMovieApproval = true,
SearchForMovies = true,
SearchForTvShows = true,
BaseUrl = baseUrl ?? string.Empty,
CollectAnalyticData = true,
};
var s = new SettingsServiceV2<PlexRequestSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
var ctor = new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider());
var s = new SettingsServiceV2<PlexRequestSettings>(ctor);
s.SaveSettings(defaultSettings);
var userSettings = new SettingsServiceV2<UserManagementSettings>(ctor);
userSettings.SaveSettings(defaultUserSettings);
var cron = (Quartz.Impl.Triggers.CronTriggerImpl)CronScheduleBuilder.WeeklyOnDayAndHourAndMinute(DayOfWeek.Friday, 7, 0).Build();
var scheduled = new ScheduledJobsSettings

@ -61,6 +61,12 @@ namespace PlexRequests.Helpers.Permissions
AutoApproveAlbum = 256,
[Display(Name = "Manage Requests")]
ManageRequests = 512
ManageRequests = 512,
[Display(Name = "Users can only view their own requests")]
UsersCanViewOnlyOwnRequests = 1024,
[Display(Name = "Users can only view their own issues")]
UsersCanViewOnlyOwnIssues = 2048
}
}

@ -317,14 +317,11 @@ namespace PlexRequests.Services.Jobs
switch (requestType)
{
case RequestType.Movie:
return Security.HasPermissions(user, Permissions.AutoApproveMovie) ||
!prSettings.RequireMovieApproval;
return Security.HasPermissions(user, Permissions.AutoApproveMovie);
case RequestType.TvShow:
return Security.HasPermissions(user, Permissions.AutoApproveTv) ||
!prSettings.RequireTvShowApproval;
return Security.HasPermissions(user, Permissions.AutoApproveTv);
case RequestType.Album:
return Security.HasPermissions(user, Permissions.AutoApproveAlbum) ||
!prSettings.RequireMusicApproval;
return Security.HasPermissions(user, Permissions.AutoApproveAlbum);
default:
return false;
}

@ -106,31 +106,6 @@
});
$('#contentBody').on('click', '#SearchForMovies', function () {
var checked = this.checked;
changeDisabledStatus($('#RequireMovieApproval'), checked, $('#RequireMovieApprovalLabel'));
});
$('#contentBody').on('click', '#SearchForTvShows', function () {
var checked = this.checked;
changeDisabledStatus($('#RequireTvShowApproval'), checked, $('#RequireTvShowApprovalLabel'));
});
$('#contentBody').on('click', '#SearchForMusic', function () {
var checked = this.checked;
changeDisabledStatus($('#RequireMusicApproval'), checked, $('#RequireMusicApprovalLabel'));
});
function changeDisabledStatus($element, checked, $label) {
if (checked) {
$element.removeAttr("disabled");
$label.css("color","");
} else {
$element.attr("disabled","disabled");
$label.css("color", "grey");
}
}
function loadArea(templateId) {
var $body = $('#contentBody');

@ -335,7 +335,7 @@ namespace PlexRequests.UI.Modules
myIssues = issuesModels.Where(x => x.IssueStatus != IssueStatus.ResolvedIssue);
}
}
else if (settings.UsersCanViewOnlyOwnIssues) // The user is not an Admin, do we have the settings to hide them?
else if (Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnIssues)) // The user is not an Admin, do we have the settings to hide them?
{
if (!showResolved)
{

@ -129,7 +129,7 @@ namespace PlexRequests.UI.Modules
var dbMovies = allRequests.ToList();
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
if (Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests) && !IsAdmin)
{
dbMovies = dbMovies.Where(x => x.UserHasRequested(Username)).ToList();
}
@ -199,7 +199,7 @@ namespace PlexRequests.UI.Modules
var dbTv = requests;
var settings = await settingsTask;
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
if (Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests) && !IsAdmin)
{
dbTv = dbTv.Where(x => x.UserHasRequested(Username)).ToList();
}
@ -271,7 +271,7 @@ namespace PlexRequests.UI.Modules
var settings = PrSettings.GetSettings();
var dbAlbum = await Service.GetAllAsync();
dbAlbum = dbAlbum.Where(x => x.Type == RequestType.Album);
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
if (Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests) && !IsAdmin)
{
dbAlbum = dbAlbum.Where(x => x.UserHasRequested(Username));
}

@ -278,7 +278,7 @@ namespace PlexRequests.UI.Modules
VoteAverage = movie.VoteAverage,
VoteCount = movie.VoteCount
};
var canSee = CanUserSeeThisRequest(viewMovie.Id, settings.UsersCanViewOnlyOwnRequests, dbMovies);
var canSee = CanUserSeeThisRequest(viewMovie.Id, Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests), dbMovies);
var plexMovie = Checker.GetMovie(plexMovies.ToArray(), movie.Title, movie.ReleaseDate?.Year.ToString(),
imdbId);
if (plexMovie != null)
@ -510,7 +510,7 @@ namespace PlexRequests.UI.Modules
{
Result = true,
Message =
settings.UsersCanViewOnlyOwnRequests
Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests)
? $"{fullMovieName} {Resources.UI.Search_SuccessfullyAdded}"
: $"{fullMovieName} {Resources.UI.Search_AlreadyRequested}"
});
@ -968,7 +968,7 @@ namespace PlexRequests.UI.Modules
{
existingRequest.RequestedUsers.Add(Username);
}
if (settings.UsersCanViewOnlyOwnRequests || episodeReq)
if (Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests) || episodeReq)
{
return
await
@ -1033,7 +1033,7 @@ namespace PlexRequests.UI.Modules
{
Result = true,
Message =
settings.UsersCanViewOnlyOwnRequests
Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests)
? $"{existingRequest.Title} {Resources.UI.Search_SuccessfullyAdded}"
: $"{existingRequest.Title} {Resources.UI.Search_AlreadyRequested}"
});
@ -1374,14 +1374,11 @@ namespace PlexRequests.UI.Modules
switch (requestType)
{
case RequestType.Movie:
return Security.HasPermissions(User, Permissions.AutoApproveMovie) ||
!prSettings.RequireMovieApproval;
return Security.HasPermissions(User, Permissions.AutoApproveMovie);
case RequestType.TvShow:
return Security.HasPermissions(User, Permissions.AutoApproveTv) ||
!prSettings.RequireTvShowApproval;
return Security.HasPermissions(User, Permissions.AutoApproveTv);
case RequestType.Album:
return Security.HasPermissions(User, Permissions.AutoApproveAlbum) ||
!prSettings.RequireMusicApproval;
return Security.HasPermissions(User, Permissions.AutoApproveAlbum);
default:
return false;
}

@ -158,10 +158,7 @@ namespace PlexRequests.UI.Modules
currentSettings.SearchForMovies = form.SearchForMovies;
currentSettings.SearchForTvShows = form.SearchForTvShows;
currentSettings.SearchForMusic = form.SearchForMusic;
currentSettings.RequireMovieApproval = form.RequireMovieApproval;
currentSettings.RequireTvShowApproval = form.RequireTvShowApproval;
currentSettings.RequireMusicApproval = form.RequireMusicApproval;
var result = await PlexRequestSettings.SaveSettingsAsync(currentSettings);
if (result)
{

@ -50,18 +50,10 @@
<br />
<a href="~/usermanagement/" class="btn btn-info-outline">User Management</a>
<br />
<p class="form-group">Current users that are allowed to authenticate: </p>
<div class="form-group">
<select id="users" multiple="" class="form-control-custom" style="height: 180px;"></select>
</div>
<div class="form-group">
<div>
<button id="refreshUsers" class="btn btn-primary-outline">Refresh Users</button>
</div>
</div>
<br />
<p class="form-group">A comma separated list of users that you do not want to login.</p>
<div class="form-group">

@ -112,81 +112,6 @@
</div>
</div>
<div class="form-group">
<div class="checkbox">
@if (Model.RequireMovieApproval)
{
<input type="checkbox" id="RequireMovieApproval" name="RequireMovieApproval" checked="checked"><label for="RequireMovieApproval">Require approval of Movie requests</label>
}
else
{
<input type="checkbox" id="RequireMovieApproval" name="RequireMovieApproval"><label for="RequireMovieApproval">Require approval of Movie requests</label>
}
</div>
</div>
<div class="form-group">
<div class="checkbox">
@if (Model.RequireTvShowApproval)
{
<input type="checkbox" id="RequireTvShowApproval" name="RequireTvShowApproval" checked="checked"><label for="RequireTvShowApproval">Require approval of TV show requests</label>
}
else
{
<input type="checkbox" id="RequireTvShowApproval" name="RequireTvShowApproval"><label for="RequireTvShowApproval">Require approval of TV show requests</label>
}
</div>
</div>
<div class="form-group">
<div class="checkbox">
@if (Model.RequireMusicApproval)
{
<input type="checkbox" id="RequireMusicApproval" name="RequireMusicApproval" checked="checked"><label for="RequireMusicApproval">Require approval of Music requests</label>
}
else
{
<input type="checkbox" id="RequireMusicApproval" name="RequireMusicApproval"><label for="RequireMusicApproval">Require approval of Music requests</label>
}
</div>
</div>
<div class="form-group">
<div class="checkbox">
@if (Model.UsersCanViewOnlyOwnRequests)
{
<input type="checkbox" id="UsersCanViewOnlyOwnRequests" name="UsersCanViewOnlyOwnRequests" checked="checked">
<label for="UsersCanViewOnlyOwnRequests">Users can view their own requests only</label>
}
else
{
<input type="checkbox" id="UsersCanViewOnlyOwnRequests" name="UsersCanViewOnlyOwnRequests"><label for="UsersCanViewOnlyOwnRequests">Users can view their own requests only</label>
}
</div>
</div>
<div class="form-group">
<div class="checkbox">
@if (Model.UsersCanViewOnlyOwnIssues)
{
<input type="checkbox" id="UsersCanViewOnlyOwnIssues" name="UsersCanViewOnlyOwnIssues" checked="checked">
<label for="UsersCanViewOnlyOwnIssues">Users can view their own issues only</label>
}
else
{
<input type="checkbox" id="UsersCanViewOnlyOwnIssues" name="UsersCanViewOnlyOwnIssues"><label for="UsersCanViewOnlyOwnIssues">Users can view their own issues only</label>
}
</div>
</div>
<div class="form-group">
<div class="checkbox">

@ -11,19 +11,19 @@
<h3>Permissions</h3>
@Html.Checkbox(Model.RequestMovies, "RequestMovies", "Request Movies");
@Html.Checkbox(Model.RequestTvShows, "RequestTvShows", "Request TV Shows");
@Html.Checkbox(Model.RequestMusic, "RequestMusic", "Request Music");
@Html.Checkbox(Model.AutoApproveMovies, "AutoApproveMovies", "Auto Approve Movie Requests");
@Html.Checkbox(Model.AutoApproveTvShows, "AutoApproveTvShows", "Auto Approve TV Show Requests");
@Html.Checkbox(Model.AutoApproveMusic, "AutoApproveMusic", "Auto Approve Music Requests");
@Html.Checkbox(Model.ReportIssues, "ReportIssues", "Report Issues");
@Html.Checkbox(Model.RequestMovies, "RequestMovies", "Request Movies")
@Html.Checkbox(Model.RequestTvShows, "RequestTvShows", "Request TV Shows")
@Html.Checkbox(Model.RequestMusic, "RequestMusic", "Request Music")
@Html.Checkbox(Model.AutoApproveMovies, "AutoApproveMovies", "Auto Approve Movie Requests")
@Html.Checkbox(Model.AutoApproveTvShows, "AutoApproveTvShows", "Auto Approve TV Show Requests")
@Html.Checkbox(Model.AutoApproveMusic, "AutoApproveMusic", "Auto Approve Music Requests")
@Html.Checkbox(Model.ReportIssues, "ReportIssues", "Report Issues")
<h3>Features</h3>
@Html.Checkbox(Model.RecentlyAddedNewsletter, "RecentlyAddedNewsletter", "Recently Added Newsletter");
@Html.Checkbox(Model.RecentlyAddedNotification, "RecentlyAddedNotification", "Recently Added Notifications");
@Html.Checkbox(Model.RecentlyAddedNewsletter, "RecentlyAddedNewsletter", "Recently Added Newsletter")
@Html.Checkbox(Model.RecentlyAddedNotification, "RecentlyAddedNotification", "Recently Added Notifications")
<div>
</div>

@ -104,22 +104,7 @@
<input type="checkbox" id="SearchForMusic" name="SearchForMusic"><label id="SearchForMusicLabel" for="SearchForMusic">Allow searching for Music</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" disabled="disabled" id="RequireMovieApproval" name="RequireMovieApproval"><label style="color:grey" id="RequireMovieApprovalLabel" for="RequireMovieApproval">Require approval of all Movie requests</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" disabled="disabled" id="RequireTvShowApproval" name="RequireTvShowApproval"><label style="color:grey" id="RequireTvShowApprovalLabel" for="RequireTvShowApproval">Require approval of all TV show requests</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" disabled="disabled" id="RequireMusicApproval" name="RequireMusicApproval"><label style="color:grey" id="RequireMusicApprovalLabel" for="RequireMusicApproval">Require approval of all Music requests</label>
</div>
</div>
<div class="form-group">
<div style="text-align: center; margin-top: 20px">
<a href="#" id="submitPlexRequest" class="btn btn-primary-outline">Next</a>

Loading…
Cancel
Save