Skip to content
Snippets Groups Projects
Commit d9465b67 authored by Bartek Wrona's avatar Bartek Wrona
Browse files

Merge branch 'pczempiel_list_subscribers' into 'develop'

Fix issue #164

See merge request !513
parents 130609e0 84e7f8f0
No related branches found
No related tags found
2 merge requests!518Delivery of new features and bugfixes into master branch.,!517Delivery of new features and bugfixes into master branch.
...@@ -3,7 +3,7 @@ CREATE TYPE bridge_api_list_subscribers AS ( ...@@ -3,7 +3,7 @@ CREATE TYPE bridge_api_list_subscribers AS (
name VARCHAR, name VARCHAR,
role VARCHAR, role VARCHAR,
title VARCHAR, title VARCHAR,
created_at VARCHAR(19) created_at TIMESTAMP WITHOUT TIME ZONE
); );
DROP FUNCTION IF EXISTS bridge_list_subscribers DROP FUNCTION IF EXISTS bridge_list_subscribers
...@@ -19,22 +19,22 @@ AS ...@@ -19,22 +19,22 @@ AS
$function$ $function$
DECLARE DECLARE
__community_id INT := find_community_id( _community, True ); __community_id INT := find_community_id( _community, True );
__last_id INT := find_account_id(_last, True); __last_id INT := find_subscription_id(_last, _community, True);
BEGIN BEGIN
RETURN QUERY RETURN QUERY
SELECT ha.name, get_role_name(COALESCE(hr.role_id,0)), hr.title, hs.created_at::VARCHAR(19) SELECT ha.name, get_role_name(COALESCE(hr.role_id,0)), hr.title, hs.created_at
FROM hive_subscriptions hs FROM hive_subscriptions hs
LEFT JOIN hive_roles hr ON hs.account_id = hr.account_id LEFT JOIN hive_roles hr ON hs.account_id = hr.account_id
AND hs.community_id = hr.community_id AND hs.community_id = hr.community_id
JOIN hive_accounts ha ON hs.account_id = ha.id JOIN hive_accounts ha ON hs.account_id = ha.id
WHERE hs.community_id = __community_id WHERE hs.community_id = __community_id
AND (__last_id = 0 OR ( AND (__last_id = 0 OR (
hs.created_at <= (SELECT min(created_at) FROM hive_subscriptions WHERE account_id = __last_id AND community_id = __community_id) AND hs.id < __last_id
hs.id > (SELECT max(id) FROM hive_subscriptions WHERE account_id = __last_id AND community_id = __community_id)
) )
) )
ORDER BY hs.created_at DESC, hs.id ASC ORDER BY hs.id DESC
LIMIT _limit; LIMIT _limit;
END END
$function$ $function$
; ;
\ No newline at end of file
...@@ -183,4 +183,34 @@ BEGIN ...@@ -183,4 +183,34 @@ BEGIN
; ;
END END
$function$ $function$
; ;
\ No newline at end of file
DROP FUNCTION IF EXISTS public.find_subscription_id CASCADE
;
CREATE OR REPLACE FUNCTION public.find_subscription_id(
in _account hive_accounts.name%TYPE,
in _community_name hive_communities.name%TYPE,
in _check BOOLEAN
)
RETURNS INTEGER
LANGUAGE 'plpgsql' STABLE
AS
$function$
DECLARE
__subscription_id INT = 0;
BEGIN
IF (_account <> '') THEN
SELECT INTO __subscription_id COALESCE( (
SELECT hs.id FROM hive_subscriptions hs
JOIN hive_accounts ha ON ha.id = hs.account_id
JOIN hive_communities hc ON hc.id = hs.community_id
WHERE ha.name = _account AND hc.name = _community_name
), 0 );
IF _check AND __subscription_id = 0 THEN
RAISE EXCEPTION '% subscription on % does not exist', _account, _community_name USING ERRCODE = 'CEHM9';
END IF;
END IF;
RETURN __subscription_id;
END
$function$
;
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import logging import logging
from hive.server.hive_api.common import (get_community_id) from hive.server.hive_api.common import (get_community_id)
from hive.server.common.helpers import (return_error_info, valid_community, valid_account, valid_limit) from hive.server.common.helpers import (return_error_info, valid_community, valid_account, valid_limit, json_date)
# pylint: disable=too-many-lines # pylint: disable=too-many-lines
...@@ -82,7 +82,7 @@ async def list_subscribers(context, community, last='', limit=100): ...@@ -82,7 +82,7 @@ async def list_subscribers(context, community, last='', limit=100):
db = context['db'] db = context['db']
sql = "SELECT * FROM bridge_list_subscribers( (:community)::VARCHAR, (:last)::VARCHAR, (:limit)::INT )" sql = "SELECT * FROM bridge_list_subscribers( (:community)::VARCHAR, (:last)::VARCHAR, (:limit)::INT )"
rows = await db.query_all(sql, community=community, last=last, limit=limit) rows = await db.query_all(sql, community=community, last=last, limit=limit)
return [(r[0], r[1], r[2], r[3]) for r in rows] return [(r[0], r[1], r[2], json_date(r[3])) for r in rows]
@return_error_info @return_error_info
async def list_communities(context, last='', limit=100, query=None, sort='rank', observer=None): async def list_communities(context, last='', limit=100, query=None, sort='rank', observer=None):
......
...@@ -2952,6 +2952,39 @@ ...@@ -2952,6 +2952,39 @@
"ref_block_prefix": 1, "ref_block_prefix": 1,
"expiration": "2020-03-23T12:17:00", "expiration": "2020-03-23T12:17:00",
"operations": [ "operations": [
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"hive-188204"
],
"id": "community",
"json": "[\"setRole\",{\"community\":\"hive-188204\",\"account\":\"gtg\",\"role\":\"muted\"}]"
}
},
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"agartha"
],
"id": "community",
"json": "[\"subscribe\",{\"community\":\"hive-186669\"}]"
}
},
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"alice"
],
"id": "community",
"json": "[\"subscribe\",{\"community\":\"hive-165317\"}]"
}
},
{ {
"type": "custom_json_operation", "type": "custom_json_operation",
"value": { "value": {
...@@ -3163,6 +3196,28 @@ ...@@ -3163,6 +3196,28 @@
"ref_block_prefix": 1, "ref_block_prefix": 1,
"expiration": "2020-03-23T12:17:00", "expiration": "2020-03-23T12:17:00",
"operations": [ "operations": [
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"hive-188204"
],
"id": "community",
"json": "[\"setRole\",{\"community\":\"hive-188204\",\"account\":\"alice\",\"role\":\"mod\"}]"
}
},
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"camilla"
],
"id": "community",
"json": "[\"subscribe\",{\"community\":\"hive-165317\"}]"
}
},
{ {
"type": "custom_json_operation", "type": "custom_json_operation",
"value": { "value": {
...@@ -3319,6 +3374,50 @@ ...@@ -3319,6 +3374,50 @@
"ref_block_prefix": 1, "ref_block_prefix": 1,
"expiration": "2020-03-23T12:17:00", "expiration": "2020-03-23T12:17:00",
"operations": [ "operations": [
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"hive-188204"
],
"id": "community",
"json": "[\"setRole\",{\"community\":\"hive-188204\",\"account\":\"agartha\",\"role\":\"admin\"}]"
}
},
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"abit"
],
"id": "community",
"json": "[\"subscribe\",{\"community\":\"hive-186669\"}]"
}
},
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"gtg"
],
"id": "community",
"json": "[\"subscribe\",{\"community\":\"hive-165317\"}]"
}
},
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"abit"
],
"id": "community",
"json": "[\"subscribe\",{\"community\":\"hive-165317\"}]"
}
},
{ {
"type": "custom_json_operation", "type": "custom_json_operation",
"value": { "value": {
...@@ -3518,6 +3617,39 @@ ...@@ -3518,6 +3617,39 @@
"ref_block_prefix": 1, "ref_block_prefix": 1,
"expiration": "2020-03-23T12:17:00", "expiration": "2020-03-23T12:17:00",
"operations": [ "operations": [
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"hive-188204"
],
"id": "community",
"json": "[\"setRole\",{\"community\":\"hive-188204\",\"account\":\"camilla\",\"role\":\"owner\"}]"
}
},
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"abit"
],
"id": "community",
"json": "[\"subscribe\",{\"community\":\"hive-188204\"}]"
}
},
{
"type": "custom_json_operation",
"value": {
"required_auths": [],
"required_posting_auths": [
"agartha"
],
"id": "community",
"json": "[\"subscribe\",{\"community\":\"hive-165317\"}]"
}
},
{ {
"type": "comment_operation", "type": "comment_operation",
"value": { "value": {
......
Subproject commit 2f3d374cb2a79cadc6a5fd3f1696f94b914b6939 Subproject commit 7a28ed11bdb362020a3d688cfd1acc93f5f0a44d
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment