From f9f460d71a3ede01ac112e21c58faa7f2ece9c8f Mon Sep 17 00:00:00 2001
From: Howo <drov0@users.noreply.github.com>
Date: Fri, 16 Dec 2022 14:36:36 -0500
Subject: [PATCH] Squashed commit of the following:

commit 3eb729847d5fae6480163f09edcd1fda599e3eb7
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Mon Aug 22 00:18:09 2022 -0400

    Fix pattern tests following changes in mocks

commit e0ed25f8af23d40acecc4c057401a7585b906419
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Aug 21 20:35:51 2022 -0400

    Added test cases in the mocks + pattern tests

commit 1144c26586f5c48004904a729d5cecaf90acee6d
Merge: 2a80d650 066762c7
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Aug 21 20:35:21 2022 -0400

    Merge branch 'feature/role-only-if-subscribed' of gitlab.syncad.com:hive/hivemind into feature/role-only-if-subscribed

commit 066762c71b843b7a181e247a1e81146b89c232ce
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun May 8 23:13:17 2022 -0400

    Added flow.txt where it's missed

commit 6acdb3003093feb4e94b0c8fa14b6b4de1da006e
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 24 10:46:38 2022 -0400

    fix all tests

commit 566a71abe485e90242ce6e6e81f65da4bdb87e7d
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sat Apr 23 22:35:34 2022 -0400

    attempt at fixing most tests

commit ec803921f216e3a5f829ab205662265b3c355d65
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sat Apr 23 21:25:23 2022 -0400

    first fix try

commit cbb74d37a9227a026ab7e499eb18ba802c9f006c
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 3 23:26:00 2022 -0400

    small fix

commit 9dc83b3b96ad00053a6737bfe647e39f9e6c2da3
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 3 23:23:55 2022 -0400

    Allows setting the muted role even if you're not subscribed

commit 446a4c1b5759823e137e75277a6336eb195b105b
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 3 23:11:00 2022 -0400

    added communtiy_helpers to base schema

commit e710b92c4c9c9a120440baae07eb09b8a539f924
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 3 19:52:29 2022 -0400

    Update SetRole/SetUserTitle so that you have to be subscribed to get it, also added a script to generate flow.txt and cleaned up communtiy_flow

commit 2a80d650a6297853fb63ff86d88e074810b64837
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun May 8 23:13:17 2022 -0400

    Added flow.txt where it's missed

commit 555d03c6e01dca7f4c56ddbab20aba3a39a6a6f6
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 24 10:46:38 2022 -0400

    fix all tests

commit 0b7052045668c38c02a01ad1bde984539ccab9a8
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sat Apr 23 22:35:34 2022 -0400

    attempt at fixing most tests

commit 4e2946f7fe6042249042b3ae848866b5be31112b
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sat Apr 23 21:25:23 2022 -0400

    first fix try

commit 7c467c37c2b7d821f430afb977289cefe0bf03f2
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 3 23:26:00 2022 -0400

    small fix

commit 3ecaf6403cbb4bfe8d782aa2521eb9c51fd0b280
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 3 23:23:55 2022 -0400

    Allows setting the muted role even if you're not subscribed

commit 2e9081e5f21ccf7a948d5aded4ec2913827b96d4
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 3 23:11:00 2022 -0400

    added communtiy_helpers to base schema

commit 7f0cc6d5f654c4532ae930041d04d5c0d24edbe1
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Apr 3 19:52:29 2022 -0400

    Update SetRole/SetUserTitle so that you have to be subscribed to get it, also added a script to generate flow.txt and cleaned up communtiy_flow

fix plsql function to accomodate the new haf bindings

fixed block_data_community to match new haf design

fixed json again

fix keys again

fixes for hive_roles

update tests + flows

fix pattern tests to account for new mocked community

Cleaned branch

Squashed commit of the following:

commit f6824e05b47fb84d8099f6fa1265b3e730aefde3
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sat Apr 2 13:53:06 2022 -0400

    try other idea

commit 587797618dca2da7ac82fbb3fbf0efde15594e37
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sat Apr 2 13:51:27 2022 -0400

    test wihout php.author_id

commit 4a0c9dda3acdec835ee3d6ac56b80353e61a4ccd
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Wed Mar 23 01:13:30 2022 -0400

    test

commit 1147b6c19d877d6b333f688b6d0b29ef9be8b7b4
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Wed Mar 23 01:04:26 2022 -0400

    try to return a NULL::integer

commit 5163b17932919f6a9e73b4a3d4694c2978f6e037
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Wed Mar 23 01:03:24 2022 -0400

    test

commit 8e737f13127db7d676891705fd48d03b7a9225c4
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Wed Mar 23 00:46:54 2022 -0400

    fix query

commit 1f3f40d5ae32d359c0ae80ba1b96b9ea4c3fbb1f
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Wed Mar 23 00:41:36 2022 -0400

    overhaul of the query

commit a0c08b48e58c5851b980557c7d931452f6211ed7
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Tue Mar 22 22:23:32 2022 -0400

    test

commit 4128881322394879bc67715a93300f02961daf58
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Tue Mar 22 21:35:40 2022 -0400

    typo

commit 924dd89e6631736b8b9bb450860bc88a9026de64
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Tue Mar 22 21:31:19 2022 -0400

    Decorated sql to fix conflict

commit ebcda2ccfc94c64f5528e864038272ad81d670e0
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Tue Mar 22 21:16:39 2022 -0400

    code style

commit df102d8e151b1467df9053c803dc4c1f318e236b
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Mar 13 23:27:53 2022 -0400

    fix query

commit 77dc4fb29b3daf888821ddf2371562e46f3bacd9
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Mar 13 17:10:09 2022 -0400

    Fix format

commit 46add4ed815fea64391ed8d58f7e7c67eeefe8bd
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Mar 13 17:04:05 2022 -0400

    fix typo

commit d1d08f626ced15c2db0fe0c5b87f8b8694b82c7d
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Sun Mar 13 17:01:55 2022 -0400

    added the flow + mocked ops

commit 5a90840dd0ac4aca18915a1186bb58ee0d224243
Author: Martin Lees <drov0@users.noreply.github.com>
Date:   Tue Jan 25 23:56:05 2022 -0500

    update community type feature

communities type 1 tests + updated sql to work with haf

Fix broken mock
---
 hive/db/sql_scripts/hive_post_operations.sql  |  67 ++++-
 hive/indexer/community.py                     |  38 +--
 hive/indexer/posts.py                         |   8 +-
 .../mock_block_data_community.json            | 245 ++++++++++++++++++
 scripts/ci/start-api-benchmarks.sh            |   2 +-
 .../get_community/hive-111119.pat.json        |  26 ++
 .../get_community/hive-111119.tavern.yaml     |  28 ++
 .../get_community/hive-211119.pat.json        |  26 ++
 .../get_community/hive-211119.tavern.yaml     |  28 ++
 .../get_community/hive-311119.pat.json        |  26 ++
 .../get_community/hive-311119.tavern.yaml     |  28 ++
 11 files changed, 489 insertions(+), 33 deletions(-)
 create mode 100644 tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-111119.pat.json
 create mode 100644 tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-111119.tavern.yaml
 create mode 100644 tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-211119.pat.json
 create mode 100644 tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-211119.tavern.yaml
 create mode 100644 tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-311119.pat.json
 create mode 100644 tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-311119.tavern.yaml

diff --git a/hive/db/sql_scripts/hive_post_operations.sql b/hive/db/sql_scripts/hive_post_operations.sql
index ecbee293b..80eebba51 100644
--- a/hive/db/sql_scripts/hive_post_operations.sql
+++ b/hive/db/sql_scripts/hive_post_operations.sql
@@ -25,6 +25,54 @@ BEGIN
 END
 $function$;
 
+
+DROP FUNCTION IF EXISTS process_community_post;
+CREATE OR REPLACE FUNCTION process_community_post(_block_num hive_posts.block_num%TYPE, _community_support_start_block hive_posts.block_num%TYPE, _community_id hive_posts.community_id%TYPE, _community_name hive_permlink_data.permlink%TYPE, _author_id hive_posts.author_id%TYPE, is_comment bool)
+RETURNS TABLE(is_muted bool, community_id hive_posts.community_id%TYPE)
+LANGUAGE plpgsql
+as
+    $$
+declare
+        __community_type_id SMALLINT;
+        __role_id SMALLINT;
+        __member_role CONSTANT SMALLINT := 2;
+        __community_type_topic CONSTANT SMALLINT := 1;
+        __community_type_journal CONSTANT SMALLINT := 2;
+        __community_type_council CONSTANT SMALLINT := 3;
+        __is_muted bool := FALSE;
+        __community_id hivemind_app.hive_posts.community_id%TYPE;
+BEGIN
+        IF _block_num < _community_support_start_block THEN
+            __is_muted := FALSE;
+            __community_id := NULL;
+        ELSE
+            IF _community_id IS NOT NULL THEN
+                SELECT type_id INTO __community_type_id FROM hivemind_app.hive_communities WHERE id = _community_id;
+            ELSE
+                SELECT type_id, id INTO __community_type_id, _community_id from hivemind_app.hive_communities where name = _community_name;
+            END IF;
+
+            IF __community_type_id = __community_type_topic THEN
+                __is_muted := TRUE;
+            ELSE
+                IF __community_type_id = __community_type_journal AND is_comment = TRUE THEN
+                    __is_muted := TRUE;
+                ELSE
+                    select role_id into __role_id from hivemind_app.hive_roles where hivemind_app.hive_roles.community_id = _community_id AND account_id = _author_id;
+                    IF __community_type_id = __community_type_journal AND is_comment = FALSE AND __role_id IS NOT NULL AND __role_id >= __member_role THEN
+                        __is_muted := TRUE;
+                    ELSIF __community_type_id = __community_type_council AND __role_id IS NOT NULL AND __role_id >= __member_role THEN
+                        __is_muted := TRUE;
+                    END IF;
+                END IF;
+            END IF;
+        END IF;
+
+        RETURN QUERY SELECT __is_muted, __community_id;
+    END;
+$$;
+
+
 DROP FUNCTION IF EXISTS hivemind_app.process_hive_post_operation;
 ;
 CREATE OR REPLACE FUNCTION hivemind_app.process_hive_post_operation(
@@ -58,17 +106,14 @@ if _parent_author != '' THEN
     root_id, is_muted, is_valid,
     author_id, permlink_id, created_at, updated_at, sc_hot, sc_trend, active, payout_at, cashout_time, counter_deleted, block_num, block_num_created)
   SELECT php.id AS parent_id, php.depth + 1 AS depth,
-      (CASE
-          WHEN _block_num > _community_support_start_block THEN
-            COALESCE(php.community_id, (select hc.id from hivemind_app.hive_communities hc where hc.name = _parent_permlink))
-          ELSE NULL
-      END) AS community_id,
+      pcp.community_id AS community_id,
       COALESCE(php.category_id, (select hcg.id from hivemind_app.hive_category_data hcg where hcg.category = _parent_permlink)) AS category_id,
       (CASE(php.root_id)
           WHEN 0 THEN php.id
           ELSE php.root_id
         END) AS root_id,
-      php.is_muted AS is_muted, php.is_valid AS is_valid,
+      pcp.is_muted AS is_muted,
+      php.is_valid AS is_valid,
       ha.id AS author_id, hpd.id AS permlink_id, _date AS created_at,
       _date AS updated_at,
       hivemind_app.calculate_time_part_of_hot(_date) AS sc_hot,
@@ -77,6 +122,7 @@ if _parent_author != '' THEN
         _block_num as block_num, _block_num as block_num_created
   FROM hivemind_app.hive_accounts ha,
         hivemind_app.hive_permlink_data hpd,
+        hivemind_app.process_community_post(_block_num, _community_support_start_block, NULL, _parent_permlink, ha.id, false) pcp,
         hivemind_app.hive_posts php
   INNER JOIN hivemind_app.hive_accounts pha ON pha.id = php.author_id
   INNER JOIN hivemind_app.hive_permlink_data phpd ON phpd.id = php.permlink_id
@@ -106,14 +152,10 @@ ELSE
     active, payout_at, cashout_time, counter_deleted, block_num, block_num_created,
     tags_ids)
   SELECT 0 AS parent_id, 0 AS depth,
-      (CASE
-        WHEN _block_num > _community_support_start_block THEN
-          (select hc.id FROM hivemind_app.hive_communities hc WHERE hc.name = _parent_permlink)
-        ELSE NULL
-      END) AS community_id,
+      pcp.community_id AS community_id,
       (SELECT hcg.id FROM hivemind_app.hive_category_data hcg WHERE hcg.category = _parent_permlink) AS category_id,
       0 as root_id, -- will use id as root one if no parent
-      false AS is_muted, true AS is_valid,
+      pcp.is_muted AS is_muted, true AS is_valid,
       ha.id AS author_id, hpd.id AS permlink_id, _date AS created_at,
       _date AS updated_at,
       hivemind_app.calculate_time_part_of_hot(_date) AS sc_hot,
@@ -125,6 +167,7 @@ ELSE
           FROM hivemind_app.prepare_tags( ARRAY_APPEND(_metadata_tags, _parent_permlink ) )
         ) as tags_ids
   FROM hivemind_app.hive_accounts ha,
+       hivemind_app.process_community_post(_block_num, _community_support_start_block, NULL, _parent_permlink, author_id, false) pcp,
         hivemind_app.hive_permlink_data hpd
   WHERE ha.name = _author and hpd.permlink = _permlink
 
diff --git a/hive/indexer/community.py b/hive/indexer/community.py
index a3559e69f..f56988064 100644
--- a/hive/indexer/community.py
+++ b/hive/indexer/community.py
@@ -33,6 +33,7 @@ class Role(IntEnum):
 TYPE_TOPIC = 1
 TYPE_JOURNAL = 2
 TYPE_COUNCIL = 3
+valid_types = [TYPE_TOPIC, TYPE_JOURNAL, TYPE_COUNCIL]
 
 # https://en.wikipedia.org/wiki/ISO_639-1
 LANGS = (
@@ -103,6 +104,12 @@ def read_key_dict(obj, key):
     assert isinstance(obj[key], dict), f'key `{key}` not a dict'
     return obj[key]
 
+def read_key_integer(op, key):
+    """Reads a key from dict, ensuring valid bool if present."""
+    if key in op:
+        assert isinstance(op[key], int), 'must be int: %s' % key
+        return op[key]
+    return None
 
 class Community:
     """Handles hive community registration and operations."""
@@ -123,8 +130,7 @@ class Community:
         This method checks for any valid community names and inserts them.
         """
 
-        # if not re.match(r'^hive-[123]\d{4,6}$', name):
-        if not re.match(r'^hive-[1]\d{4,6}$', name):
+        if not re.match(r'^hive-[123]\d{4,6}$', name):
             return
         type_id = int(name[5])
         _id = Accounts.get_id(name)
@@ -372,24 +378,22 @@ class CommunityOp:
 
         # Account-level actions
         elif action == 'setRole':
-            DB.query(
-                f"""INSERT INTO {SCHEMA_NAME}.hive_roles
-                               (account_id, community_id, role_id, created_at)
-                        VALUES (:account_id, :community_id, :role_id, :date)
-                            ON CONFLICT (account_id, community_id)
-                            DO UPDATE SET role_id = :role_id """,
+            subscribed = DB.query_one(
+                f"""SELECT * FROM {SCHEMA_NAME}.set_community_role_or_title(:community_id, :account_id, :role_id, NULL::varchar, CAST(:date AS timestamp ))""",
                 **params,
             )
+            if not subscribed:
+                log.info("set role failed account '%s' must be subscribed to the community", params['account'])
+                return
             self._notify('set_role', payload=Role(self.role_id).name)
         elif action == 'setUserTitle':
-            DB.query(
-                f"""INSERT INTO {SCHEMA_NAME}.hive_roles
-                               (account_id, community_id, title, created_at)
-                        VALUES (:account_id, :community_id, :title, :date)
-                            ON CONFLICT (account_id, community_id)
-                            DO UPDATE SET title = :title""",
+            subscribed = DB.query_one(
+                f"""SELECT * FROM {SCHEMA_NAME}.set_community_role_or_title(:community_id, :account_id, NULL::integer , :title, CAST(:date AS timestamp ))""",
                 **params,
             )
+            if not subscribed:
+                log.info("set role failed account '%s' must be subscribed to the community", params['account'])
+                return
             self._notify('set_label', payload=self.title)
 
         # Post-level actions
@@ -535,7 +539,7 @@ class CommunityOp:
     def _read_props(self):
         # TODO: assert props changed?
         props = read_key_dict(self.op, 'props')
-        valid = ['title', 'about', 'lang', 'is_nsfw', 'description', 'flag_text', 'settings']
+        valid = ['title', 'about', 'lang', 'is_nsfw', 'description', 'flag_text', 'settings', 'type_id']
         assert_keys_match(props.keys(), valid, allow_missing=True)
 
         out = {}
@@ -560,6 +564,10 @@ class CommunityOp:
                 avatar_url = settings['avatar_url']
                 assert not avatar_url or _valid_url_proto(avatar_url)
                 out['avatar_url'] = avatar_url
+        if 'type_id' in props:
+            community_type = read_key_integer(props, 'type_id')
+            assert community_type in valid_types, 'invalid community type'
+            out['type_id'] = community_type
         assert out, 'props were blank'
         self.props = out
 
diff --git a/hive/indexer/posts.py b/hive/indexer/posts.py
index adfe7aa77..dd913c655 100644
--- a/hive/indexer/posts.py
+++ b/hive/indexer/posts.py
@@ -89,8 +89,7 @@ class Posts(DbAdapterHolder):
             return
         result = dict(row)
 
-        # TODO we need to enhance checking related community post validation and honor is_muted.
-        error = cls._verify_post_against_community(op, result['community_id'], result['is_valid'], result['is_muted'])
+        error = cls._verify_post_against_community(op, result['community_id'], result['is_valid'])
 
         img_url = None
         if 'image' in md:
@@ -392,12 +391,11 @@ class Posts(DbAdapterHolder):
         Votes.drop_votes_of_deleted_comment(op)
 
     @classmethod
-    def _verify_post_against_community(cls, op, community_id, is_valid, is_muted):
+    def _verify_post_against_community(cls, op, community_id, is_valid):
         error = None
         if community_id and is_valid and not Community.is_post_valid(community_id, op):
             error = 'not authorized'
-            # is_valid = False # TODO: reserved for future blacklist status?
-            is_muted = True
+            #is_valid = False # TODO: reserved for future blacklist status?
         return error
 
     @classmethod
diff --git a/mock_data/block_data/community_op/mock_block_data_community.json b/mock_data/block_data/community_op/mock_block_data_community.json
index e671852f6..8fde8fcf4 100644
--- a/mock_data/block_data/community_op/mock_block_data_community.json
+++ b/mock_data/block_data/community_op/mock_block_data_community.json
@@ -970,6 +970,17 @@
               "json": "[\"subscribe\",{\"community\":\"hive-167892\"}]"
             }
           },
+          {
+            "type": "custom_json_operation",
+            "value": {
+              "required_auths": [],
+              "required_posting_auths": [
+                "test-safari"
+              ],
+              "id": "community",
+              "json": "[\"subscribe\",{\"community\":\"hive-167892\"}]"
+            }
+          },
           {
             "type": "custom_json_operation",
             "value": {
@@ -4745,6 +4756,126 @@
               "json_metadata": "",
               "extensions": []
             }
+          },
+          {
+            "type": "account_create_operation",
+            "value": {
+              "creator": "howo",
+              "new_account_name": "hive-111119",
+              "owner": {
+                "weight_threshold": 1,
+                "account_auths": [],
+                "key_auths": [
+                  [
+                    "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+                    1
+                  ]
+                ]
+              },
+              "active": {
+                "weight_threshold": 1,
+                "account_auths": [],
+                "key_auths": [
+                  [
+                    "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+                    1
+                  ]
+                ]
+              },
+              "posting": {
+                "weight_threshold": 1,
+                "account_auths": [],
+                "key_auths": [
+                  [
+                    "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+                    1
+                  ]
+                ]
+              },
+              "memo_key": "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+              "json_metadata": "",
+              "extensions": []
+            }
+          },
+          {
+            "type": "account_create_operation",
+            "value": {
+              "creator": "howo",
+              "new_account_name": "hive-211119",
+              "owner": {
+                "weight_threshold": 1,
+                "account_auths": [],
+                "key_auths": [
+                  [
+                    "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+                    1
+                  ]
+                ]
+              },
+              "active": {
+                "weight_threshold": 1,
+                "account_auths": [],
+                "key_auths": [
+                  [
+                    "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+                    1
+                  ]
+                ]
+              },
+              "posting": {
+                "weight_threshold": 1,
+                "account_auths": [],
+                "key_auths": [
+                  [
+                    "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+                    1
+                  ]
+                ]
+              },
+              "memo_key": "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+              "json_metadata": "",
+              "extensions": []
+            }
+          },
+          {
+            "type": "account_create_operation",
+            "value": {
+              "creator": "howo",
+              "new_account_name": "hive-311119",
+              "owner": {
+                "weight_threshold": 1,
+                "account_auths": [],
+                "key_auths": [
+                  [
+                    "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+                    1
+                  ]
+                ]
+              },
+              "active": {
+                "weight_threshold": 1,
+                "account_auths": [],
+                "key_auths": [
+                  [
+                    "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+                    1
+                  ]
+                ]
+              },
+              "posting": {
+                "weight_threshold": 1,
+                "account_auths": [],
+                "key_auths": [
+                  [
+                    "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+                    1
+                  ]
+                ]
+              },
+              "memo_key": "STM8JH4fTJr73FQimysjmXCEh2UvRwZsG6ftjxsVTmYCeEehZgh25",
+              "json_metadata": "",
+              "extensions": []
+            }
           }
         ]
       }
@@ -4866,6 +4997,120 @@
               "id": "community",
               "json": "[\"setRole\",{\"community\":\"hive-199999\",\"account\":\"isoldmember\",\"role\":\"member\"}]"
             }
+          },
+          {
+            "type": "custom_json_operation",
+            "value": {
+              "required_auths": [],
+              "required_posting_auths": [
+                "ismember"
+              ],
+              "id": "community",
+              "json": "[\"subscribe\",{\"community\":\"hive-111119\"}]"
+            }
+          },
+          {
+            "type": "custom_json_operation",
+            "value": {
+              "required_auths": [],
+              "required_posting_auths": [
+                "ismember"
+              ],
+              "id": "community",
+              "json": "[\"subscribe\",{\"community\":\"hive-211119\"}]"
+            }
+          },
+          {
+            "type": "custom_json_operation",
+            "value": {
+              "required_auths": [],
+              "required_posting_auths": [
+                "ismember"
+              ],
+              "id": "community",
+              "json": "[\"subscribe\",{\"community\":\"hive-311119\"}]"
+            }
+          },
+          {
+            "type": "custom_json_operation",
+            "value": {
+              "required_auths": [],
+              "required_posting_auths": [
+                "hive-111119"
+              ],
+              "id": "community",
+              "json": "[\"setRole\",{\"community\":\"hive-111119\",\"account\":\"ismember\",\"role\":\"member\"}]"
+            }
+          },
+          {
+            "type": "custom_json_operation",
+            "value": {
+              "required_auths": [],
+              "required_posting_auths": [
+                "hive-211119"
+              ],
+              "id": "community",
+              "json": "[\"setRole\",{\"community\":\"hive-211119\",\"account\":\"ismember\",\"role\":\"member\"}]"
+            }
+          },
+          {
+            "type": "custom_json_operation",
+            "value": {
+              "required_auths": [],
+              "required_posting_auths": [
+                "hive-311119"
+              ],
+              "id": "community",
+              "json": "[\"setRole\",{\"community\":\"hive-311119\",\"account\":\"ismember\",\"role\":\"member\"}]"
+            }
+          },
+          {
+            "type": "comment_operation",
+            "value": {
+              "parent_author": "",
+              "parent_permlink": "hive-111119",
+              "author": "ismember",
+              "permlink": "ismember-hive-111119",
+              "title": "ismember This post will not be muted",
+              "body": "lorem ipsum",
+              "json_metadata": "{}"
+            }
+          },
+          {
+            "type": "comment_operation",
+            "value": {
+              "parent_author": "",
+              "parent_permlink": "hive-111119",
+              "author": "notmember",
+              "permlink": "notmember-hive-111119",
+              "title": "notmember This post will not be muted",
+              "body": "lorem ipsum",
+              "json_metadata": "{}"
+            }
+          },
+          {
+            "type": "comment_operation",
+            "value": {
+              "parent_author": "ismember",
+              "parent_permlink": "ismember-hive-111119",
+              "author": "ismember",
+              "permlink": "re-ismember-hive-111119",
+              "title": "ismember This comment will not be muted",
+              "body": "lorem ipsum",
+              "json_metadata": "{}"
+            }
+          },
+          {
+            "type": "comment_operation",
+            "value": {
+              "parent_author": "ismember",
+              "parent_permlink": "ismember-hive-111119",
+              "author": "notmember",
+              "permlink": "re-2-ismember-hive-111119",
+              "title": "notmember This comment will not be muted",
+              "body": "lorem ipsum",
+              "json_metadata": "{}"
+            }
           }
         ]
       }
diff --git a/scripts/ci/start-api-benchmarks.sh b/scripts/ci/start-api-benchmarks.sh
index 49e4faa53..9742b2796 100755
--- a/scripts/ci/start-api-benchmarks.sh
+++ b/scripts/ci/start-api-benchmarks.sh
@@ -15,7 +15,7 @@ echo "HIVEMIND_PORT: ${HIVEMIND_PORT}"
 echo "ITERATIONS: ${ITERATIONS}"
 echo "JOBS: ${JOBS}"
 
-# since it working inside docker it shoud be fine to hardcode it to tmp
+# since it working inside docker it should be fine to hardcode it to tmp
 export HIVEMIND_BENCHMARKS_IDS_FILE=/tmp/test_ids.csv
 export TAVERN_DISABLE_COMPARATOR=true
 
diff --git a/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-111119.pat.json b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-111119.pat.json
new file mode 100644
index 000000000..09930b671
--- /dev/null
+++ b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-111119.pat.json
@@ -0,0 +1,26 @@
+{
+  "about": "",
+  "avatar_url": "",
+  "context": {},
+  "created_at": "2016-09-15 19:47:51",
+  "description": "",
+  "flag_text": "",
+  "id": 92530,
+  "is_nsfw": false,
+  "lang": "en",
+  "name": "hive-111119",
+  "num_authors": 0,
+  "num_pending": 0,
+  "settings": {},
+  "subscribers": 0,
+  "sum_pending": 0,
+  "team": [
+    [
+      "hive-111119",
+      "owner",
+      ""
+    ]
+  ],
+  "title": "@hive-111119",
+  "type_id": 1
+}
diff --git a/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-111119.tavern.yaml b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-111119.tavern.yaml
new file mode 100644
index 000000000..cfdabae20
--- /dev/null
+++ b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-111119.tavern.yaml
@@ -0,0 +1,28 @@
+---
+  test_name: Hivemind
+
+  marks:
+    - patterntest
+    # Communities not implemented under 5 mln blocks, but some were created by mock mechanism, therefore they are in result.
+
+  includes:
+    - !include ../../common.yaml
+
+  stages:
+    - name: test
+      request:
+        url: "{service.proto:s}://{service.server:s}:{service.port}/"
+        method: POST
+        headers:
+          content-type: application/json
+        json:
+          jsonrpc: "2.0"
+          id: 1
+          method: "bridge.get_community"
+          params: {"name":"hive-111119"}
+      response:
+        status_code: 200
+        verify_response_with:
+          function: validate_response:compare_response_with_pattern
+          extra_kwargs:
+            ignore_tags: "<bridge community>"
diff --git a/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-211119.pat.json b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-211119.pat.json
new file mode 100644
index 000000000..cf5ea15ca
--- /dev/null
+++ b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-211119.pat.json
@@ -0,0 +1,26 @@
+{
+  "about": "",
+  "avatar_url": "",
+  "context": {},
+  "created_at": "2016-09-15 19:47:51",
+  "description": "",
+  "flag_text": "",
+  "id": 92531,
+  "is_nsfw": false,
+  "lang": "en",
+  "name": "hive-211119",
+  "num_authors": 0,
+  "num_pending": 0,
+  "settings": {},
+  "subscribers": 0,
+  "sum_pending": 0,
+  "team": [
+    [
+      "hive-211119",
+      "owner",
+      ""
+    ]
+  ],
+  "title": "@hive-211119",
+  "type_id": 2
+}
diff --git a/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-211119.tavern.yaml b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-211119.tavern.yaml
new file mode 100644
index 000000000..8bcd01236
--- /dev/null
+++ b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-211119.tavern.yaml
@@ -0,0 +1,28 @@
+---
+  test_name: Hivemind
+
+  marks:
+    - patterntest
+    # Communities not implemented under 5 mln blocks, but some were created by mock mechanism, therefore they are in result.
+
+  includes:
+    - !include ../../common.yaml
+
+  stages:
+    - name: test
+      request:
+        url: "{service.proto:s}://{service.server:s}:{service.port}/"
+        method: POST
+        headers:
+          content-type: application/json
+        json:
+          jsonrpc: "2.0"
+          id: 1
+          method: "bridge.get_community"
+          params: {"name":"hive-211119"}
+      response:
+        status_code: 200
+        verify_response_with:
+          function: validate_response:compare_response_with_pattern
+          extra_kwargs:
+            ignore_tags: "<bridge community>"
diff --git a/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-311119.pat.json b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-311119.pat.json
new file mode 100644
index 000000000..b749778a7
--- /dev/null
+++ b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-311119.pat.json
@@ -0,0 +1,26 @@
+{
+  "about": "",
+  "avatar_url": "",
+  "context": {},
+  "created_at": "2016-09-15 19:47:51",
+  "description": "",
+  "flag_text": "",
+  "id": 92532,
+  "is_nsfw": false,
+  "lang": "en",
+  "name": "hive-311119",
+  "num_authors": 0,
+  "num_pending": 0,
+  "settings": {},
+  "subscribers": 0,
+  "sum_pending": 0,
+  "team": [
+    [
+      "hive-311119",
+      "owner",
+      ""
+    ]
+  ],
+  "title": "@hive-311119",
+  "type_id": 3
+}
diff --git a/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-311119.tavern.yaml b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-311119.tavern.yaml
new file mode 100644
index 000000000..623ee80c5
--- /dev/null
+++ b/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_community/hive-311119.tavern.yaml
@@ -0,0 +1,28 @@
+---
+  test_name: Hivemind
+
+  marks:
+    - patterntest
+    # Communities not implemented under 5 mln blocks, but some were created by mock mechanism, therefore they are in result.
+
+  includes:
+    - !include ../../common.yaml
+
+  stages:
+    - name: test
+      request:
+        url: "{service.proto:s}://{service.server:s}:{service.port}/"
+        method: POST
+        headers:
+          content-type: application/json
+        json:
+          jsonrpc: "2.0"
+          id: 1
+          method: "bridge.get_community"
+          params: {"name":"hive-311119"}
+      response:
+        status_code: 200
+        verify_response_with:
+          function: validate_response:compare_response_with_pattern
+          extra_kwargs:
+            ignore_tags: "<bridge community>"
-- 
GitLab