/* * 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 = "createthread"; } // returning true if we can create a thread in the current directory bool CreateThread::HasAccess() { if( request->dir_table.empty() ) return false; if( request->is_item ) return false; if( !system->HasWriteAccess(*request->dir_table.back()) ) return false; if( !system->mounts.pmount || system->mounts.pmount->type != Mount::thread ) return false; if( 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(Mount::par_createthread_on) ) return true; if( system->mounts.pmount->IsArg(Mount::par_createthread_on, request->dir_table.size()) ) return true; return 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 & thread) { thread.parent_id = request->dir_table.back()->id; } void CreateThread::AddThread() { request->thread.dir_id = request->dir_table.back()->id; request->thread.closed = false; request->thread.items = 1; request->thread.last_item = request->item; // set by PostFunEmacsAdd() request->status = db->AddThread(request->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->thread); 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_table.back()->id; request->status = system->AddFile(request->item); if( request->status == WINIX_ERR_OK ) AddThread(); } PostFunCreateThreadLogAndRedirect(); } } // namespace