权限/空间管理调整

V0.5.x
xiwa 2022-05-09 17:53:28 +08:00
parent 228a2fdd27
commit 640262e9e5
3 changed files with 24 additions and 5 deletions

View File

@ -11,4 +11,6 @@ public interface SpaceRepository extends MongoRepository<Space, String> {
List<Space> findByUidOrderByCreateAtDesc(String uid); List<Space> findByUidOrderByCreateAtDesc(String uid);
List<Space> findByUidAndHomeIdOrderByCreateAtDesc(String uid, String homeId);
} }

View File

@ -57,6 +57,12 @@ public class KeycloakSecurityConfig extends KeycloakWebSecurityConfigurerAdapter
.antMatchers("/*.html", "/favicon.ico", "/v2/api-docs", "/webjars/**", "/swagger-resources/**", "/*.js").permitAll() .antMatchers("/*.html", "/favicon.ico", "/v2/api-docs", "/webjars/**", "/swagger-resources/**", "/*.js").permitAll()
.antMatchers("/api/**").hasRole("iot_client_user") .antMatchers("/api/**").hasRole("iot_client_user")
.antMatchers("/aligenieDevice/invoke/**").hasRole("iot_client_user") .antMatchers("/aligenieDevice/invoke/**").hasRole("iot_client_user")
//客户端用户写权限
.antMatchers("/space/addSpace/**").hasRole("iot_client_user")
.antMatchers("/space/saveSpace/**").hasRole("iot_client_user")
.antMatchers("/space/delSpace/**").hasRole("iot_client_user")
.antMatchers("/space/saveHome/**").hasRole("iot_client_user")
.antMatchers(HttpMethod.DELETE).hasRole("iot_write") .antMatchers(HttpMethod.DELETE).hasRole("iot_write")
.antMatchers(HttpMethod.PUT).hasRole("iot_write") .antMatchers(HttpMethod.PUT).hasRole("iot_write")
.antMatchers("/**/save*/**").hasRole("iot_write") .antMatchers("/**/save*/**").hasRole("iot_write")

View File

@ -26,6 +26,17 @@ public class SpaceController {
@Autowired @Autowired
private DataOwnerService dataOwnerService; private DataOwnerService dataOwnerService;
/**
*
*/
@GetMapping("/currentHome")
public Home getCurrentHome() {
return homeRepository.findByUidAndCurrent(AuthUtil.getUserId(), true);
}
/**
*
*/
@PostMapping("/saveHome/{id}") @PostMapping("/saveHome/{id}")
public void saveHome(@PathVariable("id") String id, Home home) { public void saveHome(@PathVariable("id") String id, Home home) {
Optional<Home> optHome = homeRepository.findById(id); Optional<Home> optHome = homeRepository.findById(id);
@ -44,17 +55,17 @@ public class SpaceController {
} }
/** /**
* *
*/ */
@GetMapping("/spaces") @GetMapping("/spaces/{homeId}")
public List<Space> getSpaces() { public List<Space> getSpaces(@PathVariable("homeId") String homeId) {
return spaceRepository.findByUidOrderByCreateAtDesc(AuthUtil.getUserId()); return spaceRepository.findByUidAndHomeIdOrderByCreateAtDesc(AuthUtil.getUserId(), homeId);
} }
/** /**
* *
*/ */
@PostMapping("/add") @PostMapping("/addSpace")
public void addSpace(String name) { public void addSpace(String name) {
String uid = AuthUtil.getUserId(); String uid = AuthUtil.getUserId();
Home currHome = homeRepository.findByUidAndCurrent(uid, true); Home currHome = homeRepository.findByUidAndCurrent(uid, true);