You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "vttranlina (via GitHub)" <gi...@apache.org> on 2023/11/02 03:01:37 UTC

[PR] [WIP] JAMES-2586 Postgres Subscription mapper [james-project]

vttranlina opened a new pull request, #1775:
URL: https://github.com/apache/james-project/pull/1775

   jira github.com/apache/james-project


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


Re: [PR] JAMES-2586 Postgres Subscription mapper [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #1775:
URL: https://github.com/apache/james-project/pull/1775#discussion_r1384545395


##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/jpa/user/PostgresSubscriptionTable.java:
##########
@@ -0,0 +1,45 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.jpa.user;
+
+import org.apache.james.backends.postgres.PostgresIndex;
+import org.apache.james.backends.postgres.PostgresTable;
+import org.jooq.Field;
+import org.jooq.Record;
+import org.jooq.Table;
+import org.jooq.impl.DSL;
+import org.jooq.impl.SQLDataType;
+
+public interface PostgresSubscriptionTable {
+
+    Field<String> MAILBOX = DSL.field("mail_box", SQLDataType.VARCHAR(255).notNull());
+    Field<String> USER = DSL.field("user_name", SQLDataType.VARCHAR(255).notNull());
+    Table<Record> TABLE_NAME = DSL.table("subscription");
+
+    PostgresTable TABLE = PostgresTable.name(TABLE_NAME.getName())
+        .createTableStep(((dsl, tableName) -> dsl.createTable(tableName)
+            .column(MAILBOX)
+            .column(USER)
+            .constraint(DSL.unique(MAILBOX, USER))))
+        .enableRLS();

Review Comment:
   enableRLS -> enableRowLevelSecurity
   
   Please avoid acronyms they put an undue entry barrier to comprehension



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


Re: [PR] [WIP] JAMES-2586 Postgres Subscription mapper [james-project]

Posted by "vttranlina (via GitHub)" <gi...@apache.org>.
vttranlina commented on code in PR #1775:
URL: https://github.com/apache/james-project/pull/1775#discussion_r1379538617


##########
backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java:
##########
@@ -53,6 +55,26 @@ public Mono<Void> initializeTables() {
                 .then());
     }
 
+    private Mono<Void> alterTableEnableRLSIfNeed(PostgresTable table) {
+        if (table.isEnableRowLevelSecurity()) {
+            return alterTableEnableRLS(table);
+        }
+        return Mono.empty();
+    }
+
+    public Mono<Void> alterTableEnableRLS(PostgresTable table) {
+        return postgresExecutor.connection()
+            .flatMapMany(con -> con.createStatement(getAlterRLSStatement(table.getName())).execute())
+            .flatMap(Result::getRowsUpdated)
+            .then();
+    }
+
+    private String getAlterRLSStatement(String tableName) {
+        return "ALTER TABLE " + tableName + " ADD DOMAIN varchar(255) not null DEFAULT current_setting('app.current_domain')::text;" +

Review Comment:
   I can't find the API for doing that with Jooq, 
   So I try to native SQL



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


Re: [PR] JAMES-2586 Postgres Subscription mapper [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #1775:
URL: https://github.com/apache/james-project/pull/1775#issuecomment-1798019378

   Can be rebased


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


Re: [PR] [WIP] JAMES-2586 Postgres Subscription mapper [james-project]

Posted by "quantranhong1999 (via GitHub)" <gi...@apache.org>.
quantranhong1999 commented on code in PR #1775:
URL: https://github.com/apache/james-project/pull/1775#discussion_r1379817309


##########
backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java:
##########
@@ -53,6 +55,26 @@ public Mono<Void> initializeTables() {
                 .then());
     }
 
+    private Mono<Void> alterTableEnableRLSIfNeed(PostgresTable table) {
+        if (table.isEnableRowLevelSecurity()) {
+            return alterTableEnableRLS(table);
+        }
+        return Mono.empty();
+    }
+
+    public Mono<Void> alterTableEnableRLS(PostgresTable table) {
+        return postgresExecutor.connection()
+            .flatMapMany(con -> con.createStatement(getAlterRLSStatement(table.getName())).execute())
+            .flatMap(Result::getRowsUpdated)
+            .then();
+    }
+
+    private String getAlterRLSStatement(String tableName) {
+        return "ALTER TABLE " + tableName + " ADD DOMAIN varchar(255) not null DEFAULT current_setting('app.current_domain')::text;" +

Review Comment:
   I guess this should be done in https://github.com/linagora/james-project/issues/4898 instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


Re: [PR] JAMES-2586 Postgres Subscription mapper [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #1775:
URL: https://github.com/apache/james-project/pull/1775#discussion_r1384543577


##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/jpa/user/PostgresSubscriptionTable.java:
##########
@@ -0,0 +1,45 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.jpa.user;
+
+import org.apache.james.backends.postgres.PostgresIndex;
+import org.apache.james.backends.postgres.PostgresTable;
+import org.jooq.Field;
+import org.jooq.Record;
+import org.jooq.Table;
+import org.jooq.impl.DSL;
+import org.jooq.impl.SQLDataType;
+
+public interface PostgresSubscriptionTable {
+
+    Field<String> MAILBOX = DSL.field("mail_box", SQLDataType.VARCHAR(255).notNull());

Review Comment:
   mailbox



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


Re: [PR] JAMES-2586 Postgres Subscription mapper [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #1775:
URL: https://github.com/apache/james-project/pull/1775#discussion_r1384541207


##########
backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresDAO.java:
##########
@@ -0,0 +1,31 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.backends.postgres;
+
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+
+public abstract class PostgresDAO {

Review Comment:
   I hardly see the use of this class.
   
   If you want marking just use an interface?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


Re: [PR] [WIP] JAMES-2586 Postgres Subscription mapper [james-project]

Posted by "vttranlina (via GitHub)" <gi...@apache.org>.
vttranlina commented on code in PR #1775:
URL: https://github.com/apache/james-project/pull/1775#discussion_r1383020599


##########
backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java:
##########
@@ -53,6 +55,26 @@ public Mono<Void> initializeTables() {
                 .then());
     }
 
+    private Mono<Void> alterTableEnableRLSIfNeed(PostgresTable table) {
+        if (table.isEnableRowLevelSecurity()) {
+            return alterTableEnableRLS(table);
+        }
+        return Mono.empty();
+    }
+
+    public Mono<Void> alterTableEnableRLS(PostgresTable table) {
+        return postgresExecutor.connection()
+            .flatMapMany(con -> con.createStatement(getAlterRLSStatement(table.getName())).execute())
+            .flatMap(Result::getRowsUpdated)
+            .then();
+    }
+
+    private String getAlterRLSStatement(String tableName) {
+        return "ALTER TABLE " + tableName + " ADD DOMAIN varchar(255) not null DEFAULT current_setting('app.current_domain')::text;" +

Review Comment:
   I did cherrypick this commit to postgres table manager PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


Re: [PR] JAMES-2586 Postgres Subscription mapper [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #1775:
URL: https://github.com/apache/james-project/pull/1775#discussion_r1384543038


##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/jpa/user/PostgresSubscriptionTable.java:
##########
@@ -0,0 +1,45 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.jpa.user;
+
+import org.apache.james.backends.postgres.PostgresIndex;
+import org.apache.james.backends.postgres.PostgresTable;
+import org.jooq.Field;
+import org.jooq.Record;
+import org.jooq.Table;
+import org.jooq.impl.DSL;
+import org.jooq.impl.SQLDataType;
+
+public interface PostgresSubscriptionTable {

Review Comment:
   IMO move table definition into `PostgresSubscriptionModule`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


Re: [PR] JAMES-2586 Postgres Subscription mapper [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael merged PR #1775:
URL: https://github.com/apache/james-project/pull/1775


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org