-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
300 changed files
with
81,797 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"directory": "src/main/webapp/resources/bower_components" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
.classpath | ||
.project | ||
.settings/ | ||
.idea/ | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/io/bagarino/controller/api/AdminApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.bagarino.controller.api; | ||
|
||
import io.bagarino.manager.user.UserManager; | ||
import io.bagarino.model.user.Organization; | ||
import io.bagarino.model.user.User; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.security.Principal; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/admin/api") | ||
public class AdminApiController { | ||
|
||
private final UserManager userManager; | ||
|
||
@Autowired | ||
public AdminApiController(UserManager userManager) { | ||
this.userManager = userManager; | ||
} | ||
|
||
|
||
@RequestMapping("/organizations") | ||
@ResponseStatus(HttpStatus.OK) | ||
public List<Organization> getAllOrganizations(Principal principal) { | ||
return userManager.findUserOrganizations(principal.getName()); | ||
} | ||
|
||
@RequestMapping("/users") | ||
public List<User> getAllUsers(Principal principal) { | ||
return userManager.findAllUsers(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.bagarino.manager; | ||
|
||
public class EventManager { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.bagarino.manager.user; | ||
|
||
import io.bagarino.model.user.Authority; | ||
import io.bagarino.model.user.Organization; | ||
import io.bagarino.model.user.User; | ||
import io.bagarino.repository.user.AuthorityRepository; | ||
import io.bagarino.repository.user.OrganizationRepository; | ||
import io.bagarino.repository.user.UserRepository; | ||
import io.bagarino.repository.user.join.UserOrganizationRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
public class UserManager { | ||
|
||
private final AuthorityRepository authorityRepository; | ||
private final OrganizationRepository organizationRepository; | ||
private final UserOrganizationRepository userOrganizationRepository; | ||
private final UserRepository userRepository; | ||
|
||
@Autowired | ||
public UserManager(AuthorityRepository authorityRepository, | ||
OrganizationRepository organizationRepository, | ||
UserOrganizationRepository userOrganizationRepository, | ||
UserRepository userRepository) { | ||
this.authorityRepository = authorityRepository; | ||
this.organizationRepository = organizationRepository; | ||
this.userOrganizationRepository = userOrganizationRepository; | ||
this.userRepository = userRepository; | ||
} | ||
|
||
public List<Authority> getUserAuthorities(User user) { | ||
return authorityRepository.findGrantedAuthorities(user.getUsername()); | ||
} | ||
|
||
public List<User> findAllUsers() { | ||
return userRepository.findAll(); | ||
} | ||
|
||
public List<Organization> findUserOrganizations(String username) { | ||
return findUserOrganizations(userRepository.findByUsername(username)); | ||
} | ||
|
||
public List<Organization> findUserOrganizations(User user) { | ||
if(isAdmin(user)) { | ||
return organizationRepository.findAll(); | ||
} | ||
return userOrganizationRepository.findByUserId(user.getId()) | ||
.stream() | ||
.map(uo -> organizationRepository.findById(uo.getOrganizationId())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public boolean isAdmin(User user) { | ||
return getUserAuthorities(user).stream().anyMatch(a -> a.getRole().equals(AuthorityRepository.ROLE_ADMIN)); | ||
} | ||
|
||
public List<User> findMembers(Organization organization) { | ||
return userOrganizationRepository.findByOrganizationId(organization.getId()) | ||
.stream() | ||
.map(uo -> userRepository.findById(uo.getUserId())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/io/bagarino/model/user/join/UserOrganization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.bagarino.model.user.join; | ||
|
||
import io.bagarino.datamapper.ConstructorAnnotationRowMapper.Column; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class UserOrganization { | ||
|
||
private final int userId; | ||
private final int organizationId; | ||
|
||
public UserOrganization(@Column("user_id") int userId, @Column("org_id") int organizationId) { | ||
this.userId = userId; | ||
this.organizationId = organizationId; | ||
} | ||
} |
Oops, something went wrong.