fix stuff
by breaking it
This commit is contained in:
parent
4804892f42
commit
66ead17348
8 changed files with 52 additions and 22 deletions
|
@ -1,5 +1,6 @@
|
|||
package eu.m724.talkpages;
|
||||
|
||||
import eu.m724.talkpages.auth.AuthService;
|
||||
import eu.m724.talkpages.orm.entity.auth.Account;
|
||||
import eu.m724.talkpages.orm.entity.content.Page;
|
||||
import eu.m724.talkpages.orm.entity.content.PageRevision;
|
||||
|
@ -19,6 +20,9 @@ public class Startup {
|
|||
@Inject
|
||||
private ThemeService themeService;
|
||||
|
||||
@Inject
|
||||
private AuthService authService;
|
||||
|
||||
@ConfigProperty(name = "talkpages.systemUser.name")
|
||||
private String username;
|
||||
|
||||
|
@ -42,6 +46,12 @@ public class Startup {
|
|||
|
||||
System.out.println("Performing first run setup");
|
||||
|
||||
try {
|
||||
authService.register("user", "1234");
|
||||
} catch (AuthService.UsernameExistsException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Account account = new Account(username);
|
||||
account.persistAndFlush();
|
||||
|
||||
|
@ -58,12 +68,12 @@ public class Startup {
|
|||
@Transactional
|
||||
public Page addPage(Account account, String title, String content) {
|
||||
Page page = new Page(title);
|
||||
PageRevision revision = new PageRevision(page, account, content);
|
||||
PageRevision revision = new PageRevision(page, content);
|
||||
revision.setAuthor(account);
|
||||
|
||||
page.setLatestRevision(revision);
|
||||
page.persistAndFlush();
|
||||
|
||||
account.getRevisions().add(revision);
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class AuthService {
|
|||
* @throws UsernameExistsException if user with same username already exists
|
||||
*/
|
||||
@Transactional
|
||||
Session register(String username, String password) throws UsernameExistsException {
|
||||
public Session register(String username, String password) throws UsernameExistsException {
|
||||
Account account = Account.findByName(username);
|
||||
|
||||
if (account != null) {
|
||||
|
|
|
@ -59,12 +59,9 @@ public class Account extends PanacheEntity {
|
|||
|
||||
private Set<String> roles = new HashSet<>();
|
||||
|
||||
@OneToMany(orphanRemoval = true, cascade = CascadeType.ALL)
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private Set<Session> sessions = new HashSet<>();
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = false, fetch = FetchType.EAGER)
|
||||
private List<PageRevision> revisions = new ArrayList<>();
|
||||
|
||||
|
||||
// Getters
|
||||
|
||||
|
@ -73,11 +70,18 @@ public class Account extends PanacheEntity {
|
|||
public String getPassword() { return password; }
|
||||
public Set<String> getRoles() { return roles; }
|
||||
public Set<Session> getSessions() { return sessions; }
|
||||
public List<PageRevision> getRevisions() { return revisions; }
|
||||
|
||||
public boolean isSystemAccount() { return password == null; }
|
||||
|
||||
|
||||
public List<PageRevision> getRevisions() {
|
||||
return PageRevision.find("author", this).list();
|
||||
}
|
||||
|
||||
public long getRevisionsCount() {
|
||||
return PageRevision.count("author", this);
|
||||
}
|
||||
|
||||
// Operations
|
||||
|
||||
public static Account findByName(String name) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.m724.talkpages.orm.entity.content;
|
|||
import eu.m724.talkpages.page.action.NoSuchNamespaceException;
|
||||
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -56,6 +57,7 @@ public class Page extends PanacheEntity {
|
|||
public List<Page> getSubpages() { return subpages; }
|
||||
public Page getParentPage() { return parentPage; }
|
||||
|
||||
@Transactional
|
||||
public void setLatestRevision(PageRevision pageRevision) {
|
||||
revisions.add(pageRevision);
|
||||
latestRevision = pageRevision;
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.m724.talkpages.orm.entity.content;
|
|||
import eu.m724.talkpages.orm.entity.auth.Account;
|
||||
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -15,7 +16,7 @@ import java.time.LocalDateTime;
|
|||
public class PageRevision extends PanacheEntity {
|
||||
private PageRevision() {}
|
||||
|
||||
public PageRevision(Page page, Account author, String content) {
|
||||
public PageRevision(Page page, String content) {
|
||||
long index = 1;
|
||||
int delta = content.length();
|
||||
|
||||
|
@ -29,7 +30,6 @@ public class PageRevision extends PanacheEntity {
|
|||
|
||||
this.page = page;
|
||||
this.index = index;
|
||||
this.author = author;
|
||||
this.content = content;
|
||||
this.delta = delta;
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ public class PageRevision extends PanacheEntity {
|
|||
@CreationTimestamp
|
||||
private LocalDateTime timestamp;
|
||||
|
||||
@ManyToOne(cascade = CascadeType.DETACH)
|
||||
// not a relationship because complicated
|
||||
@ManyToOne
|
||||
private Account author;
|
||||
|
||||
// TODO wondering about a table only for content and meta and title perhaps
|
||||
|
@ -64,6 +65,11 @@ public class PageRevision extends PanacheEntity {
|
|||
public String getContent() { return content; }
|
||||
public int getDelta() { return delta; }
|
||||
|
||||
@Transactional
|
||||
public void setAuthor(Account account) {
|
||||
this.author = account;
|
||||
}
|
||||
|
||||
|
||||
// Operations
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@ import eu.m724.talkpages.orm.entity.content.PageRevision;
|
|||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* This service handles creating and editing pages.<br>
|
||||
* It creates pages and revisions and everything
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class ActionService {
|
||||
@Transactional
|
||||
|
@ -20,13 +24,12 @@ public class ActionService {
|
|||
}
|
||||
|
||||
Page page = new Page(title);
|
||||
PageRevision revision = new PageRevision(page, account, content);
|
||||
PageRevision revision = new PageRevision(page, content); // TODO
|
||||
revision.setAuthor(account);
|
||||
|
||||
page.setLatestRevision(revision);
|
||||
page.persistAndFlush();
|
||||
|
||||
account.getRevisions().add(revision);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
|
@ -34,12 +37,11 @@ public class ActionService {
|
|||
Page editPage(Page page, String newContent, Account account) {
|
||||
// constraints are not checked
|
||||
|
||||
PageRevision revision = new PageRevision(page, account, newContent);
|
||||
PageRevision revision = new PageRevision(page, newContent);
|
||||
revision.setAuthor(account);
|
||||
revision.persistAndFlush();
|
||||
|
||||
page.setLatestRevision(revision);
|
||||
account.getRevisions().add(revision);
|
||||
|
||||
revision.persist();
|
||||
|
||||
return page;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package eu.m724.talkpages.template;
|
||||
|
||||
import eu.m724.talkpages.orm.entity.auth.Account;
|
||||
import eu.m724.talkpages.orm.entity.auth.Session;
|
||||
import io.quarkus.arc.Arc;
|
||||
import io.quarkus.arc.InstanceHandle;
|
||||
import io.quarkus.qute.TemplateExtension;
|
||||
|
@ -13,12 +15,16 @@ public class AuthExtension {
|
|||
return !identity.isAnonymous();
|
||||
}
|
||||
|
||||
public static Session session() {
|
||||
SecurityIdentity identity = getIdentity();
|
||||
return identity.getAttribute("session");
|
||||
}
|
||||
|
||||
public static String name() {
|
||||
SecurityIdentity identity = getIdentity();
|
||||
return identity.isAnonymous() ? identity.getAttribute("address") : identity.getPrincipal().getName();
|
||||
}
|
||||
|
||||
|
||||
private static SecurityIdentity getIdentity() {
|
||||
try (InstanceHandle<CurrentIdentityAssociation> handle = Arc.container().instance(CurrentIdentityAssociation.class)) {
|
||||
return handle.get().getIdentity();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<ul>
|
||||
<li>Your account <strong>{user:name}</strong> will be deleted.</li>
|
||||
<li>Your user page and talk page, along with their subpages, and all revisions from all users, will be deleted.</li>
|
||||
<li>Your authored revisions will remain, but your name will be replaced with a shared "Deleted User"</li>
|
||||
<li>Your <strong>{user:session.account.getRevisionsCount}</strong> authored revisions will remain, but your name will be replaced with a shared "Deleted User"</li> <!-- TODO optimize the size operation -->
|
||||
<li>Your username will become available.</li>
|
||||
</ul>
|
||||
{#else}
|
||||
|
@ -23,11 +23,11 @@
|
|||
<li>Your account <strong>{user:name}</strong> will be deleted.</li>
|
||||
<li>Your user page and talk page, along with their subpages, and all revisions from all users, will be deleted.</li>
|
||||
<li>Your authored revisions will remain, but your name will be replaced with a shared "Deleted User"</li>
|
||||
<li>If you continue your activity on this website, your actions will still be posted as that IP address.</li>
|
||||
<li>If you continue your activity on this website, your account will be re-created.</li>
|
||||
</ul>
|
||||
{/if}
|
||||
|
||||
<p>While data is deleted on our side, it probably has been saved on third party archiving websites, legally or not. This is beyond our control, and we take no responsibility for it.</p>
|
||||
<p>While data is deleted on our side, it probably has been saved on third party archiving websites. This is beyond our control, and we take no responsibility for it.</p>
|
||||
|
||||
<form method="post" action="/auth/action/delete">
|
||||
<label for="confirm">I confirm</label>
|
||||
|
|
Loading…
Reference in a new issue