<commit_before><?php

namespace Controllers\Adm\Mship;

use \AuthException;
use \Input;
use \Auth;
use \Session;
use \Response;
use \Request;
use \URL;
use \View;
use \VatsimSSO;
use \Config;
use \Redirect;
use \DB;
use \Models\Mship\Account as AccountData;
use \Models\Mship\Account\Security as AccountSecurityData;
use Models\Mship\Role as RoleData;
use Models\Mship\Security as SecurityData;
use Models\Mship\Account\Note as AccountNoteData;
use Models\Mship\Note\Type as NoteTypeData;
use Models\Sys\Timeline\Entry as TimelineEntryData;

class Account extends \Controllers\Adm\AdmController {

    public function getIndex() {
        $totalMembers = AccountData::count();
        $memberSearch = new AccountData;

        // Sorting and searching!
        $sortBy = in_array(Input::get("sort_by"), ["account_id", "name_first", "name_last"]) ? Input::get("sort_by") : "account_id";
        $sortDir = in_array(Input::get("sort_dir"), ["ASC", "DESC"]) ? Input::get("sort_dir") : "ASC";

        // ORM it all!
        $memberSearch = AccountData::isNotSystem()
                                   ->orderBy($sortBy, $sortDir)
                                   ->with("qualifications")
                                   ->with("qualifications.qualification")
                                   ->with("states")
                                   ->with("emails")
                                   ->paginate(50);

        return $this->viewMake("adm.mship.account.index")
                    ->with("members", $memberSearch)
                    ->with("sortBy", $sortBy)
                    ->with("sortDir", $sortDir)
                    ->with("sortDirSwitch", ($sortDir == "DESC" ? "ASC" : "DESC"));
    }

    public function getDetail(AccountData $account, $tab="basic") {
        if (!$account OR $account->is_system) {
            return Redirect::route("adm.mship.account.index");
        }

        // Do they have permission to view their own profile?
        if(!$this->_account->hasPermission("adm/mship/account/own")){
            return Redirect::route("adm.mship.account.index")->withError("You cannot view or manage your own profile.");
        }

        // Lazy eager loading
        $account->load(
                "notes", "notes.type", "notes.writer",
                "messagesReceived", "messagesReceived.sender",
                "messagesSent", "messagesSent.recipient",
                "dataChanges",
                "roles", "roles.permissions",
                "qualifications",
                "states",
                "emails",
                "security",
                "security.security"
        );

        // Get all possible roles!
        $availableRoles = RoleData::all()->diff($account->roles);

        // Get all possible security levels.
        $securityLevels = SecurityData::all();

        // Get all possible note types.
        $noteTypes = NoteTypeData::usable()->orderBy("name", "ASC")->get();
        $noteTypesAll = NoteTypeData::withTrashed()->orderBy("name", "ASC")->get();

        $this->_pageTitle = "Account Details: " . $account->name;

        return $this->viewMake("adm.mship.account.detail")
                        ->with("selectedTab", $tab)<commit_msg>Commit 59cc65f  improved to actually stop members viewing their own account, rather than stopping them viewing any account.<commit_after><?php

namespace Controllers\Adm\Mship;

use \AuthException;
use \Input;
use \Auth;
use \Session;
use \Response;
use \Request;
use \URL;
use \View;
use \VatsimSSO;
use \Config;
use \Redirect;
use \DB;
use \Models\Mship\Account as AccountData;
use \Models\Mship\Account\Security as AccountSecurityData;
use Models\Mship\Role as RoleData;
use Models\Mship\Security as SecurityData;
use Models\Mship\Account\Note as AccountNoteData;
use Models\Mship\Note\Type as NoteTypeData;
use Models\Sys\Timeline\Entry as TimelineEntryData;

class Account extends \Controllers\Adm\AdmController {

    public function getIndex() {
        $totalMembers = AccountData::count();
        $memberSearch = new AccountData;

        // Sorting and searching!
        $sortBy = in_array(Input::get("sort_by"), ["account_id", "name_first", "name_last"]) ? Input::get("sort_by") : "account_id";
        $sortDir = in_array(Input::get("sort_dir"), ["ASC", "DESC"]) ? Input::get("sort_dir") : "ASC";

        // ORM it all!
        $memberSearch = AccountData::isNotSystem()
                                   ->orderBy($sortBy, $sortDir)
                                   ->with("qualifications")
                                   ->with("qualifications.qualification")
                                   ->with("states")
                                   ->with("emails")
                                   ->paginate(50);

        return $this->viewMake("adm.mship.account.index")
                    ->with("members", $memberSearch)
                    ->with("sortBy", $sortBy)
                    ->with("sortDir", $sortDir)
                    ->with("sortDirSwitch", ($sortDir == "DESC" ? "ASC" : "DESC"));
    }

    public function getDetail(AccountData $account, $tab="basic") {
        if (!$account OR $account->is_system) {
            return Redirect::route("adm.mship.account.index");
        }

        // Do they have permission to view their own profile?
        if($this->_account->account_id == $account->account_id && !$this->_account->hasPermission("adm/mship/account/own")){
            return Redirect::route("adm.mship.account.index")->withError("You cannot view or manage your own profile.");
        }

        // Lazy eager loading
        $account->load(
                "notes", "notes.type", "notes.writer",
                "messagesReceived", "messagesReceived.sender",
                "messagesSent", "messagesSent.recipient",
                "dataChanges",
                "roles", "roles.permissions",
                "qualifications",
                "states",
                "emails",
                "security",
                "security.security"
        );

        // Get all possible roles!
        $availableRoles = RoleData::all()->diff($account->roles);

        // Get all possible security levels.
        $securityLevels = SecurityData::all();

        // Get all possible note types.
        $noteTypes = NoteTypeData::usable()->orderBy("name", "ASC")->get();
        $noteTypesAll = NoteTypeData::withTrashed()->orderBy("name", "ASC")->get();

        $this->_pageTitle = "Account Details: " . $account->name;

        return $this->viewMake("adm.mship.account.detail")
                        ->with("selectedTab", $tab)
{'fraction_non_alphanumeric': 0.14283552731124224, 'fraction_numerical': 0.0012104705704342564, 'mean_word_length': 2.1076633756464505, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4025036', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1777, 'n_words': 398}