-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Communication: Accept messaging code of conduct (#7154)
- Loading branch information
1 parent
3900fea
commit 19a81aa
Showing
43 changed files
with
923 additions
and
39 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/main/java/de/tum/in/www1/artemis/domain/ConductAgreement.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,65 @@ | ||
package de.tum.in.www1.artemis.domain; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.persistence.*; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
/** | ||
* A user's agreement of a course's code of conduct. | ||
*/ | ||
@Entity | ||
@Table(name = "conduct_agreement") | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
@IdClass(ConductAgreementId.class) | ||
public class ConductAgreement { | ||
|
||
@Id | ||
@ManyToOne | ||
@JoinColumn(name = "course_id") | ||
private Course course; | ||
|
||
@Id | ||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
public Course getCourse() { | ||
return course; | ||
} | ||
|
||
public void setCourse(Course course) { | ||
this.course = course; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
ConductAgreement that = (ConductAgreement) o; | ||
return course.equals(that.course) && user.equals(that.user); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(course, user); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ConductAgreement{" + "course=" + course + ", user=" + user + '}'; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/de/tum/in/www1/artemis/domain/ConductAgreementId.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,56 @@ | ||
package de.tum.in.www1.artemis.domain; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
/** | ||
* The primary key for ConductAgreement | ||
*/ | ||
public class ConductAgreementId implements Serializable { | ||
|
||
private Long course; | ||
|
||
private Long user; | ||
|
||
ConductAgreementId(Long course, Long user) { | ||
this.course = course; | ||
this.user = user; | ||
} | ||
|
||
ConductAgreementId() { | ||
// Needed for JPA | ||
} | ||
|
||
public Long getCourse() { | ||
return course; | ||
} | ||
|
||
public void setCourse(Long course) { | ||
this.course = course; | ||
} | ||
|
||
public Long getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(Long user) { | ||
this.user = user; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
ConductAgreementId that = (ConductAgreementId) o; | ||
return course.equals(that.course) && user.equals(that.user); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(course, user); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/de/tum/in/www1/artemis/repository/ConductAgreementRepository.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,36 @@ | ||
package de.tum.in.www1.artemis.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import de.tum.in.www1.artemis.domain.ConductAgreement; | ||
import de.tum.in.www1.artemis.domain.ConductAgreementId; | ||
|
||
/** | ||
* Spring Data repository for the Code of Conduct Agreement entity. | ||
*/ | ||
@Repository | ||
public interface ConductAgreementRepository extends JpaRepository<ConductAgreement, ConductAgreementId> { | ||
|
||
/** | ||
* Find the user's agreement to a course's code of conduct. | ||
* | ||
* @param courseId the ID of the code of conduct's course | ||
* @param userId the user's ID | ||
* @return the user's agreement to the course's code of conduct | ||
*/ | ||
Optional<ConductAgreement> findByCourseIdAndUserId(Long courseId, Long userId); | ||
|
||
/** | ||
* Delete all users' agreements to a course's code of conduct. | ||
* | ||
* @param courseId the ID of the code of conduct's course | ||
*/ | ||
@Transactional // ok because of delete | ||
@Modifying | ||
void deleteByCourseId(Long courseId); | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/de/tum/in/www1/artemis/service/ConductAgreementService.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,58 @@ | ||
package de.tum.in.www1.artemis.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import de.tum.in.www1.artemis.domain.ConductAgreement; | ||
import de.tum.in.www1.artemis.domain.Course; | ||
import de.tum.in.www1.artemis.domain.User; | ||
import de.tum.in.www1.artemis.repository.ConductAgreementRepository; | ||
|
||
/** | ||
* Service Implementation for managing a user's agreement to a course's code of conduct. | ||
*/ | ||
@Service | ||
public class ConductAgreementService { | ||
|
||
private final ConductAgreementRepository conductAgreementRepository; | ||
|
||
ConductAgreementService(ConductAgreementRepository conductAgreementRepository) { | ||
this.conductAgreementRepository = conductAgreementRepository; | ||
} | ||
|
||
/** | ||
* Fetches if a user agreed to a course's code of conduct. | ||
* | ||
* @param user the user in the course | ||
* @param course the code of conduct's course | ||
* @return if the user agreed to the course's code of conduct | ||
*/ | ||
public boolean fetchUserAgreesToCodeOfConductInCourse(User user, Course course) { | ||
var codeOfConduct = course.getCourseInformationSharingMessagingCodeOfConduct(); | ||
if (codeOfConduct == null || codeOfConduct.isEmpty()) { | ||
return true; | ||
} | ||
return conductAgreementRepository.findByCourseIdAndUserId(course.getId(), user.getId()).isPresent(); | ||
} | ||
|
||
/** | ||
* A user agrees to a course's code of conduct. | ||
* | ||
* @param user the user in the course | ||
* @param course the code of conduct's course | ||
*/ | ||
public void setUserAgreesToCodeOfConductInCourse(User user, Course course) { | ||
ConductAgreement conductAgreement = new ConductAgreement(); | ||
conductAgreement.setCourse(course); | ||
conductAgreement.setUser(user); | ||
conductAgreementRepository.save(conductAgreement); | ||
} | ||
|
||
/** | ||
* Reset all agreements to a course's code of conduct. | ||
* | ||
* @param course the code of conduct's course | ||
*/ | ||
public void resetUsersAgreeToCodeOfConductInCourse(Course course) { | ||
conductAgreementRepository.deleteByCourseId(course.getId()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/de/tum/in/www1/artemis/service/dto/ResponsibleUserDTO.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,7 @@ | ||
package de.tum.in.www1.artemis.service.dto; | ||
|
||
/** | ||
* A DTO representing a course's responsible user, i.e., a person to report misconduct to. | ||
*/ | ||
public record ResponsibleUserDTO(String name, String email) { | ||
} |
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
Oops, something went wrong.