pull/2580/head^2
TidusJar 6 years ago
commit afc55e6f1f

@ -14,5 +14,6 @@
public const string RequestMusic = nameof(RequestMusic);
public const string Disabled = nameof(Disabled);
public const string ReceivesNewsletter = nameof(ReceivesNewsletter);
public const string ManageOwnRequests = nameof(ManageOwnRequests);
}
}

@ -145,6 +145,16 @@ namespace Ombi.Store.Context
SaveChanges();
}
var manageOwnRequestsRole = Roles.Where(x => x.Name == OmbiRoles.ManageOwnRequests);
if (!manageOwnRequestsRole.Any())
{
Roles.Add(new IdentityRole(OmbiRoles.ManageOwnRequests)
{
NormalizedName = OmbiRoles.ManageOwnRequests.ToUpper()
});
SaveChanges();
}
// Make sure we have the API User
var apiUserExists = Users.Any(x => x.UserName.Equals("Api", StringComparison.CurrentCultureIgnoreCase));
if (!apiUserExists)

@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Authorization;
using Ombi.Helpers;
namespace Ombi.Attributes
{
public class UserAttribute : AuthorizeAttribute
{
public UserAttribute()
{
Roles = "ManageOwnRequests";
}
}
}

@ -94,13 +94,13 @@
</a>
</li>
<li [routerLinkActive]="['active']" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<a href="#" id="userDropdown" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<i class="fa fa-user"></i>{{ 'NavigationBar.Welcome' | translate: {username: user.name} }}
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li [routerLinkActive]="['active']">
<a [routerLink]="['/usermanagement/updatedetails']">
<a id="updateUserDetails" [routerLink]="['/usermanagement/updatedetails']">
<i class="fa fa-key"></i>{{ 'NavigationBar.UpdateDetails' | translate }}</a>
</li>
<li [routerLinkActive]="['active']">

@ -186,7 +186,7 @@
</div>
<div *ngIf="isAdmin || isRequestUser(request)">
<form id="removeBtn" class="col-md-6">
<form id="removeBtn">
<button (click)="removeRequest(request)" style="text-align: right" class="btn btn-sm btn-danger-outline delete">
<i class="fa fa-minus"></i> {{ 'Requests.Remove' | translate }}
</button>

@ -31,7 +31,7 @@
</div>
</div>
<div>
<button type="submit" class="btn btn-primary-outline" [disabled]="form.invalid">Save</button>
<button type="submit" data-test="submitbtn" class="btn btn-primary-outline" [disabled]="form.invalid">Save</button>
</div>
</form>

@ -80,7 +80,7 @@
<div class="checkbox">
<input type="checkbox" [(ngModel)]="c.enabled" [value]="c.value" id="create{{c.value}}"
[attr.name]="'create' + c.value" ng-checked="c.enabled">
<label for="create{{c.value}}">{{c.value | humanize}}</label>
<label id="label{{c.value}}" for="create{{c.value}}">{{c.value | humanize}}</label>
</div>
</div>
@ -132,7 +132,7 @@
<label for="{{pref.agent}}" class="control-label">{{NotificationAgent[pref.agent]
| humanize}}</label>
<div>
<input type="text" [(ngModel)]="pref.value" class="form-control form-control-custom"
<input type="text" [attr.data-test]="NotificationAgent[pref.agent]" [(ngModel)]="pref.value" class="form-control form-control-custom"
name="{{pref.agent}}" value="{{pref?.value}}">
</div>
</div>
@ -213,7 +213,7 @@
<div class="col-md-12">
<button *ngIf="!edit" type="button" data-test="createuserbtn" class="btn btn-danger-outline" (click)="create()">Create</button>
<div *ngIf="edit">
<button type="button" class="btn btn-primary-outline" (click)="update()">Update</button>
<button type="button" data-test="updatebtn" class="btn btn-primary-outline" (click)="update()">Update</button>
<button type="button" data-test="deletebtn" class="btn btn-danger-outline" (click)="delete()">Delete</button>
<button type="button" style="float:right;" class="btn btn-info-outline" (click)="resetPassword()"
pTooltip="You need your SMTP settings setup">Send Reset Password Link</button>

@ -240,6 +240,7 @@ namespace Ombi.Controllers
await CreateRole(OmbiRoles.RequestTv);
await CreateRole(OmbiRoles.Disabled);
await CreateRole(OmbiRoles.ReceivesNewsletter);
await CreateRole(OmbiRoles.ManageOwnRequests);
}
private async Task CreateRole(string role)

@ -88,7 +88,7 @@ namespace Ombi.Controllers
/// <param name="requestId">The request identifier.</param>
/// <returns></returns>
[HttpDelete("{requestId:int}")]
[PowerUser]
[Authorize(Roles = "Admin,PowerUser,ManageOwnRequests")]
public async Task DeleteRequest(int requestId)
{
await _engine.RemoveAlbumRequest(requestId);

@ -95,7 +95,7 @@ namespace Ombi.Controllers
/// <param name="requestId">The request identifier.</param>
/// <returns></returns>
[HttpDelete("movie/{requestId:int}")]
[PowerUser]
[Authorize(Roles = "Admin,PowerUser,ManageOwnRequests")]
public async Task DeleteRequest(int requestId)
{
await MovieRequestEngine.RemoveMovieRequest(requestId);
@ -269,7 +269,7 @@ namespace Ombi.Controllers
/// <param name="requestId">The request identifier.</param>
/// <returns></returns>
[HttpDelete("tv/{requestId:int}")]
[PowerUser]
[Authorize(Roles = "Admin,PowerUser,ManageOwnRequests")]
public async Task DeleteTvRequest(int requestId)
{
await TvRequestEngine.RemoveTvRequest(requestId);
@ -380,7 +380,7 @@ namespace Ombi.Controllers
/// </summary>
/// <param name="requestId">The model.</param>
/// <returns></returns>
[PowerUser]
[Authorize(Roles = "Admin,PowerUser,ManageOwnRequests")]
[HttpDelete("tv/child/{requestId:int}")]
public async Task<bool> DeleteChildRequest(int requestId)
{

@ -8,6 +8,11 @@ describe('User Management Page', function () {
Enabled: "true",
}]);
cy.createUser('userToEdit', 'password', [{
value: "requestmovie",
Enabled: "true",
}]);
cy.visit('/usermanagement');
});
@ -86,20 +91,8 @@ describe('User Management Page', function () {
})
it.only('Creates user with request limits', function () {
cy.get('[data-test=adduserbtn').click();
cy.url().should('include', '/user');
// Setup the form
cy.get('#username').type("user2");
cy.get('#alias').type("alias2");
cy.get('#emailAddress').type("user2@emailaddress.com");
cy.get('#password').type("password");
cy.get('#confirmPass').type("password");
// setup the roles
cy.contains('Roles').click()
cy.get('#labelRequestMovie').click();
it('Add request limits to a user', function () {
cy.get('#edituserToEdit').click();
cy.contains('Request Limits').click();
cy.get('#movieRequestLimit').clear().type(2);
@ -107,17 +100,98 @@ describe('User Management Page', function () {
cy.get('#episodeRequestLimit').clear().type(4);
// submit user
cy.get('[data-test=createuserbtn]').click();
cy.get('[data-test=updatebtn]').click();
cy.verifyNotification('has been created successfully');
cy.verifyNotification('successfully');
// Verify that the limits are set
cy.get('#edituser2').click();
cy.get('#edituserToEdit').click();
cy.contains('Request Limits').click();
cy.get('#movieRequestLimit').should('eq', 2);
cy.get('#musicRequestLimit').should('eq', 3);
cy.get('#tvRequestLimit').should('eq', 4);
cy.get('#movieRequestLimit').should('have.attr', 'ng-reflect-model', '2')
cy.get('#musicRequestLimit').should('have.attr', 'ng-reflect-model', '3')
cy.get('#episodeRequestLimit').should('have.attr', 'ng-reflect-model', '4')
});
it('Add notification preferences to user', function () {
cy.get('#edituserToEdit').click();
cy.contains('Notification Preferences').click();
cy.get('[data-test=Discord]').clear().type("Discord");
cy.get('[data-test=Pushbullet]').clear().type("Pushbullet");
cy.get('[data-test=Pushover]').clear().type("Pushover");
cy.get('[data-test=Telegram]').clear().type("Telegram");
cy.get('[data-test=Slack]').clear().type("Slack");
cy.get('[data-test=Mattermost]').clear().type("Mattermost");
// submit user
cy.get('[data-test=updatebtn]').click();
cy.verifyNotification('successfully');
// Verify that the limits are set
cy.get('#edituserToEdit').click();
cy.contains('Notification Preferences').click();
cy.get('[data-test=Discord]').should('have.attr', 'ng-reflect-model', "Discord");
cy.get('[data-test=Pushbullet]').should('have.attr', 'ng-reflect-model', "Pushbullet");
cy.get('[data-test=Pushover]').should('have.attr', 'ng-reflect-model', "Pushover");
cy.get('[data-test=Telegram]').should('have.attr', 'ng-reflect-model', "Telegram");
cy.get('[data-test=Slack]').should('have.attr', 'ng-reflect-model', "Slack");
cy.get('[data-test=Mattermost]').should('have.attr', 'ng-reflect-model', "Mattermost");
});
it('Modify roles', function () {
cy.get('#edituserToEdit').click();
cy.contains('Roles').click();
cy.get('#labelRequestMovie').click();
cy.get('#labelRequestTv').click();
// submit user
cy.get('[data-test=updatebtn]').click();
cy.verifyNotification('successfully');
// Verify that the limits are set
cy.get('#edituserToEdit').click();
cy.contains('Roles').click();
cy.get('#createRequestMovie').should('have.attr', 'ng-reflect-model', 'true');
cy.get('#createRequestTv').should('have.attr', 'ng-reflect-model', 'true');
cy.get('#createDisabled').should('have.attr', 'ng-reflect-model', 'false');
});
it('Update local users info', function () {
cy.get('#userDropdown').click();
cy.get('#updateUserDetails').click();
cy.url().should('include','/updatedetails');
cy.get('#emailAddress').clear().type("user11@emailaddress.com");
cy.get('#currentPassword').type("password");
cy.get('[data-test=submitbtn]').click();
cy.verifyNotification('All of your details have now been updated');
});
it('Update local users info with bad password', function () {
cy.get('#userDropdown').click();
cy.get('#updateUserDetails').click();
cy.url().should('include','/updatedetails');
cy.get('#emailAddress').clear().type("user11@emailaddress.com");
cy.get('#currentPassword').type("password32113123123");
cy.get('[data-test=submitbtn]').click();
cy.verifyNotification('Your password is incorrect');
});

@ -56,4 +56,4 @@ Cypress.Commands.add('createUser', (username, password, claims) => {
Cypress.Commands.add('verifyNotification', (text) => {
cy.get('.ui-growl-title').should('be.visible');
cy.get('.ui-growl-title').next().contains(text)
})
});

@ -1,12 +0,0 @@
{
"compilerOptions": {
"allowJs": true,
"baseUrl": "../node_modules",
"types": [
"cypress"
]
},
"include": [
"**/*.*"
]
}

@ -2,6 +2,7 @@
"compilerOptions": {
"target": "es5",
"lib": [
"es2015",
"es2017",
"dom"
],
@ -27,6 +28,9 @@
}
]
},
"types": [
"cypress"
],
"include": [
"ClientApp/**/*",
"typings/**/*",

Loading…
Cancel
Save