delete Group
This commit is contained in:
parent
baa42f0cc8
commit
3881f9b15f
@ -32,7 +32,7 @@ export class GroupService {
|
|||||||
this.api.postList(['Group', 'findAllCommon'], uuid, Group.fromJson, next);
|
this.api.postList(['Group', 'findAllCommon'], uuid, Group.fromJson, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
findAllJoined(next: Next<Group[]>) {
|
findAllJoined(next: Next<Group[]>): void {
|
||||||
this.api.getList(['Group', 'findAllJoined'], Group.fromJson, next);
|
this.api.getList(['Group', 'findAllJoined'], Group.fromJson, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ export class GroupService {
|
|||||||
this.api.getSingle(['Group', 'create'], Group.fromJson, next);
|
this.api.getSingle(['Group', 'create'], Group.fromJson, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeTitle(group: Group, title: string, next?: Next<Group>) {
|
changeTitle(group: Group, title: string, next?: Next<Group>): void {
|
||||||
const data = {
|
const data = {
|
||||||
uuid: group.uuid,
|
uuid: group.uuid,
|
||||||
title: title,
|
title: title,
|
||||||
@ -48,7 +48,7 @@ export class GroupService {
|
|||||||
this.api.postSingle(['Group', 'changeTitle'], data, Group.fromJson, next);
|
this.api.postSingle(['Group', 'changeTitle'], data, Group.fromJson, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
changePassword(group: Group, password: string, next?: Next<Group>) {
|
changePassword(group: Group, password: string, next?: Next<Group>): void {
|
||||||
const data = {
|
const data = {
|
||||||
uuid: group.uuid,
|
uuid: group.uuid,
|
||||||
password: password,
|
password: password,
|
||||||
@ -68,7 +68,7 @@ export class GroupService {
|
|||||||
this.api.postNone(['Group', 'leave'], group, next);
|
this.api.postNone(['Group', 'leave'], group, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
goto(uuid: string) {
|
goto(uuid: string): void {
|
||||||
this.router.navigate(['Group', uuid]);
|
this.router.navigate(['Group', uuid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,5 +76,13 @@ export class GroupService {
|
|||||||
return new Subscribed<Group>(Group.sameUuid, (group, next) => this.api.subscribe(['Group', group.uuid], Group.fromJson, next));
|
return new Subscribed<Group>(Group.sameUuid, (group, next) => this.api.subscribe(['Group', group.uuid], Group.fromJson, next));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gotoGroups(): void {
|
||||||
|
this.router.navigate(['Groups']);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(group: Group, next: Next<void>): void {
|
||||||
|
this.api.postNone(['Group', 'delete'], group.uuid, next);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -68,6 +68,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="tile" *ngIf="userService.iOwn(group.value)">
|
||||||
|
<div class="tileInner">
|
||||||
|
<div class="tileTitle">
|
||||||
|
Löschen
|
||||||
|
</div>
|
||||||
|
<div class="tileContent">
|
||||||
|
<button (click)="delete(group.value)">
|
||||||
|
Löschen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -80,18 +80,22 @@ export class GroupComponent implements OnInit, OnDestroy {
|
|||||||
this.group.unsubscribe();
|
this.group.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected changeTitle(group: Group, title: string) {
|
protected changeTitle(group: Group, title: string): void {
|
||||||
this.groupService.changeTitle(group, title, group => this.group.value = group);
|
this.groupService.changeTitle(group, title, group => this.group.value = group);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected changePassword(group: Group, password: string) {
|
protected changePassword(group: Group, password: string): void {
|
||||||
this.groupService.changePassword(group, password, group => this.group.value = group);
|
this.groupService.changePassword(group, password, group => this.group.value = group);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected join(password: string) {
|
protected join(password: string): void {
|
||||||
if (this.uuid) {
|
if (this.uuid) {
|
||||||
this.groupService.join(this.uuid, password, group => this.group.value = group);
|
this.groupService.join(this.uuid, password, group => this.group.value = group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected delete(group: Group): void {
|
||||||
|
this.groupService.delete(group, () => this.groupService.gotoGroups());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ public class Group extends GroupAbstract implements IWebSocketMessage {
|
|||||||
private String uuid = UUID.randomUUID().toString();
|
private String uuid = UUID.randomUUID().toString();
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
|
@ToString.Exclude
|
||||||
private GroupUuid _uuid;
|
private GroupUuid _uuid;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -37,9 +38,16 @@ public class Group extends GroupAbstract implements IWebSocketMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ToString.Exclude
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
private User owner;
|
private User owner;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@ToString.Include
|
||||||
|
public String ownerPublicUuid() {
|
||||||
|
return getOwner().getPublicUuid().toString();
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private ZonedDateTime created = ZonedDateTime.now();
|
private ZonedDateTime created = ZonedDateTime.now();
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package de.ph87.tools.group;
|
package de.ph87.tools.group;
|
||||||
|
|
||||||
import de.ph87.tools.group.uuid.GroupUuid;
|
import de.ph87.tools.group.uuid.GroupUuid;
|
||||||
|
import de.ph87.tools.tools.numbers.NumbersRepository;
|
||||||
import de.ph87.tools.user.User;
|
import de.ph87.tools.user.User;
|
||||||
import de.ph87.tools.user.UserService;
|
import de.ph87.tools.user.UserService;
|
||||||
import de.ph87.tools.user.uuid.UserPrivateUuid;
|
import de.ph87.tools.user.uuid.UserPrivateUuid;
|
||||||
@ -23,7 +24,9 @@ public class GroupAccessService {
|
|||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
public boolean canAccess(@NonNull final GroupUuid groupUuid, @Nullable final UserPrivateUuid userPrivateUuid) {
|
private final NumbersRepository numbersRepository;
|
||||||
|
|
||||||
|
public boolean canAccess(@Nullable final UserPrivateUuid userPrivateUuid, @NonNull final GroupUuid groupUuid) {
|
||||||
final User user = userService.accessOrNull(userPrivateUuid);
|
final User user = userService.accessOrNull(userPrivateUuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -32,6 +35,13 @@ public class GroupAccessService {
|
|||||||
return group.getUsers().contains(user);
|
return group.getUsers().contains(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete(@NonNull final UserPrivateUuid userPrivateUuid, @NonNull final GroupUuid groupUuid) {
|
||||||
|
final GroupAccess groupAccess = accessAsOwner(userPrivateUuid, groupUuid);
|
||||||
|
numbersRepository.deleteAllByGroup(groupAccess.group);
|
||||||
|
groupRepository.delete(groupAccess.group);
|
||||||
|
log.info("Group deleted: group={}", groupAccess.group);
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public GroupAccess access(@NonNull final UserPrivateUuid userPrivateUuid, @NonNull final GroupUuid groupUuid) {
|
public GroupAccess access(@NonNull final UserPrivateUuid userPrivateUuid, @NonNull final GroupUuid groupUuid) {
|
||||||
final User user = userService.access(userPrivateUuid);
|
final User user = userService.access(userPrivateUuid);
|
||||||
@ -39,12 +49,13 @@ public class GroupAccessService {
|
|||||||
return new GroupAccess(user, group);
|
return new GroupAccess(user, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public GroupAccess accessAsOwner(@NonNull final UserPrivateUuid userPrivateUuid, @NonNull final GroupUuid groupUuid) {
|
public GroupAccess accessAsOwner(@NonNull final UserPrivateUuid userPrivateUuid, @NonNull final GroupUuid groupUuid) {
|
||||||
final GroupAccess access = access(userPrivateUuid, groupUuid);
|
final GroupAccess groupAccess = access(userPrivateUuid, groupUuid);
|
||||||
if (!access.group.isOwnedBy(access.user)) {
|
if (!groupAccess.group.isOwnedBy(groupAccess.user)) {
|
||||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
return access;
|
return groupAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|||||||
@ -31,7 +31,12 @@ public class GroupController {
|
|||||||
|
|
||||||
@PostMapping("canAccess")
|
@PostMapping("canAccess")
|
||||||
public boolean canAccess(@Nullable final UserPrivateUuid privateUuid, @NonNull final GroupUuid groupUuid) {
|
public boolean canAccess(@Nullable final UserPrivateUuid privateUuid, @NonNull final GroupUuid groupUuid) {
|
||||||
return groupAccessService.canAccess(groupUuid, privateUuid);
|
return groupAccessService.canAccess(privateUuid, groupUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("delete")
|
||||||
|
public void delete(@NonNull final UserPrivateUuid privateUuid, @NonNull final GroupUuid groupUuid) {
|
||||||
|
groupAccessService.delete(privateUuid, groupUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("get")
|
@PostMapping("get")
|
||||||
|
|||||||
@ -11,4 +11,6 @@ public interface NumbersRepository extends ListCrudRepository<Numbers, String> {
|
|||||||
@NonNull
|
@NonNull
|
||||||
Page<Numbers> findAllByGroup(@NonNull Group group, @NonNull Pageable pageable);
|
Page<Numbers> findAllByGroup(@NonNull Group group, @NonNull Pageable pageable);
|
||||||
|
|
||||||
|
void deleteAllByGroup(@NonNull Group group);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user