Fix Blog Sharing Backend and Add Blog Sharing Integration Tests

This commit is contained in:
Torsten Grote
2016-08-02 15:16:03 -03:00
parent a552d1b6a6
commit a69a4028b0
12 changed files with 808 additions and 13 deletions

View File

@@ -69,7 +69,7 @@ class BlogFactoryImpl implements BlogFactory {
Author a =
authorFactory.createAuthor(blog.getString(1), blog.getRaw(2));
// TODO change permanent depending on how this will be used
boolean permanent = false;
boolean permanent = true;
return new Blog(g, blog.getString(0), description, a, permanent);
}

View File

@@ -282,7 +282,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
}
@Override
public Blog getPersonalBlog(Author author) throws DbException {
public Blog getPersonalBlog(Author author) {
return blogFactory.createPersonalBlog(author);
}

View File

@@ -10,9 +10,7 @@ import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.inject.Inject;
@@ -69,12 +67,22 @@ class IdentityManagerImpl implements IdentityManager {
return author;
}
@Override
public LocalAuthor getLocalAuthor() throws DbException {
return getLocalAuthors().iterator().next();
}
@Override
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
return getLocalAuthors(txn).iterator().next();
}
@Override
public Collection<LocalAuthor> getLocalAuthors() throws DbException {
Collection<LocalAuthor> authors;
Transaction txn = db.startTransaction(true);
try {
authors = db.getLocalAuthors(txn);
authors = getLocalAuthors(txn);
txn.setComplete();
} finally {
db.endTransaction(txn);
@@ -82,6 +90,12 @@ class IdentityManagerImpl implements IdentityManager {
return authors;
}
private Collection<LocalAuthor> getLocalAuthors(Transaction txn)
throws DbException {
return db.getLocalAuthors(txn);
}
@Override
public void removeLocalAuthor(AuthorId a) throws DbException {
Transaction txn = db.startTransaction(false);

View File

@@ -26,6 +26,8 @@ import org.briarproject.api.event.BlogInvitationReceivedEvent;
import org.briarproject.api.event.BlogInvitationResponseReceivedEvent;
import org.briarproject.api.identity.Author;
import org.briarproject.api.identity.AuthorFactory;
import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sharing.InvitationMessage;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
@@ -50,6 +52,8 @@ class BlogSharingManagerImpl extends
"bee438b5de0b3a685badc4e49d76e72d"
+ "21e01c4b569a775112756bdae267a028"));
@Inject
IdentityManager identityManager;
private final BlogManager blogManager;
private final SFactory sFactory;
@@ -84,10 +88,19 @@ class BlogSharingManagerImpl extends
}
@Override
public boolean canBeShared(GroupId g, Contact c) throws DbException {
Blog b = blogManager.getPersonalBlog(c.getAuthor());
protected boolean canBeShared(Transaction txn, GroupId g, Contact c)
throws DbException {
// check if g is our personal blog
LocalAuthor author = identityManager.getLocalAuthor(txn);
Blog b = blogManager.getPersonalBlog(author);
if (b.getId().equals(g)) return false;
return super.canBeShared(g, c);
// check if g is c's personal blog
b = blogManager.getPersonalBlog(c.getAuthor());
if (b.getId().equals(g)) return false;
return super.canBeShared(txn, g, c);
}
@Override

View File

@@ -58,7 +58,7 @@ class BlogSharingValidator extends BdfMessageValidator {
checkLength(name, 1, MAX_BLOG_TITLE_LENGTH);
String desc = body.getString(3);
checkLength(desc, 1, MAX_BLOG_DESC_LENGTH);
checkLength(desc, 0, MAX_BLOG_DESC_LENGTH);
BdfList author = body.getList(4);
checkSize(author, 2);

View File

@@ -500,7 +500,7 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
return canBeShared;
}
private boolean canBeShared(Transaction txn, GroupId g, Contact c)
protected boolean canBeShared(Transaction txn, GroupId g, Contact c)
throws DbException {
try {