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

removed check for COMPANY_OWNER role when no role was needed #57

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions src/main/java/com/MeetMate/company/CompanyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public Company getCompany(@Argument long id) {

} catch (Throwable t) {
Class<? extends Throwable> tc = t.getClass();
return null;
return new Company(-1, "error", "error");

// if (tc == EntityNotFoundException.class)
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body("message: " + t.getMessage());
//

// if (tc == IllegalArgumentException.class)
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("message: " + t.getMessage());
//

// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("message: " + t.getMessage());
}
}
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/com/MeetMate/company/CompanyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ public class CompanyService {
private final SequenceService sequenceService;

public Company getCompany(long id) throws IllegalArgumentException {

//Test if user is a company owner
if (userRepository.findUserById(id)
.orElseThrow(() -> new EntityNotFoundException("User not found!"))
.getRole() != UserRole.COMPANY_OWNER)
throw new IllegalArgumentException("User is not a company owner");

return companyRepository.findCompanyById(id)
.orElseThrow(() -> new EntityNotFoundException("Company not found"));
}
Expand All @@ -57,7 +50,7 @@ public void createCompany(String companyName, String ownerEmail, String ownerNam

@Transactional
public void editCompany(String token, String companyName, String description, String businessType) {
String ownerEmail = getCompanyWithToken(token).getOwnerEmail();
String ownerEmail = getCompanyWithOwnerEmail(token).getOwnerEmail();

Query query = new Query(Criteria.where("ownerEmail").is(ownerEmail));
Update update = new Update();
Expand All @@ -69,7 +62,7 @@ public void editCompany(String token, String companyName, String description, St

@Transactional
public void deleteCompany(String token) {
Company company = getCompanyWithToken(token);
Company company = getCompanyWithOwnerEmail(token);
try {
userController.deleteUser(token);
} catch (Throwable t) {
Expand All @@ -78,7 +71,7 @@ public void deleteCompany(String token) {
companyRepository.delete(company);
}

private Company getCompanyWithToken(String ownerEmail) throws IllegalArgumentException {
private Company getCompanyWithOwnerEmail(String ownerEmail) throws IllegalArgumentException {

//Test if user is a company owner
if (userRepository.findUserByEmail(ownerEmail)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/MeetMate/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
.authorizeHttpRequests(
authorizeRequests ->
authorizeRequests
// .requestMatchers("/api/user/login", "/api/user/signup", "/test/test", "/graphql/**")
.requestMatchers("/**")
.requestMatchers("/api/user/login", "/api/user/signup", "/test/test", "/graphql/**")
// .requestMatchers("/**")
.permitAll() // Whitelist
.anyRequest().authenticated() // Everything else should be authenticated
)
Expand Down
Loading