Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/0.8.0 #300

Merged
merged 180 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
7dc71e2
instantiated controller, model, repo and service for handling files.
niraymak Sep 14, 2020
4ba099f
initialized repo, service, model and controller for handling files
niraymak Sep 14, 2020
feddbe0
changed file model. Added get all files endpoint and upload single fi…
niraymak Sep 16, 2020
579111d
Added endpoint for uploading project images. Added FileUploader exten…
niraymak Sep 17, 2020
27e78e6
CreateProject now also accepts reference to File(project icon)
niraymak Sep 18, 2020
c405ff0
Created linking UserProject table
MeesvanStraten Sep 18, 2020
c06d9c2
Added an userproject migration
Sep 18, 2020
f3a8d02
fixed and issue where fileuploader did not upload file
niraymak Sep 21, 2020
7d2ca19
added summary to methods in fileuploader
niraymak Sep 21, 2020
55ffef2
changed postman environment and added postman tests
niraymak Sep 21, 2020
5fc22ca
updated changelog
niraymak Sep 21, 2020
be1421f
Created UserFollowedProjects model & included it in User model en Use…
Sep 22, 2020
81a1ad0
Added modelbinding, fileuploader checks if file exists already, postm…
niraymak Sep 22, 2020
af5344f
GetProject endpoints now also return project icon
niraymak Sep 23, 2020
a8ad52a
Created mapping for returning user followed projects.
Sep 24, 2020
d454f99
Created repository/controller/service for following projects
DaveBouman Sep 24, 2020
2ea8500
Added UserFollowedProject service, added end point to follow new proj…
Sep 24, 2020
3d40d83
Injected IUserFollowedProjects in startup.cs
Sep 24, 2020
828e142
Added UserFollowedProjectRepository to DI system
Sep 24, 2020
16ea14e
added IRepo props to service
Sep 24, 2020
a8b4e77
Merge branch 'feature/228-follow-users-projects' of https://github.co…
MeesvanStraten Sep 25, 2020
3f8359a
Renamed UserFollowedProject to UserProject
MeesvanStraten Sep 25, 2020
488a682
fixed an issue where updating project did not update the ProjectIcon …
niraymak Sep 25, 2020
9960179
file is now renamed (filename + upload datetime) before uploading to …
niraymak Sep 25, 2020
e51aaee
error handing for following user/project
DaveBouman Sep 28, 2020
b236f49
Added method to check if user already follows a given project
MeesvanStraten Sep 28, 2020
602f4c0
Needs work but function to unfollow project
MeesvanStraten Sep 28, 2020
eed48ab
added authorization
niraymak Sep 29, 2020
b6db6ab
added more assertions in tests and changed authorization for filecont…
niraymak Sep 29, 2020
1ed82c1
Change to delete entire row instead of ProjectId on table
Sep 29, 2020
bba83a0
Function to follow projects and unfollow project works, also some cle…
Sep 29, 2020
de8b4dd
Dropped table UserFolledProjects
Sep 29, 2020
7b7290c
Models,resources,repository for UserUser linking table
Sep 30, 2020
543456d
Changed end points in user controller for following users or projects
Sep 30, 2020
8a0d8f2
added attributes for validation of file extension and max file size t…
niraymak Sep 30, 2020
cfa3e2f
Merge branch 'develop' into feature/217-project-icon
Brend-Smits Oct 5, 2020
965eeda
added public resources folder
niraymak Oct 5, 2020
a2d8a48
Merge branch 'feature/217-project-icon' of https://github.com/Digital…
niraymak Oct 5, 2020
66ade0c
Update dex.postman_collection.json
Oct 6, 2020
aff57fe
Update CHANGELOG.md
Oct 6, 2020
faa0081
changed .gitignore. changed attributes for fileuploading. changed tes…
niraymak Oct 6, 2020
4e2fb88
changed Resource results for userUser and UserProject
Oct 7, 2020
91b0a2b
Fixes regarding feedback on PR
Oct 7, 2020
4028297
added .sh file to run tests. Added comments at fileservice and -repo.
niraymak Oct 7, 2020
fb0f497
stage postman environment
niraymak Oct 7, 2020
1105ff5
added variables for file testing in postman
niraymak Oct 7, 2020
ae58fc4
removed fileserver rule as it was not necessary.
niraymak Oct 7, 2020
b0256c7
Added new RoleScope for FileWriting
niraymak Oct 7, 2020
331593d
added tests files. Removed redundant methods in fileservice and -repo.
niraymak Oct 8, 2020
961b731
Added postman tests for following project and following users
Oct 8, 2020
60a3ba8
Check so that user can not follow his self
Oct 8, 2020
61d5210
Test for following projects and users PR level
Oct 9, 2020
9f063e8
FIx for userproject
Oct 9, 2020
b1ab71e
refactored fileuploader and added tests for fileuploading
niraymak Oct 9, 2020
52a1c64
rename FileUploader methods
niraymak Oct 9, 2020
8e91b1b
rename FileUploader methods
niraymak Oct 9, 2020
d439a28
updated typo and mapped File to FileResource
niraymak Oct 12, 2020
8e82535
Removed some old migrations and added a single new migration for this…
Brend-Smits Oct 14, 2020
d452617
Merge branch 'develop' into feature/228-follow-users-projects
Oct 14, 2020
2c3288d
Merge branch 'feature/228-follow-users-projects' of https://github.co…
Oct 14, 2020
6b8f264
merge
niraymak Oct 15, 2020
023aaf3
adjustments made relevant for merge
niraymak Oct 15, 2020
a0dda57
changed changelog
niraymak Oct 15, 2020
9c9cd1b
Move startup.cs UseStaticFiles to the correct location.
Brend-Smits Oct 16, 2020
78855e8
Clean up migrations and make UploaderId required
Brend-Smits Oct 16, 2020
68e27a4
Show UploaderId in FileResourceResult
Brend-Smits Oct 16, 2020
f5c0a3b
Small update to controller documentation
Brend-Smits Oct 16, 2020
b17fe01
Merge branch 'develop' into feature/217-project-icon
Brend-Smits Oct 16, 2020
168306b
Fix changelog
Brend-Smits Oct 16, 2020
bed0d77
Merge branch 'develop' into feature/228-follow-users-projects
niraymak Oct 16, 2020
b018704
Merge remote-tracking branch 'origin/feature/228-follow-users-project…
niraymak Oct 16, 2020
f879bde
Updated project highlight resource result
RubenFricke Oct 16, 2020
6828b41
Merge branch 'feature/217-project-icon' of https://github.com/Digital…
RubenFricke Oct 16, 2020
185dce7
Updated highlight repository to include project icon
RubenFricke Oct 16, 2020
d109b15
Revert "Merge remote-tracking branch 'origin/feature/228-follow-users…
niraymak Oct 16, 2020
16fb18a
Added institution to the models
RubenFricke Oct 26, 2020
14445c1
Created new migration for updated models (institution)
RubenFricke Oct 26, 2020
84c26ae
Updated migration and model
RubenFricke Oct 26, 2020
6d4b467
Added DBSet for institution model
RubenFricke Oct 26, 2020
80ab7ea
Added first version of the data officer role
RubenFricke Oct 26, 2020
05286f8
Added licence text
RubenFricke Oct 26, 2020
abe06f4
Merge branch 'develop' into feature/217-project-icon
Brend-Smits Oct 26, 2020
a8a0797
Added Id's to UserProject resource so Postman can do testing on Id's …
Oct 26, 2020
8cd8ab2
Added new postman tests to test following users and projects. Testing…
Oct 26, 2020
da940cf
Update ProjectController.cs
Oct 26, 2020
3312cb5
Merge branch 'develop' into feature/228-follow-users-projects
Brend-Smits Oct 26, 2020
1dd5bf4
Created first version for the controller implementation
RubenFricke Oct 26, 2020
1608815
Created first version of for the controller implementation for the De…
RubenFricke Oct 26, 2020
74944ac
fixed some tests regarding following users and projects
Oct 26, 2020
988bc50
Merge branch 'feature/228-follow-users-projects' of https://github.co…
Oct 26, 2020
38b2565
Updated DeleteAccount method
RubenFricke Oct 26, 2020
c373592
Updated identity id
RubenFricke Oct 28, 2020
442e24e
Added licence
RubenFricke Oct 28, 2020
f626b0e
Extended to all personal data
RubenFricke Oct 28, 2020
603c371
Updated role with new rolescopes
RubenFricke Oct 28, 2020
297cd2e
Return forbid instead of unauthorized for wrong scope
RubenFricke Oct 28, 2020
1108a4f
Same institution doesn't mean both null
RubenFricke Oct 29, 2020
8cb8930
Added basic authorization helper to implement DRY principles better
RubenFricke Oct 29, 2020
2b43f4c
Updated warning to avoid var for OpenApiMediaType
RubenFricke Oct 29, 2020
1c66092
Added Authorization helper
RubenFricke Oct 29, 2020
e53c9a5
Added documentation for the authorization helper
RubenFricke Oct 29, 2020
e74a0cf
Added documentation in the controllers for the authorization helper
RubenFricke Oct 29, 2020
fdbce8f
Updated seed to add test Fontys institution
RubenFricke Oct 29, 2020
5dd18b4
Updated return type to show added institution
RubenFricke Oct 29, 2020
fef85f0
Created first version for the institution repository
RubenFricke Oct 29, 2020
fab170d
Updated user model to store institution id for adding an institution
RubenFricke Oct 29, 2020
37c55ef
Created first version for the institution service
RubenFricke Oct 29, 2020
ab61daf
Updated parameter documentation
RubenFricke Oct 29, 2020
35599d7
Added institution resource
RubenFricke Oct 29, 2020
58b18c9
Added institution resource result
RubenFricke Oct 29, 2020
d37baf4
Improve embed controller grammar documentation
RubenFricke Oct 29, 2020
4d6d911
Created institution controller
RubenFricke Oct 29, 2020
c428a0f
Added licence text for each service test
RubenFricke Oct 29, 2020
44aaeb0
Added licnece text to base service test class
RubenFricke Oct 29, 2020
0691206
Added licence text to repository test classes
RubenFricke Oct 29, 2020
baea206
Created Institution data generator
RubenFricke Oct 29, 2020
44d4e85
Added licence text to every data generator class
RubenFricke Oct 29, 2020
2b605a4
Created institution data source attribute
RubenFricke Oct 29, 2020
69fd599
Added licence text to each data source attribute class
RubenFricke Oct 29, 2020
84f1779
Created Institution Service test class
RubenFricke Oct 29, 2020
daa9854
Created unit tests for the institution repository
RubenFricke Oct 29, 2020
f5a6448
Updated scope names for data officer
RubenFricke Oct 29, 2020
d4b47cb
Updated aministrator role scopes (added institution scopes)
RubenFricke Oct 29, 2020
1921484
Implemented new scope names in the controllers
RubenFricke Oct 30, 2020
214668d
Added institution service and repository in di-setup
RubenFricke Oct 30, 2020
1c055d5
Added policies in the startup config
RubenFricke Oct 30, 2020
9d2cecc
Fixed DI bug for retrieving IInstitutionRepository in the service
RubenFricke Oct 30, 2020
9dd1370
Added mapping profile for institution models
RubenFricke Oct 30, 2020
806ef9c
finished postman testing
niraymak Oct 30, 2020
012a036
Merge branch 'develop' into feature/228-follow-users-projects
niraymak Oct 30, 2020
827728f
refactored requested summary changes
niraymak Oct 30, 2020
e026f1b
Merge branch 'develop' into feature/217-project-icon
niraymak Oct 30, 2020
b5b91e2
Improved seeding of data
RubenFricke Oct 31, 2020
f0f2d07
Updated data officer permissions
RubenFricke Oct 31, 2020
50bda2f
Added institution id to developer seed account
RubenFricke Oct 31, 2020
c9bfe84
Updated postman environment
RubenFricke Oct 31, 2020
a12c18a
Added check for institution id when creating user
RubenFricke Oct 31, 2020
8a6ab89
Added documentation for the institution service in the constructor
RubenFricke Oct 31, 2020
06a6bce
Added institution id check for httpput
RubenFricke Oct 31, 2020
3ecc604
Updated Seed.cs documentation
RubenFricke Oct 31, 2020
7f68078
Created postman tests
RubenFricke Oct 31, 2020
64a2281
Added identity user
RubenFricke Oct 31, 2020
0b6e7a2
Update CHANGELOG.md
RubenFricke Oct 31, 2020
74b4dd0
Improve spelling
RubenFricke Oct 31, 2020
3b549ed
Merge branch 'develop' into feature/265-data-officer-role
RubenFricke Oct 31, 2020
5cbe5a2
Merge branch 'feature/265-data-officer-role' of https://github.com/Di…
RubenFricke Oct 31, 2020
2e43628
Fixed merge conflict resolve error
RubenFricke Oct 31, 2020
c72c952
Resolve identity server startup bug
RubenFricke Oct 31, 2020
22279f4
Updated role service test to succeed
RubenFricke Oct 31, 2020
959748b
Set initial value for institutionIdFromUser variable
RubenFricke Oct 31, 2020
a4824f9
Set init values for variables in environment
RubenFricke Oct 31, 2020
aa1fb37
changed testimage path
niraymak Nov 3, 2020
756ebf5
changed Postman collection testimage path
niraymak Nov 3, 2020
ff5b076
Fixed path in postman collection
niraymak Nov 3, 2020
2064667
changed testimage to remote testimage.
niraymak Nov 3, 2020
4e15bbc
refactor in fileuploader for docker enviroment
niraymak Nov 3, 2020
be1ce1a
refactor path in postman collection
niraymak Nov 3, 2020
4f7f28a
fixed an error for uploading files in docker environment
niraymak Nov 3, 2020
2c40afc
Merge pull request #241 from DigitalExcellence/feature/217-project-icon
niraymak Nov 3, 2020
0e0db30
Resolved Niray's feedback
RubenFricke Nov 3, 2020
aa39bfc
Merge branch 'develop' into feature/265-data-officer-role
RubenFricke Nov 4, 2020
340e8b8
Merge branch 'develop' into feature/265-data-officer-role
RubenFricke Nov 4, 2020
6a3ecc5
refactor after merge errors
niraymak Nov 4, 2020
0adb68b
removed FileWrite from DataOfficer role
niraymak Nov 4, 2020
f7804f9
Resolved Brend's feedback for merging
RubenFricke Nov 4, 2020
e24e252
Merge pull request #293 from DigitalExcellence/feature/265-data-offic…
RubenFricke Nov 4, 2020
bad3faa
merge develop into follow user projects
niraymak Nov 4, 2020
aae8da6
fixed summaries for controllers
niraymak Nov 4, 2020
5d218e9
Postman fix
niraymak Nov 4, 2020
a0caa13
Merge pull request #258 from DigitalExcellence/feature/228-follow-use…
MeesvanStraten Nov 4, 2020
ecfb266
Highlight Resource Result was missing the start & end date
Brend-Smits Nov 5, 2020
20eef0f
Updated Changelog
Brend-Smits Nov 5, 2020
a379f42
Merge pull request #297 from DigitalExcellence/bugfix/highlightResult…
Brend-Smits Nov 5, 2020
7aeae11
potential fix for project icon path
niraymak Nov 6, 2020
4b9cf41
Fix issue where all static resources from API (wwwroot) were not copi…
niraymak Nov 6, 2020
240b311
changed FilePathRoot so it should work in Docker environment
niraymak Nov 6, 2020
f17fcc5
changed image upload directory.
niraymak Nov 6, 2020
fe9f3cf
Update .gitignore and add .gitkeep
Brend-Smits Nov 6, 2020
2a24c70
Updated Changelog for v0.8.0
Brend-Smits Nov 6, 2020
75d3852
Update workflow file to only trigger on develop
Brend-Smits Nov 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/staging-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
docker-compose down
docker-compose pull
sleep 10s
docker-compose up -d
docker-compose up -d
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,6 @@ profile


IdentityServer/tempkey.rsa

/API/Uploads/Images/*
!/API/Uploads/Images/.gitkeep
10 changes: 9 additions & 1 deletion API/1_API.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
Expand All @@ -15,6 +15,14 @@
<None Remove="Resources\Project\**" />
</ItemGroup>

<ItemGroup>
<None Remove="Uploads\Images\.gitkeep" />
</ItemGroup>

<ItemGroup>
<Content Include="Uploads\Images\.gitkeep" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="8.6.2" />
Expand Down
65 changes: 65 additions & 0 deletions API/Common/AuthorizationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Digital Excellence Copyright (C) 2020 Brend Smits
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You can find a copy of the GNU Lesser General Public License
* along with this program, in the LICENSE.md file in the root project directory.
* If not, see https://www.gnu.org/licenses/lgpl-3.0.txt
*/

using Models;
using Services.Services;
using System.Threading.Tasks;

namespace API.Common
{
/// <summary>
/// The implementation for the authorization helper.
/// </summary>
public class AuthorizationHelper : IAuthorizationHelper
{

private readonly IUserService userService;

/// <summary>
/// Initializes a new instance of the <see cref="AuthorizationHelper"/> class.
/// </summary>
/// <param name="userService">The user service for communicating with the logic layer.</param>
public AuthorizationHelper(IUserService userService)
{
this.userService = userService;
}

/// <summary>
/// This method checks if a user has the correct scope to use the endpoint.
/// This method checks for a normal scope and the data officer scope within the
/// same institution.
/// </summary>
/// <param name="loggedInUser">The user model of the logged in user.</param>
/// <param name="scope">The required scope for accessing this endpoint.</param>
/// <param name="dataOfficerScope">The required scope for accessing this
/// endpoint for data officers within the same institution.</param>
/// <param name="propertyOfUserId">The id of the user owner of the property
/// which the logged in user wants to access.</param>
/// <returns>bool: true if the user is allowed, false if the user is not allowed.</returns>
public async Task<bool> UserIsAllowed(User loggedInUser, string scope, string dataOfficerScope, int propertyOfUserId)
{
bool hasUserWriteScope = userService.UserHasScope(loggedInUser.IdentityId, scope);
bool hasCorrectDataOfficerRights =
userService.UserHasScope(loggedInUser.IdentityId, dataOfficerScope) &&
await userService.HasSameInstitution(loggedInUser.Id, propertyOfUserId);
bool isAllowed = hasUserWriteScope || hasCorrectDataOfficerRights;
return isAllowed;
}

}

}
47 changes: 47 additions & 0 deletions API/Common/IAuthorizationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Digital Excellence Copyright (C) 2020 Brend Smits
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You can find a copy of the GNU Lesser General Public License
* along with this program, in the LICENSE.md file in the root project directory.
* If not, see https://www.gnu.org/licenses/lgpl-3.0.txt
*/

using Models;
using System.Threading.Tasks;

namespace API.Common
{
/// <summary>
/// The interface for the authorization helper
/// </summary>
public interface IAuthorizationHelper
{
/// <summary>
/// This method checks if a user has the correct scope to use the endpoint.
/// This method checks for a normal scope and the data officer scope within the
/// same institution.
/// </summary>
/// <param name="loggedInUser">The user model of the logged in user.</param>
/// <param name="scope">The required scope for accessing this endpoint.</param>
/// <param name="dataOfficerScope">The required scope for accessing this
/// endpoint for data officers within the same institution.</param>
/// <param name="propertyOfUserId">The id of the user owner of the property
/// which the logged in user wants to access.</param>
/// <returns>bool: true if the user is allowed, false if the user is not allowed.</returns>
public Task<bool> UserIsAllowed(User loggedInUser,
string scope,
string dataOfficerScope,
int propertyOfUserId);

}

}
27 changes: 26 additions & 1 deletion API/Configuration/MappingProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,26 @@ public class MappingProfile : Profile
/// </summary>
public MappingProfile()
{
CreateMap<UserResource, User>();
CreateMap<UserUserResourceResult, UserUser>();

CreateMap<UserUser, UserUserResourceResult>()
.ForMember(q => q.Id, opt => opt.MapFrom(q => q.FollowedUser.Id))
.ForMember(q => q.Name, opt => opt.MapFrom(q => q.FollowedUser.Name))
.ForAllOtherMembers(o => o.Ignore());

CreateMap<UserProject, UserProjectResourceResult>()
.ForMember(q => q.Id, opt => opt.MapFrom(p => p.Project.Id))
.ForMember(q => q.Name, opt => opt.MapFrom(p => p.Project.Name))
.ForMember(q => q.ShortDescription, opt => opt.MapFrom(p => p.Project.ShortDescription))
.ForMember(q => q.Uri, opt => opt.MapFrom(p => p.Project.Uri))
.ForMember(q => q.Description, opt => opt.MapFrom(p => p.Project.Description))
.ForAllOtherMembers(o => o.Ignore());


CreateMap<User, UserResourceResult>();

CreateMap<UserResource, User>();

CreateMap<User, LimitedUserResourceResult>();

CreateMap<ProjectResource, Project>();
Expand All @@ -57,8 +75,15 @@ public MappingProfile()
CreateMap<EmbeddedProjectResource, EmbeddedProject>();
CreateMap<EmbeddedProject, EmbeddedProjectResourceResult>();

CreateMap<FileResourceResult, File>();
CreateMap<File, FileResourceResult>().ForMember(e => e.UploaderUserId,
opt => opt.MapFrom(e => e.Uploader.Id));

CreateMap<RoleScopeResource, RoleScope>();
CreateMap<RoleScope, RoleScopeResource>();

CreateMap<InstitutionResource, Institution>();
CreateMap<Institution, InstitutionResourceResult>();
}
}
}
22 changes: 16 additions & 6 deletions API/Controllers/EmbedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* If not, see https://www.gnu.org/licenses/lgpl-3.0.txt
*/

using API.Common;
using API.Extensions;
using API.Resources;
using AutoMapper;
Expand All @@ -27,9 +28,7 @@
using Services.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace API.Controllers
Expand All @@ -47,6 +46,7 @@ public class EmbedController : ControllerBase
private readonly IMapper mapper;
private readonly IProjectService projectService;
private readonly IUserService userService;
private readonly IAuthorizationHelper authorizationHelper;

/// <summary>
/// Initializes a new instance of the <see cref="EmbedController"/> class
Expand All @@ -55,12 +55,18 @@ public class EmbedController : ControllerBase
/// <param name="mapper">The mapper which is used to convert the resources to the models to the resource results.</param>
/// <param name="projectService">The project service which is used to communicate with the logic layer.</param>
/// <param name="userService">The user service which is used to communicate with the logic layer.</param>
public EmbedController(IEmbedService embedService, IMapper mapper, IProjectService projectService, IUserService userService)
/// <param name="authorizationHelper">The authorization helper which is used to communicate with the authorization helper class.</param>
public EmbedController(IEmbedService embedService,
IMapper mapper,
IProjectService projectService,
IUserService userService,
IAuthorizationHelper authorizationHelper)
{
this.embedService = embedService;
this.mapper = mapper;
this.projectService = projectService;
this.userService = userService;
this.authorizationHelper = authorizationHelper;
}

/// <summary>
Expand All @@ -83,7 +89,7 @@ public async Task<IActionResult> GetAllEmbeddedProjects()
/// </summary>
/// <param name="guid">The unique identifier which is used for searching the embedded project.</param>
/// <returns>This method returns the project resource result.</returns>
/// <response code="200">This endpoint returns a embedded project with the specified guid.</response>
/// <response code="200">This endpoint returns an embedded project with the specified guid.</response>
/// <response code="400">The 400 Bad Request status code is returned when the guid is not specified.</response>
/// <response code="404">The 404 Not Found status code is returned when no project could be
/// found with the specified guid.</response>
Expand Down Expand Up @@ -179,8 +185,8 @@ public async Task<IActionResult> CreateEmbeddedProject(EmbeddedProjectResource e
}

string identity = HttpContext.User.GetIdentityId(HttpContext);
bool isAllowed = userService.UserHasScope(identity, nameof(Defaults.Scopes.EmbedWrite));
User user = await userService.GetUserByIdentityIdAsync(identity);
bool isAllowed = userService.UserHasScope(identity, nameof(Defaults.Scopes.EmbedWrite));

if(!(project.UserId == user.Id || isAllowed))
{
Expand Down Expand Up @@ -253,7 +259,11 @@ public async Task<IActionResult> DeleteEmbeddedProject(string guid)
}

string identity = HttpContext.User.GetIdentityId(HttpContext);
bool isAllowed = userService.UserHasScope(identity, nameof(Defaults.Scopes.EmbedWrite));
User user = await userService.GetUserByIdentityIdAsync(identity);
bool isAllowed = await authorizationHelper.UserIsAllowed(user,
nameof(Defaults.Scopes.EmbedWrite),
nameof(Defaults.Scopes.InstitutionEmbedWrite),
embeddedProject.UserId);

if(!(embeddedProject.User.IdentityId == identity || isAllowed))
{
Expand Down
Loading