Skip to content
Open
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
1 change: 1 addition & 0 deletions bugtracker/src/main/java/bugtracker/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected void configure(HttpSecurity httpSecurity) throws Exception {
.antMatchers("/api/user/current/**").permitAll()
.antMatchers("/api/**").access("hasRole('ROLE_USER') or hasRole('ROLE_ADMIN') or hasRole('ROLE_DEVELOPER') or hasRole('ROLE_APPROVER')")
.antMatchers("/ticket/**").access("hasRole('ROLE_USER') or hasRole('ROLE_ADMIN') or hasRole('ROLE_DEVELOPER') or hasRole('ROLE_APPROVER')")
.antMatchers("/comment/**").access("hasRole('ROLE_USER') or hasRole('ROLE_ADMIN') or hasRole('ROLE_DEVELOPER') or hasRole('ROLE_APPROVER')")
.and()
.csrf().disable()
.formLogin()
Expand Down
39 changes: 39 additions & 0 deletions bugtracker/src/main/java/bugtracker/comment/CommentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package bugtracker.comment;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.inject.Inject;
import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class CommentController {

@Inject
CommentService commentService;

@RequestMapping(
value = "/create",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
@ResponseBody()
public ResponseEntity addNewComment(@RequestBody CommentEntity commentEntity) {
try {
commentService.createComment(commentEntity);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(HttpStatus.OK);
}

@GetMapping("/all/{ticketId}")
public ResponseEntity<List<CommentEntity>> getAllByTicketID(@PathVariable Long ticketId) {
return new ResponseEntity<>(commentService.getAllByTicketId(ticketId), HttpStatus.OK);
}
}
70 changes: 70 additions & 0 deletions bugtracker/src/main/java/bugtracker/comment/CommentEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package bugtracker.comment;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.time.LocalDateTime;

@Entity
@Table(name = "KOMMENT")
public class CommentEntity {
@Id
@GeneratedValue
private long id;

private long ticketId;
private long userId;

private String commentText;
private String userName;
private LocalDateTime commentTime;

public long getId() {
return id;
}

public long getTicketId() {
return ticketId;
}

public long getUserId() {
return userId;
}

public String getCommentText() {
return commentText;
}

public LocalDateTime getCommentTime() {
return commentTime;
}

public void setId(long id) {
this.id = id;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public void setTicketId(long ticketId) {
this.ticketId = ticketId;
}

public void setUserId(long userId) {
this.userId = userId;
}

public void setCommentText(String commentText) {
this.commentText = commentText;
}

public void setCommentTime(LocalDateTime commentTime) {
this.commentTime = commentTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package bugtracker.comment;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface CommentRepository extends JpaRepository<CommentEntity, Long> {
List<CommentEntity> findAllByTicketId(Long ticketId);
}
21 changes: 21 additions & 0 deletions bugtracker/src/main/java/bugtracker/comment/CommentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package bugtracker.comment;

import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.List;

@Service
public class CommentService {

@Inject
CommentRepository commentRepository;

public CommentEntity createComment(CommentEntity commentEntity) {
return commentRepository.save(commentEntity);
}

public List<CommentEntity> getAllByTicketId(Long ticketId) {
return commentRepository.findAllByTicketId(ticketId);
}
}
6 changes: 5 additions & 1 deletion bugtracker/src/main/java/bugtracker/user/BTUserDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public boolean isCredentialsNonExpired() {

@Override
public boolean isEnabled() {
return true;
return user.getDeletedTs() == null;
}

public Long getId() {
return user.getId();
}
}
12 changes: 11 additions & 1 deletion bugtracker/src/main/java/bugtracker/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,18 @@ public ResponseEntity<List<UserEntity>> getAllSimpleUser(){
return new ResponseEntity<>(userService.getUsersByType(2), HttpStatus.OK);
}

@GetMapping("/current/")
public ResponseEntity<UserEntity> getCurrentUser(Authentication authentication) {
if (authentication != null) {
BTUserDetails principal = (BTUserDetails) authentication.getPrincipal();
return new ResponseEntity<>(userService.getUserById(principal.getId()), HttpStatus.OK);
} else {
return new ResponseEntity<>(null, HttpStatus.UNAUTHORIZED);
}
}

@GetMapping("/current/roles")
public ResponseEntity<List<String>> getCurrentUser(Authentication authentication){
public ResponseEntity<List<String>> getCurrentUserRoles(Authentication authentication){
if (authentication != null) {
BTUserDetails principal = (BTUserDetails) authentication.getPrincipal();
return new ResponseEntity<>(principal.getAuthorities().stream().map(t -> ((GrantedAuthority) t).getAuthority()).collect(toList()), HttpStatus.OK);
Expand Down
10 changes: 6 additions & 4 deletions bugtracker/src/main/java/bugtracker/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ public UserEntity createUser(UserEntity user){
}

public UserEntity deleteUser(UserEntity user){
user.setDeletedTs(LocalDateTime.now());
return userRepository.save(user);
UserEntity userEntity = userRepository.findUserEntityById(user.getId());
userEntity.setDeletedTs(LocalDateTime.now());
return userRepository.save(userEntity);
}

public UserEntity undeleteUser(UserEntity user){
user.setDeletedTs(null);
return userRepository.save(user);
UserEntity userEntity = userRepository.findUserEntityById(user.getId());
userEntity.setDeletedTs(null);
return userRepository.save(userEntity);
}

public UserEntity modifyUser(UserEntity user){
Expand Down
20 changes: 19 additions & 1 deletion bugtracker/src/main/resources/static/css/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
/* Based on ext-6.2.0-gpl/ext-6.2.0/build/examples/classic/responsive-app/resources/ResponsiveApp-all.css
* © 2019 Sencha Inc. (under the terms of the GPLv3 license) */

.x-dataview-item {
border : 1px solid #dadada;
border-radius : 2px;
padding : 2px;
margin : 2px;
}

.comments .created{
font-style:italic
}
.comments .user{
font-weight:bold
}
.comments .content{
margin-bottom:10px
}

.deleted-user .x-grid-cell {
background-color: #ffe2e2;
color: #900;
Expand Down Expand Up @@ -729,7 +746,8 @@ td.x-frame-br {
}

.x-splitter {
font-size: 1px
font-size: 1px;
background-color: #3892D4
}

.x-splitter-horizontal {
Expand Down
5 changes: 3 additions & 2 deletions bugtracker/src/main/resources/static/js/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ let projectdetails = function() {
};

var projectdetailswindow = Ext.create('Ext.Window', {
width: 1000,
height: 500,
width: 560,
height: 380,
padding: 15,
modal: true,
title: "Project details",
layout: {
type: 'vbox',
padding: 5
Expand Down
Loading