You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by hu...@apache.org on 2017/10/20 13:35:33 UTC

[kibble] 09/12: allow reinvite, which can toggle admin bit

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble.git

commit edeb43bc2bf66a4d52c6e3491758048b6d3712fc
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Fri Oct 20 15:31:01 2017 +0200

    allow reinvite, which can toggle admin bit
    
    ...but we still don't want people to remove themselves!
---
 api/pages/org/members.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/api/pages/org/members.py b/api/pages/org/members.py
index d57338f..f3187c9 100644
--- a/api/pages/org/members.py
+++ b/api/pages/org/members.py
@@ -163,16 +163,24 @@ def run(API, environ, indata, session):
                 doc['_source']['organisations'].append(orgid)
                 session.DB.ES.index(index=session.DB.dbname, doc_type='useraccount', id = newmember, body = doc['_source'])
             
-            # If adding as admin, we have to get the org doc and modify it
+            
+            # Get org doc from ES
+            doc = session.DB.ES.get(index=session.DB.dbname, doc_type='organisation', id = orgid)
             if isadmin:
-                # Get org doc from ES
-                doc = session.DB.ES.get(index=session.DB.dbname, doc_type='organisation', id = orgid)
                 if newmember not in doc['_source']['admins']:
                     doc['_source']['admins'].append(newmember)
                     # Override old doc
                     session.DB.ES.index(index=session.DB.dbname, doc_type='organisation', id = orgid, body = doc['_source'])
                     time.sleep(1) # Bleh!!
-                
+            
+            # If an admin, and not us, and reinvited, we purge the admin bit
+            elif newmember in doc['_source']['admins']:
+                if newmember == session.user['email']:
+                    raise API.exception(403, "You can't remove yourself from an organisation.")
+                doc['_source']['admins'].remove(newmember)
+                # Override old doc
+                session.DB.ES.index(index=session.DB.dbname, doc_type='organisation', id = orgid, body = doc['_source'])
+                time.sleep(1) # Bleh!!
             yield json.dumps({"okay": True, "message": "Member invited!!"})
             
             return

-- 
To stop receiving notification emails like this one, please contact
"commits@kibble.apache.org" <co...@kibble.apache.org>.