/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2008-2010, Tomasz Sowa * All rights reserved. * */ #include "createthread.h" #include "functions.h" namespace Fun { CreateThread::CreateThread() { fun.url = L"createthread"; } // returning true if we can create a thread in the current directory bool CreateThread::HasAccess(bool check_root) { if( request->dir_tab.empty() ) return false; if( request->is_item ) return false; if( !system->HasWriteAccess(*request->dir_tab.back()) ) return false; if( !system->mounts.pmount || system->mounts.pmount->type != system->mounts.MountTypeThread() ) return false; if( !check_root && request->session && request->session->puser && request->session->puser->super_user ) // super can create thread regardless of the restrictcreatethread option return true; if( !system->mounts.pmount->IsPar(system->mounts.MountParCreatethreadOn()) ) return true; if( system->mounts.pmount->IsArg(system->mounts.MountParCreatethreadOn(), request->dir_tab.size()) ) return true; return false; } bool CreateThread::HasAccess() { return HasAccess(false); } bool CreateThread::FunCreateThreadCheckAbuse() { if( !system->rebus.CheckRebus() ) { request->status = WINIX_ERR_INCORRECT_REBUS; return false; } functions->CheckGetPostTimes(); if( request->session->spam_score > 0 ) { request->status = WINIX_ERR_SPAM; log << log1 << "Content: ignoring due to suspected spamming" << logend; return false; } return true; } void CreateThread::ReadThread() { thread.parent_id = request->dir_tab.back()->id; } void CreateThread::AddThread() { thread.dir_id = request->dir_tab.back()->id; thread.closed = false; thread.items = 1; thread.last_item = request->item; // set by PostFunEmacsAdd() request->status = db->AddThread(thread); } void CreateThread::PostFunCreateThreadLogAndRedirect() { if( request->status == WINIX_ERR_OK ) { log << log2 << "Content: added a new thread" << logend; system->RedirectToLastDir(); } else { log << log1 << "Content: problem with adding a new thread, error code: " << request->status << logend; } } void CreateThread::MakePost() { functions->ReadItem(request->item, Item::dir); functions->SetUser(request->item); ReadThread(); request->item.privileges = 0777; // !! tymczasowo 777 aby wszyscy mogli wysylac posty if( !FunCreateThreadCheckAbuse() ) { functions->ReadItemContentWithType(request->item); // for correctly displaying the form return; } request->status = system->dirs.AddDirectory(request->item, true); if( request->status == WINIX_ERR_OK ) { functions->ReadItemContentWithType(request->item); request->item.type = Item::file; request->item.privileges = 0644; // !! tymczasowo request->item.parent_id = request->dir_tab.back()->id; request->status = system->AddFile(request->item); if( request->status == WINIX_ERR_OK ) AddThread(); } PostFunCreateThreadLogAndRedirect(); } } // namespace