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

MAILBOX-310 MailboxManager::search and delegation #1011

Closed
wants to merge 27 commits into from

Conversation

chibenwa
Copy link
Member

@chibenwa chibenwa commented Oct 4, 2017

This PR includes:

  • Fix of Cassandra UID and MODSEQ (faster tests, less changes when modifying Mappers)
  • Heavy refactoring of MailboxQuery
  • Some ACL filtering
  • Wiring and logic for delegated search.

Enjoy.

@chibenwa
Copy link
Member Author

chibenwa commented Oct 4, 2017

test this please

/**
* @author Peter Palaga
*/
public class MailboxACLTest {

private static final String USER_1 = "user1";
private static final String USER_2 = "user2";
private static final boolean NEGATIVE = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NEGATIVE = true this is weird

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're peaky. what I am supposed to do with this?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can let it like that, I just wanted to mention it's a bit weird but I don't see any overkill solution to it


import org.apache.james.mailbox.model.MailboxACL;

public class ACLChanged {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not necessary to specify that this class only handles user positive entries?

.and(eq(MAILBOX_ID, bindMarker(MAILBOX_ID))));
}

private PreparedStatement prepareSelectUser(Session session) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SelectAllForUser?

.compactionOptions(SchemaBuilder.leveledStrategy())
.caching(SchemaBuilder.KeyCaching.ALL,
SchemaBuilder.rows(CassandraConstants.DEFAULT_CACHED_ROW_PER_PARTITION))
.comment("Denormalisation table. Allow to retrieve tnon personnal mailboxId a user has right on")));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/tnon/non/
s/mailboxId/mailboxIds

}

@Test
public void retrieveUserShouldReturnEmptyWhenEmptyData() throws Exception {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/retrieveUser/listRightsForUser/

.map(aclTransformation)
.map(aclWithVersion -> updateStoredACL(cassandraId, aclWithVersion))
.orElseGet(() -> insertACL(cassandraId, replacement));
.map(value ->
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value? aclWithVersion was a better naming, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value was already used before I refactored. Changed.

@@ -100,6 +101,7 @@
*/
public class StoreMailboxManager implements MailboxManager {
private static final Logger LOGGER = LoggerFactory.getLogger(StoreMailboxManager.class);
public static final char SQL_WILDCARD_CHAR = '%';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public before private :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but honestly, I'm wondering if we should not authorize LOGGER to be always the first line, even if private

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me I prefer Logger to be in the first line, as it's pretty generic.

}

@Test
public void IsWildShouldReturnTrueWhenLocalWildcardAtBeginning() throws Exception {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Is/is/ everywhere in this file

}

@Test
public void getCombinedNameShouldWork() throws Exception {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad test name, but it's copy / pasted from the refactoring, so I won't ask it to be changed for now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's kind. I got the impression I did the refactoring quota :-)

boolean actual = testee.isExpressionMatch("folder\\123");

assertThat(actual).isTrue();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not check each test, I assume it's just a copy paster from previous regexp tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly this ;-)

@@ -176,8 +177,7 @@ public void getPathLikeShouldReturnUserPathLikeWhenNoBaseDefined() throws Except
//Given
MailboxSession session = new MockMailboxSession("user");
MailboxQuery.Builder testee = MailboxQuery.builder()
.expression("abc")
.mailboxSession(session);
.expression(new PrefixedRegex("", "abc", session.getPathDelimiter()));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this empty string? can you name it?

Copy link
Member Author

@chibenwa chibenwa Oct 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No prefix, regex only ;-)

I guess the exact one might be used...

chibenwa and others added 20 commits October 5, 2017 09:48
 - Allow missing namespace and username in mailboxQuery
 - Matching logic SHOULD be moved in MailboxQuery
…nymore on MailboxPath for its internal representation
}

private boolean isReadable(MailboxSession session, Mailbox mailbox) throws MailboxException {
return (Objects.equals(mailbox.getUser(), session.getUser().getUserName())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many conditions here IMO

}

public Stream<MailboxACL.Entry> addedEntries() {
Map<MailboxACL.EntryKey, MailboxACL.Rfc4314Rights> oldEntries = oldACL.ofPositiveNameType(MailboxACL.NameType.user);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff feature should not belong to this class because we will need it really often

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

this.pathDelimiter = Optional.of(pathDelimiter);
public Builder matchesAllMailboxNames() {
this.mailboxNameExpression = Optional.of(new Wildcard());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wildcard should be a Singleton

@@ -349,7 +349,8 @@ public void putShouldReturnOkWhenIssuedTwoTimes() {
@Test
public void putShouldAddAMailbox() {
with()
.put(MAILBOX_NAME);
.put(MAILBOX_NAME)
.prettyPeek();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sysout spotted

Copy link
Member Author

@chibenwa chibenwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for @aduprat changes

private final char pathDelimiter;

private final Pattern pattern;
public static final char SQL_WILDCARD_CHAR = '%';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have sql logic here ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part of the code was not changed, just moved

Copy link

@rouazana rouazana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not check the rebase though

@@ -95,7 +96,7 @@ public Builder expression(MailboxNameExpression expression) {
}

public Builder matchesAllMailboxNames() {
this.mailboxNameExpression = Optional.of(new Wildcard());
this.mailboxNameExpression = Optional.of(WILDCARD);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not what I meant, Wildcard whould not have a public constructor as it's always the exact same object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you handle this?

@mbaechler
Copy link

merged

@mbaechler mbaechler closed this Oct 5, 2017
chibenwa added a commit to chibenwa/james-project that referenced this pull request May 25, 2022
chibenwa added a commit to chibenwa/james-project that referenced this pull request May 26, 2022
chibenwa added a commit to chibenwa/james-project that referenced this pull request May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants