Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit de286f9

Browse files
FF-218 Show Folder Contents API (#53)
* WIP FF-218 Write Code for ShowContents * Added UserBusinessService.userWithUsernameDoesExist * Renamed dto to DTO, removed PermissionSets from FileSystemItems. * FF-218 Added main functions. * Added defaults to builder classes. * FF-218 Added FileSystemBusinessService.userIsAllowedToSeeFileSystemEntity * commented out tests. * Works but i need to rework the dto structure * FF-218 Should work now. Needs testing. * Fixed Merge Import Problems * Fixed Merge Annotation Problem * Added missing @DaTa * Added missing @builder * Added missing DummyFile. * Added Cors for local dev purposes only. * Cleanup * Added more @Builder.default * Fixed Test, Wrote UnitTests (1/2) * Fixed Test, Wrote UnitTests (2/2) * Added createBasicFilesForNewUser * Updated Sonar Hostname * Implemented Changes requested by @qvalentin * Ignored Stupid CodeSmells * Added TotalFileSize To SystemHealth * Sonar needs to access over https * added import of ssl cert for reaching sonar * also trigger workflow when workflow config is changed * bad echo? * changed passowrd * changed passowrd * use default password * why did i take the password 'changeit' literally * debug * remove debug * added SONAR_SCANNER_OPTS * ups wrong repo * trying https * everything https * made it use http for the links * added test image * undo changes * Refactored Steps and Feature File. * no https for badges images * Added same scenario but with groups * Added Steps, Fixed the feature. * Small fixes. * Fixed Tests * Bumped Up Version to -> 0.0.6 * added .run to gitingore * Revert Changes, set default profile to "test" while running tests, added stage spring profile Co-authored-by: qvalentin <[email protected]>
1 parent 21fe4b3 commit de286f9

File tree

49 files changed

+825
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+825
-412
lines changed

.github/workflows/tests.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
paths:
77
- 'src/**'
88
- 'pom.xml'
9+
- '.github/workflows/tests.yml'
910

1011
jobs:
1112
Run_all_tests:
@@ -25,8 +26,13 @@ jobs:
2526
docker create -p 27017:27017 --name FileFighterDB mongo:latest
2627
docker start FileFighterDB
2728
-
28-
name: Run Tests and update Sonar
29-
run: mvn clean verify sonar:sonar -s ./settings.xml
29+
name: Run Tests and update Sonar (import cert first)
30+
run: |
31+
echo "${{ secrets.SSL_CERT }}" > filefighter.de_ssl_certificate.cer
32+
yes yes | keytool -import -alias filefighterde -file filefighter.de_ssl_certificate.cer -storetype JKS -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit
33+
mvn clean verify sonar:sonar -s ./settings.xml
34+
rm filefighter.de_ssl_certificate.cer
35+
keytool -delete -alias filefighterde -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit
3036
env:
3137
SONAR_LOGIN: ${{ secrets.SONAR_LOGIN }}
3238
SONAR_PASSWORD: ${{ secrets.SONAR_PASSWORD }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ build/
3030
!**/src/test/**/build/
3131

3232
### VS Code ###
33-
.vscode/
33+
.vscode/

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# RestApi
2-
Backend REST API for FileFighter </br>
2+
Backend REST API for FileFighter
33
![Docker Release](https://img.shields.io/github/v/release/filefighter/restapi?color=dark-green&label=Stable%20Version&logo=docker&style=for-the-badge)
4-
![Docker Pulls](https://img.shields.io/docker/pulls/filefighter/rest?logo=docker&style=for-the-badge)</br>
5-
[![Quality Gate Status](http://filefighter.ddns.net:9000/api/project_badges/measure?project=de.filefighter%3Arest&metric=alert_status)](http://filefighter.ddns.net:9000/dashboard?id=de.filefighter%3Arest)
6-
[![Coverage](http://filefighter.ddns.net:9000/api/project_badges/measure?project=de.filefighter%3Arest&metric=coverage)](http://filefighter.ddns.net:9000/dashboard?id=de.filefighter%3Arest)
7-
[![Lines of Code](http://filefighter.ddns.net:9000/api/project_badges/measure?project=de.filefighter%3Arest&metric=ncloc)](http://filefighter.ddns.net:9000/dashboard?id=de.filefighter%3Arest)
8-
[![Security Rating](http://filefighter.ddns.net:9000/api/project_badges/measure?project=de.filefighter%3Arest&metric=security_rating)](http://filefighter.ddns.net:9000/dashboard?id=de.filefighter%3Arest)</br>
4+
![Docker Pulls](https://img.shields.io/docker/pulls/filefighter/rest?logo=docker&style=for-the-badge)
5+
[![Quality Gate Status](http://sonar.filefighter.de/api/project_badges/measure?project=de.filefighter%3Arest&metric=alert_status)](https://sonar.filefighter.de/dashboard?id=de.filefighter%3Arest)
6+
[![Coverage](http://sonar.filefighter.de/api/project_badges/measure?project=de.filefighter%3Arest&metric=coverage)](https://sonar.filefighter.de/dashboard?id=de.filefighter%3Arest)
7+
[![Lines of Code](http://sonar.filefighter.de/api/project_badges/measure?project=de.filefighter%3Arest&metric=ncloc)](https://sonar.filefighter.de/dashboard?id=de.filefighter%3Arest)
8+
[![Security Rating](http://sonar.filefighter.de/api/project_badges/measure?project=de.filefighter%3Arest&metric=security_rating)](https://sonar.filefighter.de/dashboard?id=de.filefighter%3Arest)
99
![Latest Release](https://github.com/FileFighter/RestApi/workflows/Latest%20Release/badge.svg)
1010
![Stable Release](https://github.com/FileFighter/RestApi/workflows/Stable%20Release/badge.svg)
1111
![Tests](https://github.com/FileFighter/RestApi/workflows/Tests/badge.svg)

pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>de.filefighter</groupId>
1212
<artifactId>rest</artifactId>
13-
<version>0.0.5</version>
13+
<version>0.0.6</version>
1414
<name>RestApi</name>
1515
<description>RestApi for FileFighter</description>
1616

@@ -180,10 +180,8 @@
180180
</includes>
181181
<excludes>
182182
<!-- NOT IMPLEMENTED YET -->
183-
<!-- TODO: remove fs -->
184183
<exclude>*FileSystemRestService</exclude>
185184
<exclude>*PermissionRestService</exclude>
186-
<exclude>*FileSystemBusinessService</exclude>
187185
</excludes>
188186
<limits>
189187
<limit>

settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</activation>
1111
<properties>
1212
<sonar.host.url>
13-
http://filefighter.ddns.net:9000
13+
https://sonar.filefighter.de
1414
</sonar.host.url>
1515
<sonar.login>${env.SONAR_LOGIN}</sonar.login>
1616
<sonar.password>${env.SONAR_PASSWORD}</sonar.password>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package de.filefighter.rest.configuration;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.context.annotation.Profile;
6+
import org.springframework.web.cors.CorsConfiguration;
7+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
8+
import org.springframework.web.filter.CorsFilter;
9+
10+
import java.util.ArrayList;
11+
12+
@Configuration
13+
public class CorsConfig {
14+
15+
@Bean
16+
@Profile({"dev","stage"})
17+
public CorsFilter corsFilter() {
18+
final CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues();
19+
ArrayList<String> allowedOrigins = new ArrayList<>();
20+
allowedOrigins.add("*");
21+
config.setAllowedOrigins(allowedOrigins);
22+
23+
ArrayList<String> allowedMethods = new ArrayList<>();
24+
allowedMethods.add("HEAD");
25+
allowedMethods.add("GET");
26+
allowedMethods.add("POST");
27+
allowedMethods.add("PUT");
28+
allowedMethods.add("DELETE");
29+
allowedMethods.add("OPTIONS");
30+
config.setAllowedMethods(allowedMethods);
31+
32+
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
33+
source.registerCorsConfiguration("/**", config);
34+
return new CorsFilter(source);
35+
}
36+
}

src/main/java/de/filefighter/rest/configuration/PrepareDataBase.java

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
@Configuration
2222
public class PrepareDataBase {
2323

24-
private static final String MESSAGE_ON_SUCCESS = " was successful.";
25-
private static final String MESSAGE_ON_FAILURE = " failed.";
24+
private static final String MESSAGE_ON_SUCCESS = "was successful.";
25+
private static final String MESSAGE_ON_FAILURE = "failed.";
2626

2727
@Value("${server.port}")
2828
int serverPort;
@@ -32,25 +32,26 @@ public class PrepareDataBase {
3232

3333
@Value("${filefighter.date}")
3434
String date;
35-
35+
36+
@SuppressWarnings("squid:S106")
3637
@Bean
3738
@Profile({"dev", "prod"})
3839
CommandLineRunner veryImportantFileFighterStartScript() {
3940
return args -> {
4041
System.out.println();
4142
System.out.println("-------------------------------< REST API >-------------------------------");
4243
System.out.println();
43-
System.out.println(" _____ _ _ _____ _ _ _ ");
44-
System.out.println(" | ___| (_) | | ___ | ___| (_) __ _ | |__ | |_ ___ _ __ ");
44+
System.out.println(" _____ _ _ _____ _ _ _");
45+
System.out.println(" | ___| (_) | | ___ | ___| (_) __ _ | |__ | |_ ___ _ __");
4546
System.out.println(" | |_ | | | | / _ \\ | |_ | | / _ | | '_ \\ | __| / _ \\ | '__|");
46-
System.out.println(" | _| | | | | | __/ | _| | | | (_| | | | | | | |_ | __/ | | ");
47-
System.out.println(" |_| |_| |_| \\___| |_| |_| \\__, | |_| |_| \\__| \\___| |_| ");
48-
System.out.println(" |___/ ");
49-
System.out.println(" Version v" + version + " Last updated at " + date + " ");
50-
System.out.println(" Developed by Gimleux, Valentin, Open-Schnick. ");
51-
System.out.println(" Development Blog: https://filefighter.github.io ");
52-
System.out.println(" The code can be found at: https://www.github.com/filefighter ");
53-
System.out.println(" Running on http://localhost:" + serverPort);
47+
System.out.println(" | _| | | | | | __/ | _| | | | (_| | | | | | | |_ | __/ | |");
48+
System.out.println(" |_| |_| |_| \\___| |_| |_| \\__, | |_| |_| \\__| \\___| |_|");
49+
System.out.println(" |___/");
50+
System.out.println(" Version v" + version + " Last updated at " + date + "");
51+
System.out.println(" Developed by Gimleux, Valentin, Open-Schnick.");
52+
System.out.println(" Development Blog: https://blog.filefighter.de");
53+
System.out.println(" The code can be found at: https://www.github.com/filefighter");
54+
System.out.println(" Running on http://localhost:" + serverPort);
5455
System.out.println();
5556
System.out.println("-------------------------------< REST API >-------------------------------");
5657
System.out.println();
@@ -83,19 +84,31 @@ CommandLineRunner initDataBaseProd(UserRepository userRepository, FileSystemRepo
8384
.groupIds(new long[]{0, 1})
8485
.build()));
8586

86-
log.info("Preloading default fsStructure: {}.", fileSystemRepository.save(FileSystemEntity
87-
.builder()
88-
.createdByUserId(0)
89-
.fileSystemId(0)
90-
.isFile(false)
91-
.path("/")
92-
.itemIds(new long[0])
93-
.lastUpdated(Instant.now().getEpochSecond())
94-
.name("root")
95-
.size(0)
96-
.typeId(FileSystemType.FOLDER.getId())
97-
.visibleForGroupIds(new long[]{-1, 0, 1})
98-
.build()));
87+
log.info("Preloading default fsStructure: {} {}.", fileSystemRepository.save(FileSystemEntity
88+
.builder()
89+
.createdByUserId(0)
90+
.fileSystemId(0)
91+
.isFile(false)
92+
.path("/")
93+
.itemIds(new long[0])
94+
.lastUpdated(Instant.now().getEpochSecond())
95+
.name("root")
96+
.size(0)
97+
.typeId(FileSystemType.FOLDER.getId())
98+
.visibleForGroupIds(new long[]{-1, 0, 1})
99+
.itemIds(new long[]{1})
100+
.build()),
101+
fileSystemRepository.save(FileSystemEntity.builder()
102+
.createdByUserId(0)
103+
.fileSystemId(1)
104+
.isFile(true)
105+
.lastUpdated(Instant.now().getEpochSecond())
106+
.name("dummyFile.txt")
107+
.size(420)
108+
.typeId(FileSystemType.TEXT.getId())
109+
.editableFoGroupIds(new long[]{0})
110+
.visibleForGroupIds(new long[]{0})
111+
.build()));
99112

100113
log.info("Inserting Users {}", (userRepository.findAll().size() == 1 ? MESSAGE_ON_SUCCESS : MESSAGE_ON_FAILURE));
101114
log.info("Inserting fsItems {}", (fileSystemRepository.findAll().size() == 1 ? MESSAGE_ON_SUCCESS : MESSAGE_ON_FAILURE));
@@ -123,7 +136,7 @@ CommandLineRunner initDataBaseDev(UserRepository userRepository, AccessTokenRepo
123136
.lowercaseUsername("user1")
124137
.password("12345")
125138
.refreshToken("rft")
126-
.groupIds(new long[]{-1})
139+
.groupIds(new long[]{0})
127140
.build()));
128141

129142
log.info("Preloading default tokens: {} {}",
@@ -140,22 +153,33 @@ CommandLineRunner initDataBaseDev(UserRepository userRepository, AccessTokenRepo
140153
.validUntil(Instant.now().getEpochSecond() + AccessTokenBusinessService.ACCESS_TOKEN_DURATION_IN_SECONDS)
141154
.build()));
142155

143-
log.info("Preloading default fsItems: {} {}.",
156+
log.info("Preloading default fsItems: {} {} {}.",
144157
fileSystemRepository.save(FileSystemEntity.builder()
145158
.createdByUserId(0)
146159
.fileSystemId(0)
147160
.isFile(false)
148161
.path("/")
149-
.itemIds(new long[]{1})
162+
.itemIds(new long[]{2})
150163
.lastUpdated(Instant.now().getEpochSecond())
151-
.name("root")
164+
.name("HOME_User")
165+
.size(420)
166+
.typeId(FileSystemType.FOLDER.getId())
167+
.visibleForGroupIds(new long[]{0, 1})
168+
.build()),
169+
fileSystemRepository.save(FileSystemEntity.builder()
170+
.createdByUserId(1)
171+
.fileSystemId(1)
172+
.isFile(false)
173+
.path("/")
174+
.lastUpdated(Instant.now().getEpochSecond())
175+
.name("HOME_User1")
152176
.size(420)
153177
.typeId(FileSystemType.FOLDER.getId())
154178
.visibleForGroupIds(new long[]{-1, 0, 1})
155179
.build()),
156180
fileSystemRepository.save(FileSystemEntity.builder()
157181
.createdByUserId(0)
158-
.fileSystemId(1)
182+
.fileSystemId(2)
159183
.isFile(true)
160184
.lastUpdated(Instant.now().getEpochSecond())
161185
.name("dummyFile.txt")
@@ -165,7 +189,7 @@ CommandLineRunner initDataBaseDev(UserRepository userRepository, AccessTokenRepo
165189
.visibleForGroupIds(new long[]{0})
166190
.build()));
167191

168-
log.info("Inserting FileSystemItems {}", (fileSystemRepository.findAll().size() == 2 ? MESSAGE_ON_SUCCESS : MESSAGE_ON_FAILURE));
192+
log.info("Inserting FileSystemItems {}", (fileSystemRepository.findAll().size() == 3 ? MESSAGE_ON_SUCCESS : MESSAGE_ON_FAILURE));
169193
log.info("Inserting token {}", (accessTokenRepository.findAll().size() == 2 ? MESSAGE_ON_SUCCESS : MESSAGE_ON_FAILURE));
170194
log.info("Inserting Users {}", (userRepository.findAll().size() == 2 ? MESSAGE_ON_SUCCESS : MESSAGE_ON_FAILURE));
171195
};

src/main/java/de/filefighter/rest/configuration/RestConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public class RestConfiguration {
1212
public static final String DEFAULT_ERROR_URI = "/error";
1313

1414
private RestConfiguration(){
15-
// Cannot be inst
15+
// Cannot be instantiated.
1616
}
1717
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package de.filefighter.rest.domain.common;
22

3-
public interface DtoServiceInterface<D,E> {
3+
public interface DTOServiceInterface<D,E> {
44
D createDto(E entity);
55
E findEntity(D dto);
66
}

0 commit comments

Comments
 (0)