Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/serialize-…
Browse files Browse the repository at this point in the history
…role
  • Loading branch information
bdmendes committed Jul 14, 2023
2 parents 768e445 + 0c670a9 commit e5213fe
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Website NIAEFEUP - BackEnd
[![codecov](https://codecov.io/gh/NIAEFEUP/website-niaefeup-backend/branch/develop/graph/badge.svg?token=4OPGXYESGP)](https://codecov.io/gh/NIAEFEUP/website-niaefeup-backend)

The online platform for NIAEFEUP.

Below, you can find a quickstart guide with development setup and project structure. For additional information about any implementation or usage details, please refer to our [Wiki Page](https://github.com/NIAEFEUP/website-niaefeup-backend/wiki).

## Development setup

### Prerequisites
Expand Down Expand Up @@ -73,7 +76,7 @@ Run the following command in your shell:
```


### API Documentation
## API Documentation
API documentation is generated through the use of the [Spring REST Docs API specification Integration (aka restdocs-api-spec)](https://github.com/ePages-de/restdocs-api-spec), a [Spring Rest Docs](https://spring.io/projects/spring-restdocs) extension that builds an [OpenAPI specification](https://www.openapis.org/) or a [Postman collection](https://learning.postman.com/docs/sending-requests/intro-to-collections/) from its description, included in the controller tests. To see examples of how to document the API, hop to one of the controller tests and read the [API documentation wiki page](https://github.com/NIAEFEUP/website-niaefeup-backend/wiki/API-documentation).

Find the current version of the API documentation [here](https://develop--niaefeup-backend-docs.netlify.app/).
Expand All @@ -94,16 +97,18 @@ Run the following command in your shell:
Find the OpenAPI specification and Postman collection under `docs/` after running the task.


## Project Details

### Project Structure
## Project Structure

- `src/main`
- `controller/` - Methods that register endpoints for the app
- `model/` - Database entity models (Spring Data JPA entities)
- `backend/` - Contains all the source code (excluding tests and resources)
- `config/` - Configuration classes used at boot
- `controller/` - Methods that register endpoints for the app
- `model/` - Database entity models (Spring Data JPA entities)
- `dto/` - Data Transfer Objects for creating and modifying entities
- `repository/` - Data access layer methods (Spring Data repositories)
- `service/` - Business logic for the controllers
- `annotations/` - Custom annotations used in the project
- `validation/` - Custom validations used across the different models
- `repository/` - Data access layer methods (Spring Data repositories)
- `service/` - Business logic for the controllers
- `utils/` - Auxiliary packages used in the project
- `extensions/` - [Extension functions](https://kotlinlang.org/docs/extensions.html) used throughout the project
- `validation/` - Custom validations used across the different models
- `resources/` - All assets and static files needed, including static configurations
- `src/test/` - Self explanatory: unit tests, functional (end-to-end) tests, etc.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Account(
@OneToMany(cascade = [CascadeType.ALL], fetch = FetchType.EAGER)
val websites: List<@Valid CustomWebsite> = emptyList(),

@ManyToMany(cascade = [CascadeType.ALL], fetch = FetchType.EAGER)
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable
@OrderColumn
@JsonIgnore // TODO: Decide if we want to return roles (or IDs) by default
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/pt/up/fe/ni/website/backend/model/Role.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonBackReference
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonManagedReference
import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.persistence.CascadeType
import jakarta.persistence.Convert
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
Expand Down Expand Up @@ -41,7 +42,7 @@ class Role(
@GeneratedValue
val id: Long? = null
) {
@OneToMany(mappedBy = "role")
@OneToMany(cascade = [CascadeType.ALL], fetch = FetchType.EAGER, mappedBy = "role")
@JsonManagedReference
val associatedActivities: MutableList<@Valid PerActivityRole> = mutableListOf()

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ server.error.whitelabel.enabled=false
spring.jackson.default-property-inclusion=non_null
spring.jackson.deserialization.fail-on-null-creator-properties=true
spring.jackson.date-format=dd-MM-yyyy
spring.jackson.time-zone=Europe/Lisbon

# Auth Config
auth.private-key=classpath:certs/private.pem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ class AuthControllerTest @Autowired constructor(
),
mutableListOf()
)
private val testPermissions = listOf(Permission.CREATE_ACCOUNT, Permission.CREATE_ACTIVITY)
private val testRole = Role("MEMBER", Permissions(testPermissions), false)
private val testPerActivityRole = PerActivityRole(Permissions(listOf(Permission.EDIT_ACTIVITY)))
private val testActivity = Project("Test Activity", "Test Description", mutableListOf(), mutableListOf())

private val checkAuthHeaders = listOf<HeaderDescriptorWithType>(
headerWithName(HttpHeaders.AUTHORIZATION).description("Bearer authentication token")
Expand Down Expand Up @@ -241,15 +237,25 @@ class AuthControllerTest @Autowired constructor(
@NestedTest
@DisplayName("POST /auth/hasPermission")
inner class CheckPermissions {
private val testPermissions = listOf(Permission.CREATE_ACCOUNT, Permission.CREATE_ACTIVITY)
private val testActivity = Project("Test Activity", "Test Description", mutableListOf(), mutableListOf())
private val testRole = Role("MEMBER", Permissions(testPermissions), false)
private val testPerActivityRole = PerActivityRole(Permissions(listOf(Permission.EDIT_ACTIVITY)))

init {
testPerActivityRole.activity = testActivity
testPerActivityRole.role = testRole
}

@BeforeEach
fun setup() {
activityRepository.save(testActivity)
roleRepository.save(testRole)

testPerActivityRole.activity = testActivity
testPerActivityRole.role = testRole
perActivityRoleRepository.save(testPerActivityRole)

testRole.associatedActivities.add(testPerActivityRole)
roleRepository.save(testRole)

testAccount.roles.add(testRole)
repository.save(testAccount)
}
Expand Down Expand Up @@ -329,7 +335,9 @@ class AuthControllerTest @Autowired constructor(
val accessToken = objectMapper.readTree(response.contentAsString)["access_token"].asText()
mockMvc.perform(
get(
"/auth/hasPermission/${testActivity.id}/${Permission.EDIT_ACTIVITY}"
"/auth/hasPermission/{activityId}/{permission}",
testActivity.id,
Permission.EDIT_ACTIVITY
).header("Authorization", "Bearer $accessToken")
).andExpect(status().isOk).andDocument(
documentation,
Expand Down

0 comments on commit e5213fe

Please sign in to comment.