示例#1
0
def standup_send(token, channel_id, message):
    ##### ALL ERROR CHECKING.
    channel_all = storage.load_channel_all()
    ### ERROR: channel_id is not a valid channel.
    if channel_id not in channel_all:
        raise InputError()
    channel = channel_all[channel_id]
    standup = channel['standup']
    ### ERROR: an active standup is not currently running in this channel
    if standup['is_active'] == False:
        raise InputError()
    ### ERROR: message is more than 1000 characters.
    if len(message) > 1000:
        raise InputError()
    ### ERROR: user is not a member of the channel that the standup is occurring in.
    user_all_data = auth.get_data()
    u_id = helper.get_id(token, user_all_data)
    members_list = channel['member']
    owners_list = channel['owner']
    if u_id not in (members_list or owners_list):
        raise AccessError()
    ### ERROR: if because of all the above checks the standup becomes not active, dont send the message.
    if standup['is_active'] == False:
        raise InputError()

    ##### ACTUALLY SENDING THE MESSAGE TO THE QUEUE.
    user_data = user_all_data[u_id]
    handlestr = user_data['handlestr']
    standup['message_queue'] += generate_standup_message(handlestr, message)
    storage.save_channel_all()
    return {}
def channel_leave(token,channel_id):
    channel_id = str(channel_id)
    channel_data = get_data()
    user_data = auth.get_data()
    u_id = helper.get_id(token,user_data)
    helper.check_channel(channel_id,channel_data)
    helper.check_access(u_id,channel_data,channel_id)
    storage.remove_member(u_id,channel_id)
def channel_join(token, channel_id):
    channel_id = str(channel_id)
    channel_data = get_data()
    user_data = auth.get_data()
    # if channel_data[channel_id]['access'] == "False" : print("yeet")
    helper.check_channel(channel_id,channel_data)
    helper.check_public_channel(channel_data,channel_id)
    u_id = helper.get_id(token,user_data)
    storage.add_member(u_id,channel_id)
def channel_invite(token,channel_id,u_id):
    u_id = str(u_id)
    channel_id = str(channel_id)
    data_channel = get_data()
    data_user = auth.get_data()
    helper.check_channel(channel_id,data_channel)
    helper.check_user(u_id,data_user)
    if data_user[u_id] not in data_channel[channel_id]['member']:
        helper.check_access(helper.get_id(token,data_user), data_channel, channel_id)
        storage.add_member(u_id, channel_id)
示例#5
0
def message_unreact(token, message_id, react_id):
    if not helper.check_valid_id(react_id):
        raise InputError('react_id is not a valid React ID')

    user_data = auth.get_data()
    u_id = helper.get_id(token, user_data)
    channel_data = get_data()
    react = helper.react_struct(react_id,u_id)
    for channel_id in channel_data:
        for message in channel_data[channel_id]['messages']:
            if message_id == message['message_id']:
                storage.remove_react(channel_id, message_id,react)
      
    return {}
示例#6
0
def channel_removeowner(token, channel_id, u_id):
    channel_id = str(channel_id)
    channel_data = get_data()
    # Error check that channel_id refers to a valid channel
    helper.check_channel(channel_id, data)

    # Error check if the user is not an owner
    data_user = auth.get_data()
    if data_user[u_id] not in channel_data[channel_id]['owner']:
        raise error.InputError

    # Error if the authorised user is not already a member of the channel
    helper.check_access(token, channel_data, channel_id)

    storage.remove_owner(u_id, channel_id)
示例#7
0
def channels_list(token):
    channel_data = get_data()
    user_data = auth.get_data()
    u_id = helper.get_id(token, user_data)

    channel_list = []

    for channel_id in channel_data:
        for member in channel_data[channel_id]['member']:
            if u_id == member['u_id']:
                channel_list.append({
                    'channel_id': channel_id,
                    'name': channel_data[channel_id]['name']
                })

    return {'channels': channel_list}
def channel_message(token,channel_id,start):
    channel_id = str(channel_id)
    user_data = auth.get_data()
    u_id = helper.get_id(token, user_data)
    channel_data = get_data()
    helper.check_channel(channel_id, channel_data)
    helper.check_access(u_id, channel_data, channel_id)
    index = start-1
    message = channel_data[channel_id]['messages']
    if start > len(message): raise error.InputError
    message_list = [i for i in message if message.index(i)>= index and message.index(i) <= 50+index]
    if len(message_list) < 50: end = -1
    else: end = 50
    
    return {
        'messages': message_list,
        'start': start,
        'end': end
    }
示例#9
0
def login_view(request):
    redirect_url = request.GET.get('b', reverse('public_polls'))
    if 'alumnus' in request.session:
        return redirect(redirect_url)
    if request.method == 'POST':
        auth_code = request.POST.get('auth_code', '')
        if auth_code:  # иначе анонимус
            data = auth.get_data(auth_code)
            if data['status'] == 'valid':
                alumnus, _ = core.models.Alumnus.objects.get_or_create(
                    cross_name_hash=hashlib.md5(
                        data['cross_name'].encode('utf-8')).hexdigest(),
                    cross_name=data['cross_name'],
                )
                data['id'] = alumnus.id
                request.session['alumnus'] = data
                request.session['auth_code'] = auth_code
                return redirect(redirect_url)
        messages.error(request, u'Код не принят')
        return redirect(reverse('login'))
    return render(request, 'login.html', {'b': urlquote(redirect_url)})
示例#10
0
def message_sendlater(token, channel_id, message, time_sent):

    data = storage.load_channel_all()
    user_data = auth.get_data()
    u_id = helper.get_id(token,user_data)
    helper.check_access(u_id,data,channel_id)
    u_id = helper.get_id(token, user_data)

    message_id = helper.channel_id()
    
    # Channel ID is not a valid channel
    if not helper.valid_channel_id(channel_id, data):
        raise InputError('Channel id is not a valid channel')

    # helper.check_access(u_id,data, channel_id)
    if len(message) > 1000:
        raise InputError("Message should be under 1000 characters.")

    now = datetime.now()
    current_time = datetime.timestamp(now)
    if time_sent < current_time:
        raise InputError('The time entered is a time in the past')


    message_data = {
        'message_id': message_id,
        'u_id':u_id,
        'reacts': False,
        'is_pinned': False,
        'message_text': message,
    }
    
    time = time_sent - current_time
    timer = threading.Timer(time, storage.add_message(message_data, channel_id), \
                            [message_data, channel_id])
    timer.start()


    return {'message_id': message_id} 
示例#11
0
def message_send(token,channel_id,message):

    data = storage.load_channel_all()
    user_data = auth.get_data()
    u_id = helper.get_id(token, user_data)
    helper.check_access(u_id,data,channel_id)
    message_id = helper.channel_id()
    # helper.check_access(u_id,data, channel_id)
    if len(message) > 1000:
        raise InputError("Message should be under 1000 characters.")
    time_created = helper.get_current_time_as_unix_timestamp()
    message_data = {
        'message_id': message_id,
        'u_id': u_id,
        'reacts': [],
        'is_pinned': False,
        'message_text': message,
        'time_created': time_created,
    }
    
    storage.add_message(message_data, channel_id)
    # channel['messages_list'].prepend(message_data)
    if message == "/hangman": return -1
    return {'message_id': message_id}