示例#1
0
    def new_cinvitation(adminid, inviteid, cid):
        # check if adminid == inviteid
        if adminid == inviteid:
            raise CinvitationError.InviteYourSelf(
                "The user you invite shouldn't be yourself")

        # check if channel exist
        sql = "select * from {} where cid='{}'".format(
            CinvitatioinConstant.CHANNELS, cid)
        channel_data = Database.fetchone(sql)
        if channel_data is None:
            raise CinvitationError.ChannelNotExistsError(
                "The channel in this request doesn't exist")

        # check whether the user invited is already in the workspace
        sql = "select * from {} where cid='{}' and uid='{}'".format(
            CinvitatioinConstant.INCLUDE, cid, inviteid)
        invitation_data = Database.fetchone(sql)
        if invitation_data is not None:
            raise CinvitationError.UserAlreadyInChannel(
                "The user you invite is already in the channel")

        # check whether the user invited exist
        if not User.exist_user(inviteid):
            raise CinvitationError.UserNotExistsError(
                "The user you are inviting doesn't exist")

        # update table : cinvite
        sql = "insert into {}(adminid, inviteid, cid, stamp, is_read, is_accepted)values('{}', '{}', '{}',now(), {}, {})".format(
            CinvitatioinConstant.COLLECTION, adminid, inviteid, cid, 'False',
            'False')
        Database.execute(sql)
        return True
示例#2
0
    def new_channel(user_id, cname, cdescript, ctype, wid):
        if not User.exist_user(user_id):
            raise UserError.UserNotExistsError("The admin_id doesn't exist")
        if not Workspace.exist_workspace(wid):
            raise WorkspaceError.WorkspaceNotExistsError(
                "The workspace you want to created channel in doesn't exist")
        if ctype < 0 or ctype > 2:
            raise ChannelError.ChannelTypeError(
                "The Channel Type from your input is invalid")
        if len(cname) > 50:
            raise ChannelError.InputTooLongError(
                "The input of channel name is too long")
        if len(cdescript) > 100:
            raise ChannelError.InputTooLongError(
                "The input of channel description is too long")

        sql = "select * from {} where cname='{}' and wid='{}'".format(
            ChannelConstants.COLLECTION, cname, wid)
        channel_data = Database.fetchone(sql)

        if channel_data is not None:
            raise ChannelError.ChannelAlreadyExist("The channel exists.")
        sql = "insert into {}(cname, cdescript, wid, ctype, creatorid, stamp)values('{}', '{}', '{}', '{}', '{}', now())".format(
            ChannelConstants.COLLECTION, cname, cdescript, wid, ctype, user_id)
        Database.execute(sql)

        # add creator into channel
        sql = "select * from {} where cname='{}' and wid='{}'".format(
            ChannelConstants.COLLECTION, cname, wid)
        tup = Database.fetchone(sql)
        cid = tup[0]
        sql = "insert into {}(cid, uid)values({}, {})".format(
            ChannelConstants.INCLUDE, cid, user_id)
        Database.execute(sql)
        return True
示例#3
0
    def promote_user_to_admin(user_id, wid):
        """
        admin user promote a normal user to another admin
        :param user_id: the user id to be promoted
        :param wid: workspace id
        :return:
        """
        if not Workspace.exist_workspace(wid):
            raise WorkspaceError.WorkspaceNotExistsError(
                "This workspace doesn't exists")
        if not User.exist_user(user_id):
            raise UserError.UserNotExistsError(
                "The user you want to promote doesn't exists")

        # update the admintable
        sql = "insert into {}(adminid, wid)values('{}', '{}')".format(
            WorkspaceConstants.ADMINTABLE, user_id, wid)
        Database.execute(sql)
        return True