Пример #1
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        groupid = data.get("id", "")
        device = data.get("device", "")

        if not groupid:
            logging.error("disattach failed without groupid")
            self.set_status(403)
            self.finish()
            return

        group = yield GroupMgrMgr.getgroup(groupid)
        
        if not group:
            self.set_status(404)
            self.finish()
            return

        #handle pc and app
        if device:
            other_device = GroupMgrMgr.get_other_device(device)

            self.removekey(device, self.p_userid, groupid)
            
            if self.isotherexist(other_device, self.p_userid, groupid) == True:
                self.set_status(200)
                self.finish()
                return

            

        result = yield group.disattach_member(self.p_userid)

        self.set_status(result)
        self.finish()
Пример #2
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        sharecoll = self.application.db.shareids
        shareid = data.get("shareid", "")

        logging.info("begin to add member with share id %s" % shareid)

        if not shareid:
            logging.error("invalid request")
            self.set_status(403)
            self.finish()
            return

        shareinfo = yield sharecoll.find_one({"id": shareid})

        if not shareinfo:
            logging.error("share id not found")
            self.set_status(404)
            self.finish()
            return

        groupid = shareinfo.get("groupid", "")
        
        group = yield GroupMgrMgr.getgroup(groupid)

        if not group:
            logging.error("group %s does not exist" % groupid)
            self.set_status(404)
            self.finish()
            return

        if group.is_realname() == True:
            self.set_status(403)
            self.finish()
            return

        if group.get_join_id() != shareid:
            logging.error("shareid not macth")
            self.set_status(404)
            self.finish()
            return

        #add members
        add_rst = yield group.add_members([self.p_userid])

        if add_rst == 200:
            new_group = yield GroupMgrMgr.getgroup(groupid)
            groupinfo = yield new_group.createDisplayResponse()
            self.write(groupinfo)

        self.set_status(add_rst)
        self.finish()
Пример #3
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        groupid = data.get("id", "")

        if not groupid:
            logging.error("close failed without groupid")
            self.set_status(403)
            self.finish()
            return

        group = yield GroupMgrMgr.getgroup(groupid)
        
        if not group:
            self.set_status(404)
            self.finish()
            return

        if self.p_userid != group.get_owner():
            logging.error("%s is not the owner of %s" % (self.p_userid, groupid))
            self.set_status(403)
            self.finish()
            return

        result = yield group.close()

        self.set_status(result)
        self.finish()
Пример #4
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        open_id = data.get("open_id", "")

        if not open_id:
            logging.error("query failed without openid")
            self.set_status(403)
            self.finish()
            return

        group = yield GroupMgrMgr.searchgroup(open_id)
        
        if not group:
            self.set_status(404)
            self.finish()
            return

        groupinfo = {}
        groupinfo["id"] = group.get_id()
        groupinfo["name"] = group.get_name()
        groupinfo["invite"] = group.get_invite()
        groupinfo["tp_chatid"] = group.get_chatid()
        groupinfo["open_id"] = group.get_openid()


        self.write(groupinfo)
        self.finish()
Пример #5
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        groupid = data.get("id", "")
        password = data.get("password", None)

        if not groupid:
            logging.error("open failed without groupid")
            self.set_status(403)
            self.finish()
            return

        group = yield GroupMgrMgr.getgroup(groupid)
        
        if not group:
            self.set_status(404)
            self.finish()
            return

        if self.p_userid != group.get_owner():
            logging.error("%s is not the owner of %s" % (self.p_userid, groupid))
            self.set_status(403)
            self.finish()
            return

        (result, open_id) = yield group.open(password)

        if result == 200:
            self.write({"open_id":open_id})

        self.set_status(result)
        self.finish()
Пример #6
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        groupid = data.get("groupid", "")

        logging.info("begin to enable id share id = %s" % (groupid))

        if not groupid:
            logging.error("invalid request")
            self.set_status(403)
            self.finish()
            return

        group = yield GroupMgrMgr.getgroup(groupid)

        if not group:
            logging.error("group not found")
            self.set_status(404)
            self.finish()
            return

        owner = group.get_owner()

        if owner != self.p_userid:
            self.set_status(403)
            self.finish()
            return

        yield group.disable_id_join()

        self.set_status(200)
        self.finish()
Пример #7
0
    def isotherexist(self, device, userid, groupid):
        kp_key = GroupMgrMgr.get_kpalive_key(device, userid, groupid)
        if kp_key:
            redis_key = mickey.redis.read_from_redis(kp_key)
            if redis_key:
                return True

        return False
Пример #8
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))

        (result_code, result_body) = yield GroupMgrMgr.createGroup(self.p_userid, data)

        self.set_status(result_code)
        if result_body:
            self.write(result_body)

        self.finish()
Пример #9
0
    def post(self):
        coll = self.application.userdb.users
        groupcoll = self.application.db.groups
        data = json.loads(self.request.body.decode("utf-8"))
        userid = data.get("userid", "invalid")

        logging.info("begin to list group of user %s" % userid)

        if self.p_userid != userid:
            logging.error("forbiden you can not query other user")
            self.set_status(403)
            self.finish()
            return

        user = yield coll.find_one({"id":userid})
        if user:
            groups = user.get("groups", [])

            #get group
            public_groups = yield GroupMgrMgr.get_public_groups()
            public_group_ids = [x.get("id", "") for x in public_groups]

            list_groups = []
            for item in groups:
                groupid = item.get("id", "")
                if groupid:
                    group = yield groupcoll.find_one({"_id":ObjectId(groupid)})
                    if group:
                        groupinfo = {}
                        groupinfo["id"] = groupid
                        groupinfo["name"] = group.get("name", "")
                        groupinfo["invite"] = group.get("invite", "")
                        groupinfo["tp_chatid"] = group.get("tp_chatid", "")
                        groupinfo["open_id"] = group.get("open_id", "")
                        if groupid in public_group_ids:
                            groupinfo["sys"] = "true"

                        list_groups.append(groupinfo)

            #attach the system group
            group_ids = [x.get("id", "") for x in groups]

            if public_groups:
                for item in public_groups:
                    item_id = item.get("id", "")
                    if not item_id in group_ids:
                        list_groups.append(item)
                
            self.write({"groups": list_groups})
        else:
            logging.error("user %s found" % userid)
            self.set_status(404)
            self.write({"error":"not found"});

        self.finish()
Пример #10
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        groupid = data.get("id", "")
        device = data.get("device", "")

        if not groupid:
            logging.error("keep alive failed without groupid")
            self.set_status(403)
            self.finish()
            return

        if device:
            kp_key = GroupMgrMgr.get_kpalive_key(device, self.p_userid, groupid)
            mickey.redis.write_to_redis(kp_key, "OK", expire = 120)
            

        GroupMgrMgr.keepalive_attacher(groupid, self.p_userid)

        self.set_status(200)
        self.finish()
Пример #11
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        chatcoll = self.application.db.tbchats
        sharecoll = self.application.db.shareids
        groupid = data.get("groupid", None)
        chatid = data.get("chatid", None)
        shareid = data.get("shareid", None)

        if not groupid and not chatid and not shareid:
            logging.error("invalid parameter")
            self.set_status(403)
            self.finish()
            return

        logging.info("begin to display group %s" % groupid)

        if not groupid and chatid:
            chat = yield chatcoll.find_one({"id":chatid})
            if not chat:
                self.set_status(404)
                self.finish()
                return

            groupid = chat.get('gid', '')

        if not groupid and shareid:
            shareinfo = yield sharecoll.find_one({"id": shareid})
            if not shareinfo:
                self.set_status(404)
                self.finish()
                return

            groupid = shareinfo.get("groupid", "")

        group = yield GroupMgrMgr.getgroup(groupid)

        if group:
            groupinfo = yield group.createDisplayResponse()
            if groupinfo:
                self.write(groupinfo)
            else:
                self.set_status(404)
                self.write({"error":"not found"});
        else:
            logging.error("group %s does not exist" % groupid)
            self.set_status(404)
            self.write({"error":"not found"});

        self.finish()
Пример #12
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        groupid = data.get("id", "")
        device = data.get("device", "")
        password = data.get("password", "")

        if not groupid:
            logging.error("attach failed without groupid")
            self.set_status(403)
            self.finish()
            return

        group = yield GroupMgrMgr.getgroup(groupid)
        
        if not group:
            self.set_status(404)
            self.finish()
            return

        result = yield group.attach_member(self.p_userid)

        if result == 200:
            #save the attch
            if device:
                kp_key = GroupMgrMgr.get_kpalive_key(device, self.p_userid, groupid)
                if kp_key:
                    mickey.redis.write_to_redis(kp_key, "OK", expire = 120)
                    
            #reload the data from db
            yield group.load()
            res_body = yield group.createDisplayResponse()
            if res_body:
                self.write(res_body)

        self.set_status(result)
        self.finish()
Пример #13
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        groupid = data.get("groupid", "")

        logging.info("begin to enable id share id = %s" % (groupid))

        if not groupid:
            logging.error("invalid request")
            self.set_status(403)
            self.finish()
            return

        group = yield GroupMgrMgr.getgroup(groupid)

        if not group:
            logging.error("group not found")
            self.set_status(404)
            self.finish()
            return

        owner = group.get_owner()
        if owner != self.p_userid:
            logging.error("just owner was allowd to share the group")
            self.set_status(403)
            self.finish()
            return

        if group.is_realname() == True:
            logging.error("real group is forbidden to share")
            self.set_status(403)
            self.finish()
            return

        shareid = yield group.enable_id_join()

        if shareid:
            self.set_status(200)

            body = {"shareid": shareid}
            self.write(body)
        else:
            logging.error("share group failed")
            self.set_status(500)

        self.finish()
Пример #14
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        groupid = data.get("groupid", "")

        logging.info("begin to add members to group %s" % groupid)

        if not groupid:
            logging.error("invalid request")
            self.set_status(403)
            self.finish()
            return
        
        group = yield GroupMgrMgr.getgroup(groupid)

        if not group:
            logging.error("group %s does not exist" % groupid)
            self.set_status(404)
            self.finish()
            return

        rst_code = yield group.add_realmember(self.p_userid)
        self.set_status(rst_code)
        self.finish()
Пример #15
0
    def post(self):
        data = json.loads(self.request.body.decode("utf-8"))
        groupid = data.get("groupid", "")
        members = data.get("members", [])

        logging.info("begin to add members to group %s" % groupid)

        if not groupid or not members:
            logging.error("invalid request")
            self.set_status(403)
            self.finish()
            return
        
        group = yield GroupMgrMgr.getgroup(groupid)

        if not group:
            logging.error("group %s does not exist" % groupid)
            self.set_status(404)
            self.finish()
            return

        if group.is_realname() == True:
            return self.redirect("/group/authadd/members")

        #check operate right
        if group.has_member(self.p_userid) == False:
            logging.error("%s are not the member" % self.p_userid)
            self.set_status(403)
            self.finish()
            return

        #add members
        add_rst = yield group.add_members([x.get("id", "") for x in members])

        self.set_status(add_rst)
        self.finish()
Пример #16
0
    def post(self):
        coll = self.application.db.groups
        publish = self.application.publish
        token = self.request.headers.get("Authorization", "")
        data = json.loads(self.request.body.decode("utf-8"))
        groupid      = data.get("groupid", "")
        members      = data.get("members", [])
        operasadmin  = data.get("operasadmin", "false")

        logging.info("begin to add members to group %s" % groupid)

        if not groupid or not members:
            logging.error("invalid request")
            self.set_status(403)
            self.finish()
            return
        
        group = yield GroupMgrMgr.getgroup(groupid)

        if not group:
            logging.error("group %s does not exist" % groupid)
            self.set_status(404)
            self.finish()
            return

        if group.is_realname() == False:
            return self.redirect("/group/add/members")

        #get exist members

        if operasadmin == "false" and group.has_member(self.p_userid) == False:
            logging.error("%s are not the member" % self.p_userid)
            self.set_status(403)
            self.finish()
            return

        group_members = group.get_members()

        # get members and the receivers
        add_members = list(filter(lambda x: x not in group_members, [x.get("id", "") for x in members]))

        owner = group.get_owner()
        if operasadmin == "true":
            self.p_userid = owner

        if owner == self.p_userid:
            mydevices = yield filter_mydevice(self.p_userid, add_members)
            if mydevices:
                yield group.add_members(mydevices)
                add_members = list(set(add_members) - set(mydevices))

            if not add_members:
                self.finish()
                return

            notify = {}
            notify["name"] = "mx.group.authgroup_invited"
            notify["pub_type"] = "any"
            notify["nty_type"] = "device"
            notify["msg_type"] = "other"
            notify["groupid"] = groupid
            notify["groupname"] = group.get_name()
            notify["userid"] = self.p_userid
            opter_info = yield mickey.userfetcher.getcontact(self.p_userid, token)
            if opter_info:
                notify["username"] = opter_info.get("name", "")
            else:
                logging.error("get user info failed %s" % self.p_userid)
                
            adddb_members = list(filter(lambda x: x.get("id", "") in add_members, members))
            append_result = yield coll.find_and_modify({"_id":ObjectId(groupid)}, 
                                                       {
                                                         "$addToSet":{"appendings":{"$each": adddb_members}},
                                                         "$unset": {"garbage": 1}
                                                       })
            if append_result:
                self.set_status(200)
                publish.publish_multi(add_members, notify)
            else:
                self.set_status(500)
                logging.error("add user failed %s" % groupid)

            self.finish()
            return
        else:
            notify = {}
            notify["name"] = "mx.group.member_apply"
            notify["pub_type"] = "any"
            notify["nty_type"] = "device"
            notify["msg_type"] = "other"
            notify["groupid"] = groupid
            notify["groupname"] = group.get_name()
            notify["userid"] = self.p_userid
            opter_info = yield mickey.userfetcher.getcontact(self.p_userid, token)
            if opter_info:
                notify["username"] = opter_info.get("name", "")
                notify["usernickname"] = opter_info.get("commName", "")
            else:
                logging.error("get user failed %s" % self.p_userid)
                
            noti_members = []
            for item in add_members:
                member = {}
                member["id"] = item
                user_info = yield mickey.userfetcher.getcontact(item, token)
                if user_info:
                    member["name"] = user_info.get("name", "")
                    member["nickname"] = user_info.get("commName", "")

                noti_members.append(member)

            notify["members"] = noti_members
            publish.publish_one(owner, notify)
            self.finish()
            return
Пример #17
0
 def removekey(self, device, userid, groupid):
     kp_key = GroupMgrMgr.get_kpalive_key(device, userid, groupid)
     if kp_key:
         mickey.redis.remove_from_redis(kp_key)