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

[#153] add footer (internationalized) #161

Draft
wants to merge 43 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
21cba49
add footer
Jul 1, 2023
af37166
fix 'Not Found' error when adding user to wks
Jul 2, 2023
c1d9992
add tool versions for asdf
fey Jul 3, 2023
f479d43
fix widget script
fey Jul 3, 2023
087ca3d
Merge pull request #164 from fey/fix-widget-form
fey Jul 3, 2023
a5132e3
Merge pull request #163 from RedGradient/fix-redirect-after-adding-user
Malcom1986 Jul 4, 2023
f48ef44
add dockerfile
Jun 21, 2023
e583e35
fix
Jun 22, 2023
b152990
fix dockerfile
Jun 22, 2023
a9d323e
add cors configuration
Jul 4, 2023
ab8374a
fix typo path in script
Jul 4, 2023
b59b9ad
Merge pull request #169 from Hexlet/cors-1
fey Jul 4, 2023
9f65100
add Thymeleaf Layout dialect dependency
Jul 4, 2023
3a29ccf
rename: header.html -> head.html
Jul 4, 2023
c15f424
make templating with layouts
Jul 4, 2023
37ffe12
rename: head.html -> header.html
Jul 4, 2023
793e90b
Create requirements.yml
Salivya Jul 6, 2023
4205518
Update requirements.yml
Salivya Jul 6, 2023
1ef4a32
Update requirements.yml по комментариям пользователя fey
Salivya Jul 11, 2023
c861461
Merge pull request #171 from Salivya/Salivya-patch-1
fey Jul 11, 2023
c5c91a4
Update widget code
fey Jul 12, 2023
5574b45
remove requirements.yml to docs
AavadaKedavra Jul 14, 2023
60670c3
Issue179 - Удаление пользователя из воркспейса
AlekseyNechunaev Jul 15, 2023
ced7e2a
Issue179 - Убрал обращение к репозиторию из контроллера
AlekseyNechunaev Jul 16, 2023
814efa2
Issue165 - Убрал лишнее
AlekseyNechunaev Jul 16, 2023
359dee0
Merge pull request #182 from AavadaKedavra/444_add_test_cases
fey Jul 17, 2023
1cb4813
Issue179 - Правки по ревью, переместил кнопку удаления в таблицу
AlekseyNechunaev Jul 19, 2023
e494cea
Issue179 - Правки по ревью, изменил стиль кнопки удаления, добавил мо…
AlekseyNechunaev Jul 19, 2023
a76e651
move out styles from html to separate css file
Jul 19, 2023
d8960f3
[#181] fix workspace cards height
asenka0301 Jul 20, 2023
c0a4737
Merge pull request #183 from AlekseyNechunaev/feature/nechunaev/Issue179
Malcom1986 Jul 20, 2023
c71929b
use bootstrap classes instead of custom css properties
Jul 20, 2023
585f48f
Merge pull request #186 from asenka0301/frontend/fix-workspace-cards-…
fey Jul 20, 2023
b5e0b63
make templating with layouts
Jul 20, 2023
11fc6d7
add footer
Jul 1, 2023
3f07e5b
add Thymeleaf Layout dialect dependency
Jul 4, 2023
09c8c0d
rename: header.html -> head.html
Jul 4, 2023
0c5ef95
make templating with layouts
Jul 4, 2023
45ac594
rename: head.html -> header.html
Jul 4, 2023
57951cf
move out styles from html to separate css file
Jul 19, 2023
70ceb12
use bootstrap classes instead of custom css properties
Jul 20, 2023
668d6d7
make templating with layouts
Jul 20, 2023
e930cdb
Merge remote-tracking branch 'origin/add-footer' into add-footer
Jul 20, 2023
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 .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java openjdk-19.0.2
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM maven:3.9.2-eclipse-temurin-20 AS build


# CMD mvn spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=prod,--server.port=$PORT"


#
# Build stage
#

COPY . .
RUN mvn clean package -DskipTests

#
# Package stage
#
# FROM openjdk:20-jdk-slim
# COPY --from=build ./target/typoreporter-*.jar typoreporter.jar

CMD java -Xmx256m -jar target/typoreporter-*.jar --spring.profiles.active=default,prod --server.port=$PORT
26 changes: 26 additions & 0 deletions docs/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
functional:
- Пользователь должен иметь возможность зарегестрироваться в приложении.
- Пользователь должен иметь возможность добавить скрипт на свой сайт.
- На сервисе, в личном аккаунте пользователя, должны отображаться ошибки, которые нашли на сайтах пользователя.
- Пользователь должен иметь возможность отслеживать статус ошибок, найденных на своем сайте, через сервис. #отправлено, в работе,решено, отменено, всего
- Пользователь должен иметь возможность корректировать ошибки через сервис.
- Пользователь должен иметь возможность просматривать пространства, которые он создал.
- Пользователь не должен иметь возможность просматривать пространства, созданные другими пользователями.
- Пользователь должен иметь возможность дать имя пространству.
- Пользователь должен иметь возможность описать пространство.
- Пользователь должен иметь возможность добавлять пользователей в созданное пространство.
- Должна быть возможность просматривать информацию об аккаунте.
- Должна быть возможность изменять информацию об аккаунте #ФИО,почту, пароль
non-functional:
- Сервис должен быть разработан с учетом удобства использования и оптимизирован для скорости работы.
- Сервис должен быть доступен на различных устройствах.
- Сервис должен иметь мобильную версию.
- Сервис должен быть безопасным и защищать данные пользователя.
- Сервис должен быть протестирован на совместимость с последними версиями браузеров.
- Сервис должен должен быть способен обрабатывать большое количество трафика.
- Информация на сайте должна быть представлена на русском и английском языках.
implicit:
- Сервис содержит функцию "теста" #новый пользователь мог бы иметь возможность сам себе отправить ошибку и посмотреть как работает сервис
- Сервис содержит инструкцию по установке скрипта на свой сайт
- Сервис содержит инструкцию по работе в личном кабинете пользователя
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>3.2.1</version>
</dependency>
<!-- WebJars -->
<dependency>
<groupId>org.webjars</groupId>
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/io/hexlet/typoreporter/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import org.springframework.security.web.context.RequestAttributeSecurityContextRepository;
import org.springframework.security.web.context.SecurityContextRepository;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import java.util.List;

import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
Expand Down Expand Up @@ -73,7 +77,7 @@ public SecurityFilterChain filterChain(HttpSecurity http,
http.exceptionHandling().accessDeniedHandler(accessDeniedHandler());

http.authorizeHttpRequests(authz -> authz
.requestMatchers(GET, "/webjars/**", "/widget/**", "/fragments/**", "/img/**").permitAll()
.requestMatchers(GET, "/webjars/**", "/widget/**", "/fragments/**", "/css/**", "/img/**").permitAll()
.requestMatchers("/", "/login", "/signup", "/error").permitAll()
.anyRequest().authenticated()
)
Expand All @@ -99,4 +103,17 @@ public SecurityFilterChain filterChain(HttpSecurity http,
public AccessDeniedHandler accessDeniedHandler() {
return new CustomAccessDeniedHandler();
}

@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
// TODO: allow sending a request only from the pages specified in the Workspace settings
configuration.addAllowedOriginPattern("*");
configuration.addAllowedHeader("*");
configuration.setAllowCredentials(true);
configuration.setAllowedMethods(List.of("POST", "GET"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public Account addWorkspaceRole(WorkspaceRole workspaceRole) {
return this;
}

public void removeWorkSpaceRole(WorkspaceRole workspaceRole) {
workspaceRoles.remove(workspaceRole);
workspaceRole.setAccount(null);
}

@Override
public boolean equals(Object o) {
return this == o || id != null && o instanceof Account other && id.equals(other.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public Workspace addWorkspaceRole(WorkspaceRole workspaceRole) {
return this;
}

public void removeWorkSpaceRole(WorkspaceRole workspaceRole) {
workspaceRoles.remove(workspaceRole);
workspaceRole.setWorkspace(null);
}

@Override
public int hashCode() {
return getClass().hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface WorkspaceRoleRepository extends JpaRepository<WorkspaceRole, Long> {
Expand All @@ -18,4 +19,7 @@ public interface WorkspaceRoleRepository extends JpaRepository<WorkspaceRole, Lo

@EntityGraph(attributePaths = {"account", "workspace"})
List<WorkspaceRole> getWorkspaceRolesByWorkspaceId(Long workspaceId);

@EntityGraph(attributePaths = {"account", "workspace"})
Optional<WorkspaceRole> getWorkspaceRoleByAccountIdAndWorkspaceId(Long accountId, Long workspaceId);
}
12 changes: 12 additions & 0 deletions src/main/java/io/hexlet/typoreporter/service/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.hexlet.typoreporter.service.mapper.AccountMapper;
import io.hexlet.typoreporter.service.mapper.WorkspaceRoleMapper;
import io.hexlet.typoreporter.web.exception.AccountAlreadyExistException;
import io.hexlet.typoreporter.web.exception.AccountNotFoundException;
import io.hexlet.typoreporter.web.exception.NewPasswordTheSameException;
import io.hexlet.typoreporter.web.exception.OldPasswordWrongException;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -87,6 +88,17 @@ public Optional<UpdateProfile> getUpdateProfile(final String name) {
.map(accountMapper::toUpdateProfile);
}

@Transactional(readOnly = true)
public List<Account> findAll() {
return accountRepository.findAll();
}

@Transactional(readOnly = true)
public Account findByUsername(String userName) {
return accountRepository.findAccountByUsername(userName)
.orElseThrow(() -> new AccountNotFoundException(userName));
}

public Optional<Account> updateProfile(final UpdateProfile updateProfile, final String name) {
final var sourceAccount = accountRepository.findAccountByUsername(name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.hexlet.typoreporter.repository.WorkspaceRoleRepository;
import io.hexlet.typoreporter.web.exception.AccountNotFoundException;
import io.hexlet.typoreporter.web.exception.WorkspaceNotFoundException;
import io.hexlet.typoreporter.web.exception.WorkspaceRoleNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -19,7 +20,7 @@
@RequiredArgsConstructor
public class WorkspaceRoleService {

private final WorkspaceRoleRepository repository;
private final WorkspaceRoleRepository workspaceRoleRepository;

private final WorkspaceRepository workspaceRepository;

Expand All @@ -41,6 +42,23 @@ public WorkspaceRole addAccountToWorkspace(String wksName, String accEmail) {
workspaceRepository.getReferenceById(wksId),
accountRepository.getReferenceById(accId)
);
return repository.save(workspaceRole);
return workspaceRoleRepository.save(workspaceRole);
}

@Transactional
public void deleteAccountFromWorkspace(String workspaceName, String accountEmail) {
final var account = accountRepository.findAccountByEmail(accountEmail)
.orElseThrow(() -> new AccountNotFoundException(accountEmail));
final var workspace = workspaceRepository.getWorkspaceByName(workspaceName)
.orElseThrow(() -> new WorkspaceNotFoundException(workspaceName));
final var beingDeleteRole = workspaceRoleRepository.getWorkspaceRoleByAccountIdAndWorkspaceId(
account.getId(),
workspace.getId())
.orElseThrow(() -> new WorkspaceRoleNotFoundException(account.getId(), workspace.getId()));
account.removeWorkSpaceRole(beingDeleteRole);
workspace.removeWorkSpaceRole(beingDeleteRole);
accountRepository.save(account);
workspaceRepository.save(workspace);
}

}
17 changes: 17 additions & 0 deletions src/main/java/io/hexlet/typoreporter/service/WorkspaceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import io.hexlet.typoreporter.domain.workspacesettings.WorkspaceSettings;
import io.hexlet.typoreporter.repository.AccountRepository;
import io.hexlet.typoreporter.repository.WorkspaceRepository;
import io.hexlet.typoreporter.repository.WorkspaceRoleRepository;
import io.hexlet.typoreporter.repository.WorkspaceSettingsRepository;
import io.hexlet.typoreporter.service.dto.workspace.CreateWorkspace;
import io.hexlet.typoreporter.service.dto.workspace.WorkspaceInfo;
import io.hexlet.typoreporter.service.mapper.WorkspaceMapper;
import io.hexlet.typoreporter.web.exception.AccountNotFoundException;
import io.hexlet.typoreporter.web.exception.WorkspaceAlreadyExistException;
import io.hexlet.typoreporter.web.exception.WorkspaceNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -35,6 +38,7 @@ public class WorkspaceService {
private final WorkspaceMapper workspaceMapper;

private final AccountRepository accountRepository;
private final WorkspaceRoleRepository workspaceRoleRepository;

@Transactional(readOnly = true)
public List<WorkspaceInfo> getAllWorkspacesInfo() {
Expand Down Expand Up @@ -124,4 +128,17 @@ public boolean isUserRelatedToWorkspace(String wksName, String username) {
.anyMatch(wks -> wks.getName().equals(wksName)))
.orElse(false);
}

@Transactional(readOnly = true)
public boolean isAdminRoleUserInWorkspace(String wksName, String username) {
final var account = accountRepository.findAccountByUsername(username).
orElseThrow(() -> new AccountNotFoundException(username));
final var workspace = repository.getWorkspaceByName(wksName).
orElseThrow(() -> new WorkspaceNotFoundException(wksName));
final var workSpaceRoleOptional = workspaceRoleRepository.getWorkspaceRoleByAccountIdAndWorkspaceId(
account.getId(),
workspace.getId()
);
return workSpaceRoleOptional.filter(workspaceRole -> workspaceRole.getRole() == AccountRole.ROLE_ADMIN).isPresent();
}
}
5 changes: 0 additions & 5 deletions src/main/java/io/hexlet/typoreporter/web/WorkspaceApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public class WorkspaceApi {
private final TypoService service;

@PostMapping("/{id}/typos")
// TODO: allow sending a request only from the pages specified in the Workspace settings
@CrossOrigin(
originPatterns = {"*"},
allowCredentials = "true"
)
public ResponseEntity<ReportedTypo> addTypoReport(@PathVariable long id,
Authentication authentication,
@Valid @RequestBody TypoReport typoReport,
Expand Down
Loading