Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#119 Native Sublinks API #359

Open
wants to merge 131 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
139ae2a
#119 Created base controllers for native API
jgrim Dec 22, 2023
8115338
Merge branch 'main' into issue/119-native-api
jgrim Apr 23, 2024
9388d2a
Minor fix addition
Pdzly Apr 24, 2024
d340421
Added Personmapper
Pdzly Apr 24, 2024
c29a96b
Remove unnecessary blank line in PersonMapper
Pdzly Apr 25, 2024
e922f0e
Merge branch 'refs/heads/feature/353-swap-to-postgres' into issue/119…
Pdzly Apr 26, 2024
523d863
Refactor PersonService, implement JWT auth and person registration
Pdzly Apr 29, 2024
adab151
Refactor codebase to switch primitive boolean to Boolean and expand A…
Pdzly May 2, 2024
6384aba
Fixed a bug
Pdzly May 2, 2024
93f62f0
Fixed a bug
Pdzly May 2, 2024
6034093
Add find methods in repositories and enhance community service
Pdzly May 2, 2024
364454a
Implement comment service logic and enhance authorization
Pdzly May 4, 2024
7945a0a
Refactor to use Optional in CommunityRepository methods
Pdzly May 4, 2024
842ce8d
Refactor authentication and add language support to comments
Pdzly May 5, 2024
a21b35b
Merge branch 'refs/heads/main' into issue/119-native-api
Pdzly May 5, 2024
ce6b513
Refactor code for readability and consistency
Pdzly May 5, 2024
123a928
.
Pdzly May 6, 2024
0b8f6e2
Refactor authentication and update APIs
Pdzly May 6, 2024
e2523b1
Refactor controller classes and improve security
Pdzly May 7, 2024
ac83973
Renamed Enum 'ListingType' to 'SublinksListingType' and updated refer…
Pdzly May 7, 2024
505d895
Made the community controller work
Pdzly May 7, 2024
9b91168
Merge branch 'main' into issue/119-native-api
Pdzly May 8, 2024
2566d31
Fixed some more
Pdzly May 8, 2024
0d47e47
Add CommunityView and CommunityAggregates models
Pdzly May 8, 2024
05a030b
Fixed a hickup
Pdzly May 8, 2024
a76268e
Renamed some attributes
Pdzly May 8, 2024
171f0b7
Renamed some attributes
Pdzly May 8, 2024
95a7861
Revert "Renamed some attributes"
Pdzly May 10, 2024
94d7372
Revert "Fixed a hickup"
Pdzly May 10, 2024
a15c903
Revert "Add CommunityView and CommunityAggregates models"
Pdzly May 10, 2024
fb87d98
Merge remote-tracking branch 'origin/issue/119-native-api' into issue…
Pdzly May 10, 2024
9a5e686
Revert "Renamed some attributes"
Pdzly May 11, 2024
bddbff7
Revert "Renamed some attributes"
Pdzly May 11, 2024
904475b
Revert "Fixed a hickup"
Pdzly May 11, 2024
ae145c4
Revert "Add CommunityView and CommunityAggregates models"
Pdzly May 11, 2024
19a10ec
Renamed some attributes
Pdzly May 11, 2024
92b6f1c
Add community moderation features
Pdzly May 11, 2024
9288a10
Merge branch 'main' into issue/119-native-api
jgrim May 12, 2024
bc0c69f
Implement user ban and unban functionality
Pdzly May 13, 2024
99d0a69
Add CRUD features for communities and initial post functionality
Pdzly May 17, 2024
4b873d1
Refactor UserController to improve person update logic
Pdzly May 19, 2024
800de62
Update comment controller to return a list of responses
Pdzly May 19, 2024
f467971
Enhance comment and community features
Pdzly May 19, 2024
24b5209
Enhance ban logic and add community remove feature
Pdzly May 21, 2024
9e01c0b
Enhance ban logic and add community remove feature
Pdzly May 21, 2024
e3d7037
Merge remote-tracking branch 'origin/issue/119-native-api' into issue…
Pdzly May 21, 2024
f894d1f
Merge branch 'main' into issue/119-native-api
Pdzly May 22, 2024
5bbf85a
Add community and comment moderation features
Pdzly May 18, 2024
dd612d5
Merge branch 'refs/heads/main' into issue/119-native-api
Pdzly May 25, 2024
430baa2
Add comment pinning feature and refactor HTTP methods
Pdzly May 25, 2024
815c3f0
Add comment pinning functionality and refactor HTTP methods
Pdzly May 26, 2024
290cb35
Refactor application and extend functionality
Pdzly May 28, 2024
4a5a936
Merge branch 'main' into issue/119-native-api
Pdzly May 28, 2024
529971e
Refactor PersonAggregationController and add Auth checks
Pdzly May 28, 2024
c6f3615
Enhanced authorization checks and response models
Pdzly May 28, 2024
b4fe7c4
Add search functionality for instances and enhance APIs
Pdzly May 30, 2024
6fdc7b3
LINT
Pdzly May 30, 2024
1885ed3
Extend Search API to support communities, posts, and comments
Pdzly May 31, 2024
b67c2d8
Refactor code structure and add search functionality
Pdzly Jun 1, 2024
cf8726a
Optimize search functionality and improve code structure
Pdzly Jun 2, 2024
ac6a1dd
Refactor PostReport and PostLike repositories
Pdzly Jun 3, 2024
1ee4353
Add show and create methods to SublinksPostService
Pdzly Jun 3, 2024
74f00e8
Merge branch 'refs/heads/main' into issue/119-native-api
Pdzly Jun 3, 2024
3ddde7b
Enhance Post functionalities with language support and slur filter
Pdzly Jun 3, 2024
58b825a
Implement comment aggregate API and extend post functionalities
Pdzly Jun 6, 2024
f37650b
Implement comment aggregate API and extend post functionalities
Pdzly Jun 7, 2024
c450e00
Merge branch 'main' into issue/119-native-api
Pdzly Jun 7, 2024
dbf7b5d
Remove unnecessary comment from SQL migration script
Pdzly Jun 9, 2024
5a5ec06
Merge branch 'refs/heads/main' into issue/119-native-api
Pdzly Jun 10, 2024
dec9b68
Add announcement functionality to Sublinks API
Pdzly Jun 16, 2024
6977dff
Add CRUD operations and models for announcements
Pdzly Jun 17, 2024
9f157db
Add 'active' status and 'creator' field to announcements
Pdzly Jun 24, 2024
626ca5d
Refactor permissions checks in various services
Pdzly Jun 25, 2024
46def33
Add functionality for handling user metadata
Pdzly Jun 29, 2024
47c53fa
Merge branch 'refs/heads/main' into issue/119-native-api
Pdzly Jun 29, 2024
9a0a7eb
Refactor security configuration in SecurityConfig.java
Pdzly Jun 29, 2024
bd0ebc1
Rearrange JWT filter addition in SecurityConfig
Pdzly Jun 29, 2024
e99b145
Refactor SublinksPersonMetaDataMapper class
Pdzly Jun 30, 2024
d550b84
Refactor code and enhance User Data Management capabilities
Pdzly Jun 30, 2024
2ae010c
Refactor UserDataService to simplify metadata updates
Pdzly Jun 30, 2024
67b75a7
Reorder import statements in UserDataService
Pdzly Jul 2, 2024
abd18c6
Add authorization to instance config actions
Pdzly Jul 5, 2024
3769ed4
Refactor moderation models and update relevant methods
Pdzly Jul 6, 2024
b3be4a2
Add post aggregate functionality
Pdzly Jul 6, 2024
68da5cb
Update moderation actions from "remove" to "pin"
Pdzly Jul 7, 2024
4cf90cb
Add purge community operation and update delete action summary
Pdzly Jul 7, 2024
9afff74
Add post pinning, community pinning, and post purging methods
Pdzly Jul 9, 2024
015d23e
Update permissions and search functionalities in API
Pdzly Jul 15, 2024
230837a
Remove "purge" functionality and cleanup controllers
Pdzly Jul 15, 2024
0559f32
Change request mapping in SublinksPostAggregateController
Pdzly Jul 16, 2024
7c55988
Merge branch 'refs/heads/main' into issue/119-native-api
Pdzly Jul 29, 2024
c4e12ed
Enhance role management and authorization handling.
Pdzly Aug 2, 2024
3a74604
Update role management and ACL services for role expiration
Pdzly Aug 4, 2024
07c22d8
Refactor RequestResponse imports and enhance RolesController
Pdzly Aug 4, 2024
b1fe484
Merge branch 'refs/heads/main' into issue/119-native-api
Pdzly Aug 4, 2024
341daf8
Add inheritance support to roles and enhance role mapping.
Pdzly Aug 6, 2024
efb22c1
Enable Hikari pool suspension and update transactional annotations
Pdzly Aug 6, 2024
ba4f7d0
Refactor role saving to use saveAndFlush
Pdzly Aug 6, 2024
89e2b8d
Refactor role and permissions mapping for improved handling
Pdzly Aug 7, 2024
c058838
Enhance mapper configurations and simplify role permission logic
Pdzly Aug 8, 2024
d3be423
Refactor role service pagination and formatting of controller methods
Pdzly Aug 8, 2024
f364f08
Add missing newline for better readability
Pdzly Aug 8, 2024
9510654
Add purge post functionality to moderation
Pdzly Aug 9, 2024
eecb193
Implement purge post placeholder in SublinksPostService
Pdzly Aug 9, 2024
2625aae
Refactor method parameter name in purge method
Pdzly Aug 9, 2024
4172499
Add @NonNull annotations and comprehensive JavaDocs
Pdzly Aug 9, 2024
528cc2f
Adjust pagination to start from the first page.
Pdzly Aug 9, 2024
42662ce
Add SublinksCommentSortTypeMapper and refactor sort type logic
Pdzly Aug 9, 2024
a0c129d
Refactor comment entities and service methods
Pdzly Aug 11, 2024
700476e
Remove replies field from CommentResponse model
Pdzly Aug 11, 2024
15a53ea
Remove @Builder annotation from CommentResponse
Pdzly Aug 11, 2024
ebb7e41
Add instance data to PersonResponse and improve search handling
Pdzly Aug 11, 2024
eaad440
Refactor comment handling and clean up unused dependencies
Pdzly Aug 12, 2024
b79b558
Clarify comment handling in buildHierarchy method
Pdzly Aug 12, 2024
c4007d1
Fix incomplete comment in SublinksCommentService.java
Pdzly Aug 12, 2024
96cff2e
Fix typos in comment structuring logic documentation.
Pdzly Aug 12, 2024
fa2fed4
Refactor pagination logic and improve SQL query
Pdzly Aug 12, 2024
81bc5d8
Standardize API tags and refactor unauthorized exception
Pdzly Aug 12, 2024
53dd65a
Add Swagger annotations to community models
Pdzly Aug 13, 2024
66d4ee9
Add Swagger annotations to CommentResponse and UpdateComment
Pdzly Aug 14, 2024
cfa198a
Add Swagger annotations and rename model class
Pdzly Aug 14, 2024
04a03be
Fix indentation in SublinksCommentAggregateController
Pdzly Aug 19, 2024
6e4f6ef
Merge branch 'main' into issue/119-native-api
Pdzly Aug 19, 2024
9e0f129
Remove RolePermissionService from SublinksCommentModerationController
Pdzly Aug 26, 2024
2dbeae8
Add token handling to session management
Pdzly Sep 5, 2024
f0d250f
Format code for consistency in SublinksAnnouncementService
Pdzly Sep 19, 2024
1c0587a
Add JWT token to SublinksJwtPerson object
Pdzly Oct 12, 2024
caba87b
LINT
Pdzly Oct 18, 2024
b855280
Change submodule URL for 'docker' repository
Pdzly Oct 18, 2024
8de8fcd
Change submodule URL for 'docker' repository
Pdzly Oct 18, 2024
1da86ae
Add password encryption in SublinksPersonService
Pdzly Oct 18, 2024
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
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ ij_java_message_dd_suffix = EJB
ij_java_message_eb_prefix =
ij_java_message_eb_suffix = Bean
ij_java_method_annotation_wrap = split_into_lines
ij_java_method_brace_style = end_of_line
ij_java_method_brace_style = next_line_if_wrapped
ij_java_method_call_chain_wrap = split_into_lines
ij_java_method_parameters_new_line_after_left_paren = false
ij_java_method_parameters_right_paren_on_new_line = false
Expand All @@ -200,7 +200,7 @@ ij_java_multi_catch_types_wrap = normal
ij_java_names_count_to_use_import_on_demand = 999
ij_java_new_line_after_lparen_in_annotation = false
ij_java_new_line_after_lparen_in_deconstruction_pattern = true
ij_java_new_line_after_lparen_in_record_header = false
ij_java_new_line_after_lparen_in_record_header = true
ij_java_packages_to_use_import_on_demand =
ij_java_parameter_annotation_wrap = on_every_item
ij_java_parameter_name_prefix =
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
testImplementation 'org.springframework.amqp:spring-rabbit-test'

annotationProcessor "org.hibernate:hibernate-jpamodelgen:6.5.2.Final"
implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.8.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.util.UrlPathHelper;

/**
* Application Boot.
Expand All @@ -34,13 +36,17 @@ public static void main(String[] args) {
@Bean
public OpenAPI customOpenAPI() {

return new OpenAPI().components(new Components().addSecuritySchemes("bearerAuth",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT")));
return new OpenAPI()
.components(new Components()
.addSecuritySchemes("bearerAuth",
new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")));
}

@Bean
public GroupedOpenApi v3OpenApi(@Value("${springdoc.version}") String appVersion,
@Value("${springdoc.pathsToMatch}") String pathsToMatch,
public GroupedOpenApi v3LemmyApi(@Value("${springdoc.version}") String appVersion,
@Value("#{${springdoc.servers}}") List<String> servers) {

return GroupedOpenApi.builder()
Expand All @@ -52,7 +58,30 @@ public GroupedOpenApi v3OpenApi(@Value("${springdoc.version}") String appVersion
.addOpenApiCustomizer(openApi -> openApi.info(
new Info().title("Lemmy OpenAPI Documentation").version(appVersion))
.servers(servers.stream().map(s -> new Server().url(s)).toList()))
.pathsToMatch(pathsToMatch)
.pathsToMatch("/api/v3/**")
.build();
}

@Bean
public GroupedOpenApi v1SublinksApi(@Value("${springdoc.version}") String appVersion,
@Value("#{${springdoc.servers}}") List<String> servers) {

return GroupedOpenApi.builder().group("v1")
.addOperationCustomizer((operation, handlerMethod) -> {
operation.addSecurityItem(new SecurityRequirement().addList("bearerAuth"));
return operation;
})
.addOpenApiCustomizer(openApi -> openApi.info(new Info()
.title("OpenAPI Documentation")
.version(appVersion))
.servers(servers.stream().map(s -> new Server().url(s)).toList()))
.pathsToMatch("/api/v1/**")
.build();
}

public void configurePathMatch(PathMatchConfigurer configurer) {
UrlPathHelper urlPathHelper = new UrlPathHelper();
urlPathHelper.setUrlDecode(false);
configurer.setUrlPathHelper(urlPathHelper);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.sublinks.sublinksapi.announcement.entities;

import com.sublinks.sublinksapi.person.entities.Person;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.util.Objects;
import lombok.AllArgsConstructor;
Expand All @@ -29,6 +32,13 @@
@Table(name = "announcements")
public class Announcement {

/**
* Relationships.
*/
@ManyToOne
@JoinColumn(name = "creator_id")
private Person creator;

/**
* Attributes.
*/
Expand All @@ -39,6 +49,9 @@ public class Announcement {
@Column(name = "content")
private String content;

@Column(name = "is_active")
private Boolean active;

@Column(name = "local_site_id")
private Long localSiteId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;

import java.util.List;

import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -144,13 +146,13 @@ AddAdminResponse create(@Valid @RequestBody final AddAdmin addAdminForm, JwtPers
@GetMapping("registration_application/count")
GetUnreadRegistrationApplicationCountResponse registrationApplicationCount(
@Valid GetUnreadRegistrationApplicationCount getUnreadRegistrationApplicationCountForm,
JwtPerson principal) {
JwtPerson principal)
{

final Person person = getPersonOrThrowUnauthorized(principal);

aclService.canPerson(person)
.performTheAction(RolePermissionInstanceTypes.INSTANCE_REMOVE_ADMIN)

.orElseThrow(() -> new ResponseStatusException(HttpStatus.UNAUTHORIZED, "unauthorized"));

return GetUnreadRegistrationApplicationCountResponse.builder()
Expand All @@ -168,7 +170,8 @@ GetUnreadRegistrationApplicationCountResponse registrationApplicationCount(
@GetMapping("registration_application/list")
ListRegistrationApplicationsResponse registrationApplicationList(
@Valid final ListRegistrationApplications listRegistrationApplicationsForm,
JwtPerson principal) {
JwtPerson principal)
{

final Person person = getPersonOrThrowUnauthorized(principal);

Expand All @@ -194,7 +197,8 @@ ListRegistrationApplicationsResponse registrationApplicationList(
@PutMapping("registration_application/approve")
RegistrationApplicationResponse registrationApplicationApprove(
@Valid final ApproveRegistrationApplication approveRegistrationApplicationForm,
final JwtPerson principal) {
final JwtPerson principal)
{

final Person person = getPersonOrThrowUnauthorized(principal);

Expand Down Expand Up @@ -231,7 +235,8 @@ RegistrationApplicationResponse registrationApplicationApprove(
schema = @Schema(implementation = PurgeItemResponse.class))})})
@PostMapping("purge/person")
PurgeItemResponse purgePerson(@Valid @RequestBody final PurgePerson purgePersonForm,
final JwtPerson principal) {
final JwtPerson principal)
{

final Person person = getPersonOrThrowUnauthorized(principal);

Expand All @@ -242,8 +247,6 @@ PurgeItemResponse purgePerson(@Valid @RequestBody final PurgePerson purgePersonF
final Person personToPurge = personRepository.findById((long) purgePersonForm.person_id())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "person_not_found"));

final int removedPostHistory = postHistoryService.deleteAllByCreator(personToPurge);
final int removedCommentHistory = commentHistoryService.deleteAllByCreator(personToPurge);
// @todo: Log purged history amount?
// @todo: Implement purging

Expand All @@ -257,7 +260,8 @@ PurgeItemResponse purgePerson(@Valid @RequestBody final PurgePerson purgePersonF
schema = @Schema(implementation = PurgeItemResponse.class))})})
@PostMapping("purge/community")
PurgeItemResponse purgeCommunity(@Valid @RequestBody final PurgeCommunity purgeCommunityForm,
final JwtPerson principal) {
final JwtPerson principal)
{

final Person person = getPersonOrThrowUnauthorized(principal);

Expand All @@ -275,7 +279,8 @@ PurgeItemResponse purgeCommunity(@Valid @RequestBody final PurgeCommunity purgeC
schema = @Schema(implementation = PurgeItemResponse.class))})})
@PostMapping("purge/post")
PurgeItemResponse purgePost(@Valid @RequestBody final PurgePost purgePostForm,
final JwtPerson principal) {
final JwtPerson principal)
{

final Person person = getPersonOrThrowUnauthorized(principal);

Expand All @@ -302,7 +307,8 @@ PurgeItemResponse purgePost(@Valid @RequestBody final PurgePost purgePostForm,
schema = @Schema(implementation = PurgeItemResponse.class))})})
@PostMapping("purge/comment")
PurgeItemResponse purgeComment(@Valid @RequestBody final PurgeComment purgeCommentForm,
final JwtPerson principal) {
final JwtPerson principal)
{

final Person person = getPersonOrThrowUnauthorized(principal);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
Expand All @@ -19,9 +20,10 @@
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
@Order(2)
public class SecurityConfig {

private final JwtFilter jwtFilter;
private final JwtFilter lemmyJwtFilter;

/**
* Returns a configured SecurityFilterChain object for the application's security.
Expand All @@ -33,13 +35,14 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(final HttpSecurity http) throws Exception {

http
.csrf(AbstractHttpConfigurer::disable)
.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class)
http.csrf(AbstractHttpConfigurer::disable)
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Show resolved Hide resolved
.securityMatcher("/api/v3/**")
.authorizeHttpRequests((requests) -> requests.anyRequest()
.permitAll())
.sessionManagement((sessionManagement) -> sessionManagement.sessionCreationPolicy(
SessionCreationPolicy.STATELESS));
SessionCreationPolicy.STATELESS))
.addFilterBefore(lemmyJwtFilter, UsernamePasswordAuthenticationFilter.class);

return http.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Person getPersonOrThrowBadRequest(JwtPerson principal) throws ResponseSta
* @throws ResponseStatusException Exception thrown when Person not present
*/
public <X extends Throwable> Person getPersonOrThrow(JwtPerson principal,
Supplier<? extends X> exceptionSupplier) throws X {
Supplier<? extends X> exceptionSupplier) throws X {

return Optional.ofNullable(principal).map(p -> (Person) p.getPrincipal())
.orElseThrow(exceptionSupplier);
Expand Down
Loading