Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen committed Oct 29, 2024
1 parent f7d274c commit 486f875
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class Authority implements Serializable {
@Column(name = "system_role")
private boolean systemRole;

@Column(name = "description")
private String description;

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public class User extends AbstractAuditingEntity<Long> implements Serializable {

public LocalDateTime getLastLoginTime() {
if (lastLoginTime == null) return null;
ZoneId userZone = (timezone != null) ? ZoneId.of(timezone) : ZoneId.of("America/Los_Angeles");
ZoneId userZone =
(timezone != null) ? ZoneId.of(timezone) : ZoneId.of("America/Los_Angeles");
return lastLoginTime.atZone(ZoneOffset.UTC).withZoneSameInstant(userZone).toLocalDateTime();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.flexwork.modules.usermanagement.service.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class ResourceDTO {
private String name;
private String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import jakarta.validation.Valid;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -68,9 +69,9 @@ public ResponseEntity<Authority> createAuthority(@Valid @RequestBody Authority a
*/
@GetMapping("")
@PreAuthorize("hasAnyAuthority('ROLE_ADMIN')")
public List<Authority> getAllAuthorities() {
public Page<Authority> getAllAuthorities(Pageable pageable) {
LOG.debug("REST request to get all Authorities");
return authorityRepository.findAll();
return authorityRepository.findAll(pageable);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.flexwork.modules.usermanagement.web.rest;

import io.flexwork.modules.usermanagement.repository.ResourceRepository;
import io.flexwork.modules.usermanagement.service.dto.ResourceDTO;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/resources")
public class ResourceController {

private final ResourceRepository resourceRepository;

@Autowired
public ResourceController(ResourceRepository resourceRepository) {
this.resourceRepository = resourceRepository;
}

@GetMapping
public ResponseEntity<List<ResourceDTO>> getAllResources() {
List<ResourceDTO> resources =
resourceRepository.findAll().stream()
.map(
resource ->
new ResourceDTO(
resource.getName(), resource.getDescription()))
.collect(Collectors.toList());
return ResponseEntity.ok(resources);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</column>
<column name="system_role" type="BOOLEAN"
defaultValueBoolean="false" />
<column name="description" type="VARCHAR(256)" />
<column name="description" type="TEXT" />
</createTable>

<createTable tableName="fw_user_authority">
Expand Down Expand Up @@ -88,7 +88,7 @@
<column name="name" type="VARCHAR(50)">
<constraints nullable="false" primaryKey="true" />
</column>
<column name="description" type="VARCHAR(256)" />
<column name="description" type="TEXT" />
</createTable>

<createTable tableName="fw_authority_resource_permission">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
authority_name;resource_name;permission
ROLE_USER;user;READ
ROLE_USER;account;READ
ROLE_USER;contact;READ
ROLE_USER;User;READ
ROLE_USER;Account;WRITE
ROLE_USER;Contact;WRITE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name
user
file
account
contact
case
name;description
User;
File;
Account;
Contact;
Case;
Team;
Organization;

0 comments on commit 486f875

Please sign in to comment.