Skip to content

Commit

Permalink
Merge pull request #107 from rash0621/main
Browse files Browse the repository at this point in the history
project management
  • Loading branch information
rash0621 authored Sep 18, 2024
2 parents 835b002 + f406934 commit 8201c95
Show file tree
Hide file tree
Showing 8,498 changed files with 3,499,376 additions and 124 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 4 additions & 0 deletions back-end/src/main/java/com/example/demo/appuser/AppUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public AppUser( String firstName,
* This method is used by Spring Security to determine the roles of the user
*/
@Override
@JsonIgnore
public Collection<? extends GrantedAuthority> getAuthorities() {
SimpleGrantedAuthority authority = new SimpleGrantedAuthority(appUserRole.name());
return Collections.singletonList(authority);
Expand All @@ -97,16 +98,19 @@ public String getUsername() {
}

@Override
@JsonIgnore
public boolean isAccountNonExpired() {
return true;
}

@Override
@JsonIgnore
public boolean isAccountNonLocked() {
return !locked;
}

@Override
@JsonIgnore
public boolean isCredentialsNonExpired() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
Expand All @@ -33,4 +30,7 @@ public List<AppUser> getUserList(){
public AppUser getUser(@PathVariable Integer userID){
return appUserService.getUser(userID);
}

@PostMapping("/getUserByEmail")
public AppUser getUserByEmail(@RequestBody EmailRequest email){return appUserService.getUserAndCheckingByEmail(email);}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* Users can have either the USER role or the ADMIN role.
*/
public enum AppUserRole {
USER, ADMIN;
USER, ADMIN, COORDINATOR, MANAGER, SUPER_ADMIN;
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public List<AppUser> getAllUsers(){
public AppUser getUser(long userID){
return appUserRepository.findById(userID).get();
}

//checking if a user exists
public AppUser getUserAndCheckingByEmail(EmailRequest emailRequest) {
Optional<AppUser> appUser = appUserRepository.findByEmail(emailRequest.getEmail());
return appUser.orElse(null);
}
}


16 changes: 16 additions & 0 deletions back-end/src/main/java/com/example/demo/appuser/EmailRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.demo.appuser;

public class EmailRequest {
private String email;

// Getters and setters
public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@RestController
@RequestMapping("/api/v1/files")
@AllArgsConstructor

public class FileController {

private final FileService fileService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.authorizeHttpRequests(authz -> authz

.requestMatchers("/api/v*/registration/**", "/api/v1/news/**", "/api/v1/gallery/**", "/api/v*/files/**",
"/api/v*/registration/login/**", "/oauth2/**","/api/v1/tasks/**", "/api/v1/users/**", "/deliverable/**", "/workplan/**")
"/api/v*/registration/login/**", "/oauth2/**","/api/v1/tasks/**", "/api/v1/users/**", "/deliverable/**", "/workplan/**","/api/v1/users/**")

.permitAll()
.anyRequest().authenticated()
Expand Down
9 changes: 3 additions & 6 deletions back-end/src/main/java/com/example/demo/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,10 @@ public void assignMember(AppUser user) {
assignedUsers.add(user);
}

public void deleteAssignMember(AppUser user) {
assignedUsers.remove(user);
public void deleteAssignMembers() {
assignedUsers.clear();
}

public void setAssignedMembers(Set<AppUser> taskMembers){
for (AppUser taskMember : taskMembers) {
assignMember(taskMember);}
}


}
30 changes: 29 additions & 1 deletion back-end/src/main/java/com/example/demo/task/TaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ public TaskResponse addTask(@RequestBody Task newTask){
return new TaskResponse(s);
}

@PostMapping("/addWithUsers")
public ResponseEntity<String> addTaskWithUsers(@RequestBody TaskDTO taskDTO){
try {
Task task = taskDTO.getTask();
Set<AppUser> taskMembers = taskDTO.getTaskMembers();
taskService.addTaskWithUsers(task,taskMembers);
return ResponseEntity.ok("Task added successfully");
}catch (Exception e) {
return ResponseEntity.status(500).body("Failed to add task");
}
}

@PostMapping("/updateWithUsers")
public ResponseEntity<String> updateTaskWithUsers(@RequestBody TaskDTO taskDTO){
try {
Task task = taskDTO.getTask();
Set<AppUser> taskMembers = taskDTO.getTaskMembers();
taskService.updateTaskWithUsers(task,taskMembers);
return ResponseEntity.ok("Task updated successfully");
}catch (Exception e) {
return ResponseEntity.status(500).body("Failed to update task");
}
}

@PutMapping("/update")
public void updateTask(@RequestBody Task updateTask){
taskService.updateTask(updateTask);
Expand All @@ -58,6 +82,10 @@ public TaskResponse addUserToTask(@PathVariable Integer taskID,@PathVariable Lon
return new TaskResponse("Assigned user with id "+userID+" to task with id "+taskID);
}


@DeleteMapping("/{taskID}/users/{userID}")
public TaskResponse deleteUserToTask(@PathVariable Integer taskID,@PathVariable Long userID){
taskService.deleteTaskUsers(taskID,userID);
return new TaskResponse("Deleted user with id "+userID+" to task with id "+taskID);
}

}
28 changes: 28 additions & 0 deletions back-end/src/main/java/com/example/demo/task/TaskDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.demo.task;

import com.example.demo.appuser.AppUser;

import java.util.Optional;
import java.util.Set;

public class TaskDTO {

private Task task;
private Set<AppUser> assignedUsers;

public Task getTask() {
return task;
}

public void setTask(Task task) {
this.task = task;
}

public Set<AppUser> getTaskMembers(){
return assignedUsers;
}

public void setAssignedUsers(Set<AppUser> assignedUsers) {
this.assignedUsers = assignedUsers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public interface TaskRepository extends JpaRepository<Task, Integer> {
@Query("SELECT t FROM Task t where ?1 member of t.assignedUsers")
List<Task> findTasksByUser(AppUser user);

// @Modifying
// @Query("UPDATE Task t SET t.assignedUsers = t.assignedUsers - ?1 WHERE t IN (SELECT t FROM Task t WHERE ?1 member of t.assignedUsers)")
// void deleteUserFromTasks(AppUser user);
@Transactional
@Modifying
// @Query(nativeQuery = true, value = "UPDATE Task t SET t.assignedUsers = t.assignedUsers - ?1 WHERE t IN (SELECT t FROM Task t WHERE ?1 member of t.assignedUsers)")
@Query(nativeQuery = true, value = "DELETE FROM assigned_tasks where task_id=?1 AND user_id=?2")
void deleteUserFromTasks(int taskID,Long userID);

}

22 changes: 18 additions & 4 deletions back-end/src/main/java/com/example/demo/task/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.example.demo.appuser.AppUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -44,12 +45,25 @@ public void addUserToTask(int task_ID, long userID){
taskRepository.save(task);
}

@Transactional
public void addTaskWithUsers(Task task, Set<AppUser> taskMembers){

task.setAssignedMembers(taskMembers);
taskRepository.save(task);
for (AppUser taskMember : taskMembers) {
task.assignMember(taskMember);
}
taskRepository.save(task);

}

@Transactional
public void updateTaskWithUsers(Task task, Set<AppUser> taskMembers){
task.deleteAssignMembers();
for (AppUser taskMember : taskMembers) {
task.assignMember(taskMember);
}
taskRepository.save(task);
}

public void deleteTask(int task_ID){
taskRepository.deleteById(task_ID);
Expand All @@ -61,9 +75,9 @@ public List<Task> findUserTasks(Long userID) {
return taskRepository.findTasksByUser(user);
}

// public void deleteTaskUsers(int taskID,Long userID){
// taskRepository.deleteUserFromTasks(taskID,userID);
// }
public void deleteTaskUsers(int taskID,Long userID){
taskRepository.deleteUserFromTasks(taskID,userID);
}
}


98 changes: 53 additions & 45 deletions back-end/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
server:
error:
include-message: always
include-binding-errors: always

spring:
datasource:
url: jdbc:mysql://localhost:3306/cycle
password:
username: root
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
format_sql: true
show-sql: true

mail:
host: localhost
port: 1025
username: hello
password: hello
properties:
mail:
smtp:
ssl:
trust: "*"
auth: true
starttls:
enable: true
connection timeout: 5000
timeout: 3000
write timeout: 5000

servlet:
multipart:
max-file-size: 100MB # Increase size for large files
max-request-size: 100MB # Increase size for large files

tomcat:
max-http-header-size: 16384 # Adjust if needed for large headers
max-swallow-size: 104857600 # 100MB, adjust according to file size needs
server:
error:
include-message: always
include-binding-errors: always

spring:
datasource:
url: jdbc:mysql://localhost:3306/cycle
password: "&*531cW9/?"
username: root
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
format_sql: true
show-sql: true

mail:
host: localhost
port: 1025
username: hello
password: hello
properties:
mail:
smtp:
ssl:
trust: "*"
auth: true
starttls:
enable: true
connection timeout: 5000
timeout: 3000
write timeout: 5000

security:
oauth2:
client:
registration:
google:
client-id: "257276141541-av8vs5jp5u7e9f3am8dllo761kg7abo8.apps.googleusercontent.com"
client-secret: "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"

servlet:
multipart:
max-file-size: 100MB # Increase size for large files
max-request-size: 100MB # Increase size for large files

tomcat:
max-http-header-size: 16384 # Adjust if needed for large headers
max-swallow-size: 104857600 # 100MB, adjust according to file size needs
27 changes: 25 additions & 2 deletions front-end/src/Pages/Dashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import style from "../components/Dashboard.module.css";

/*Dashboard Page */
function Dashboard() {



return(
<>
<div className={style["DashboardTitle"]}>
<h3>Dashboard</h3>

{/* <div className="tasks-container">
{tasks.map((item) => (
<div key={item.taskID} className="task-tile">
<h2>{item.taskName}</h2>
<b><p>Date: {item.startDate}</p></b>
<b><p>Date: {item.endDtae}</p></b>
<b><p>Author: {item.newsAuthor}</p></b>
<a href={item.newsUrl} target="_blank" rel="noopener noreferrer">Financial Report</a> {/* Link to fiancial report */}

{/* Show edit and delete buttons only if user is logged in */}
{/* {loggedInUser.isLoggedIn && (
<div>
<button className="actionButton" onClick={() => onEditClick(item)}><FontAwesomeIcon icon={faPen}/></button>
<button className="actionButton" onClick={() => onViewClick(item)}><FontAwesomeIcon icon={faEye}/></button>
<button className="actionButton" onClick={() => onDeleteClick(item.newsID)}><FontAwesomeIcon icon={faTrash} /></button>
</div>
)}
</div> */}
{/* ))}
</div> */}

</div>
</>
);
Expand Down
Loading

0 comments on commit 8201c95

Please sign in to comment.