Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix various comments / types
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 18, 2016
1 parent c90b7de commit 27155e1
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 29 deletions.
Expand Up @@ -34,6 +34,6 @@ class UserNotFoundException extends PydioException
*/
public function __construct($userId)
{
parent::__construct("Cannot find user ".$userId, null, 50014);
parent::__construct("Cannot find user ".$userId, false, 50014);
}
}
7 changes: 6 additions & 1 deletion core/src/core/src/pydio/Core/Model/UserInterface.php
Expand Up @@ -266,7 +266,12 @@ public function getMergedRole();
* @return AJXP_Role
*/
public function getPersonalRole();


/**
* @param AJXP_Role $role
*/
public function updatePersonalRole(AJXP_Role $role);

/**
* @return bool
* @throws \Exception
Expand Down
1 change: 0 additions & 1 deletion core/src/core/src/pydio/Core/Services/AuthService.php
Expand Up @@ -85,7 +85,6 @@ public static function getLoggedUser()
public static function logUser($user_id, $pwd, $bypass_pwd = false, $cookieLogin = false, $returnSeed="")
{
$user_id = UsersService::filterUserSensitivity($user_id);
$confDriver = ConfService::getConfStorageImpl();
$authDriver = ConfService::getAuthDriverImpl();
// CHECK USER PASSWORD HERE!
$loginAttempt = BruteForceHelper::getBruteForceLoginArray();
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Services/RolesService.php
Expand Up @@ -137,7 +137,7 @@ public static function getOrCreateRole($roleId, $groupPath)
* Create or update role
*
* @param AJXP_Role $roleObject
* @param null $userObject
* @param UserInterface|null $userObject
*/
public static function updateRole($roleObject, $userObject = null)
{
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/src/pydio/Core/Services/UsersService.php
Expand Up @@ -80,7 +80,7 @@ public static function getUserById($userId, $checkExists = true){
$test = CacheService::fetch("shared", "pydio:user:" . $userId);
if($test !== false && $test instanceof UserInterface){
if($test->getPersonalRole() === null){
$test->personalRole = $test->roles["AJXP_USR_/".$userId];
$test->updatePersonalRole($test->getRoles()["AJXP_USR_/".$userId]);
}
$test->recomputeMergedRole();
$self->usersCache[$userId] = $test;
Expand All @@ -90,7 +90,7 @@ public static function getUserById($userId, $checkExists = true){
throw new UserNotFoundException($userId);
}
// Try to get from conf
$userObject = ConfService::getConfStorageImpl()->createUserObject($userId, false);
$userObject = ConfService::getConfStorageImpl()->createUserObject($userId);
if($userObject instanceof UserInterface){
// Save in memory
$self->usersCache[$userId] = $userObject;
Expand Down
Expand Up @@ -28,6 +28,7 @@
use Pydio\Access\Core\Filter\AJXP_PermissionMask;
use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Core\Model\UserSelection;
use Pydio\Conf\Core\AbstractAjxpUser;
use Pydio\Core\Exception\UserNotFoundException;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
Expand Down Expand Up @@ -714,7 +715,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
$sharedRepos = array();
if(isSet($userObject)){
// Add User shared Repositories as well
$acls = $userObject->mergedRole->listAcls();
$acls = $userObject->getMergedRole()->listAcls();
if(count($acls)) {
$sharedRepos = RepositoryService::listRepositoriesWithCriteria(array(
"uuid" => array_keys($acls),
Expand Down Expand Up @@ -804,7 +805,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
foreach($rolesList as $rId => $rObj){
$data["ALL"]["ROLES_DETAILS"][$rId] = array("label" => $rObj->getLabel(), "sticky" => $rObj->alwaysOverrides());
}
if (isSet($userObject->parentRole)) {
if ($userObject instanceof AbstractAjxpUser && isSet($userObject->parentRole)) {
$data["PARENT_ROLE"] = $userObject->parentRole->getDataArray();
}
} else if (isSet($groupPath)) {
Expand Down Expand Up @@ -976,7 +977,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
try {
$originalRole->bunchUpdate($roleData);
if (isSet($userObject)) {
$userObject->personalRole = $originalRole;
$userObject->updatePersonalRole($originalRole);
$userObject->save("superuser");
} else {
RolesService::updateRole($originalRole);
Expand Down Expand Up @@ -1259,7 +1260,6 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct

case "user_update_role" :

$confStorage = ConfService::getConfStorageImpl();
$selection = UserSelection::fromContext($ctx, $httpVars);
$files = $selection->getFiles();
$detectedRoles = array();
Expand Down
7 changes: 6 additions & 1 deletion core/src/plugins/action.avatar/class.AvatarProvider.php
Expand Up @@ -33,6 +33,11 @@
*/
class AvatarProvider extends Plugin
{
/**
* @param \Psr\Http\Message\ServerRequestInterface $requestInterface
* @param \Psr\Http\Message\ResponseInterface $responseInterface
* @throws \Pydio\Core\Exception\UserNotFoundException
*/
public function receiveAction(\Psr\Http\Message\ServerRequestInterface &$requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface)
{
$ctx = $requestInterface->getAttribute("ctx");
Expand Down Expand Up @@ -68,7 +73,7 @@ public function receiveAction(\Psr\Http\Message\ServerRequestInterface &$request
$userid = $httpVars["userid"];
if (UsersService::usersEnabled() && UsersService::userExists($userid)) {
$user = UsersService::getUserById($userid, false);
$userEmail = $user->personalRole->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "");
$userEmail = $user->getPersonalRole()->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "");
if (!empty($userEmail)) {
$url .= md5(strtolower(trim($userEmail)));
}
Expand Down
10 changes: 4 additions & 6 deletions core/src/plugins/action.share/src/Store/ShareRightsManager.php
Expand Up @@ -430,12 +430,12 @@ public function assignSharedRepositoryPermissions($parentRepository, $childRepos
}

// ASSIGN NEW REPO RIGHTS
$userObject->personalRole->setAcl($childRepoId, $userEntry["RIGHT"]);
$userObject->getPersonalRole()->setAcl($childRepoId, $userEntry["RIGHT"]);

// FORK MASK IF THERE IS ANY
$childMask = $this->forkMaskIfAny($loggedUser, $parentRepository->getId(), $selection->getUniqueNode());
if($childMask != null){
$userObject->personalRole->setMask($childRepoId, $childMask);
$userObject->getPersonalRole()->setMask($childRepoId, $childMask);
}

// CREATE A MINISITE-LIKE ROLE FOR THIS REPOSITORY
Expand All @@ -448,9 +448,9 @@ public function assignSharedRepositoryPermissions($parentRepository, $childRepos
// ADD "my shared files" REPO OTHERWISE SOME USER CANNOT ACCESS
if( !isSet($userEntry["HIDDEN"]) && $childRepository->hasContentFilter()){
$inboxRepo = RepositoryService::getRepositoryById("inbox");
$currentAcl = $userObject->mergedRole->getAcl("inbox");
$currentAcl = $userObject->getMergedRole()->getAcl("inbox");
if($inboxRepo !== null && empty($currentAcl)){
$userObject->personalRole->setAcl("inbox", "rw");
$userObject->getPersonalRole()->setAcl("inbox", "rw");
}
}

Expand All @@ -474,8 +474,6 @@ public function assignSharedRepositoryPermissions($parentRepository, $childRepos
*/
public function unregisterRemovedUsers($repoId, $newUsers, $newGroups, $watcherNode = null){

$confDriver = ConfService::getConfStorageImpl();

$currentRights = $this->computeSharedRepositoryAccessRights(
$repoId,
false,
Expand Down
5 changes: 5 additions & 0 deletions core/src/plugins/core.conf/class.AbstractAjxpUser.php
Expand Up @@ -493,6 +493,11 @@ public function getPersonalRole()
return $this->personalRole;
}

public function updatePersonalRole(AJXP_Role $role)
{
$this->personalRole = $role;
}

protected function migrateRightsToPersonalRole()
{
$changes = 0;
Expand Down
90 changes: 80 additions & 10 deletions core/src/plugins/core.mailer/class.AjxpMailer.php
Expand Up @@ -22,6 +22,7 @@
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Core\Model\ContextInterface;
use Pydio\Conf\Core\AbstractAjxpUser;
use Pydio\Core\Model\UserInterface;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Services\LocaleService;
Expand Down Expand Up @@ -62,17 +63,32 @@ public function init(ContextInterface $ctx, $options = [])
}
}

/**
* @return array
* @throws Exception
*/
protected function getDibiDriver () {
if (!isset($this->_dibiDriver)) {
$this->_dibiDriver = Utils::cleanDibiDriverParameters(array("group_switch_value"=>"core"));
}
return $this->_dibiDriver;
}

/**
* @param $action
* @param $httpVars
* @param $fileVars
* @param ContextInterface $ctx
* @throws PydioException
*/
public function mailConsumeQueue ($action, $httpVars, $fileVars, ContextInterface $ctx) {

if ($action === "consume_mail_queue") {

$mailer = PluginsService::getInstance($ctx)->getActivePluginsForType("mailer", true);
if(!$mailer instanceof AjxpMailer){
throw new PydioException("Cannot find active mailer!");
}
if (!dibi::isConnected()) {
dibi::connect($this->getDibiDriver());
}
Expand Down Expand Up @@ -167,10 +183,19 @@ public function mailConsumeQueue ($action, $httpVars, $fileVars, ContextInterfac
}
}

/**
* @param $int
* @return string
*/
protected function stringify($int){
return ($int < 10 ? "0".$int : "".$int);
}

/**
* @param $frequencyType
* @param $frequencyDetail
* @return DateTime|int|null|string
*/
protected function computeEmailSendDate($frequencyType, $frequencyDetail){

$date = new DateTime("now");
Expand Down Expand Up @@ -233,6 +258,11 @@ protected function computeEmailSendDate($frequencyType, $frequencyDetail){
return $nextFrequency;
}

/**
* @param AJXP_Notification $notification
* @throws Exception
* @throws PydioException
*/
public function processNotification(AJXP_Notification &$notification)
{
try{
Expand All @@ -241,15 +271,15 @@ public function processNotification(AJXP_Notification &$notification)
$messages = LocaleService::getMessages();
throw new PydioException($messages['core.mailer.2']);
}
if($userObject->mergedRole->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL_GET", AJXP_REPO_SCOPE_ALL,"true") !== "true"){
if($userObject->getMergedRole()->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL_GET", AJXP_REPO_SCOPE_ALL,"true") !== "true"){
// User does not want to receive any emails.
return;
}

$notification_email = $userObject->mergedRole->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL", AJXP_REPO_SCOPE_ALL,"");
$notification_email = $userObject->getMergedRole()->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL", AJXP_REPO_SCOPE_ALL,"");
$arrayRecipients = array();
$mainRecipient = $userObject->mergedRole->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "");
$useHtml = $userObject->mergedRole->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL_SEND_HTML", AJXP_REPO_SCOPE_ALL,"true") === "true" ? 1 : 0;
$mainRecipient = $userObject->getMergedRole()->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "");
$useHtml = $userObject->getMergedRole()->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL_SEND_HTML", AJXP_REPO_SCOPE_ALL,"true") === "true" ? 1 : 0;

if(!empty($mainRecipient)) $arrayRecipients[] = $mainRecipient;
$additionalRecipients = array_map("trim", explode(',', $notification_email));
Expand All @@ -259,8 +289,8 @@ public function processNotification(AJXP_Notification &$notification)

if ($this->pluginConf["MAILER_ACTIVATE_QUEUE"] && count($arrayRecipients)) {

$frequencyType = $userObject->mergedRole->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL_FREQUENCY", AJXP_REPO_SCOPE_ALL,"M");
$frequencyDetail = $userObject->mergedRole->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL_FREQUENCY_USER", AJXP_REPO_SCOPE_ALL,"5");
$frequencyType = $userObject->getMergedRole()->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL_FREQUENCY", AJXP_REPO_SCOPE_ALL,"M");
$frequencyDetail = $userObject->getMergedRole()->filterParameterValue("core.mailer","NOTIFICATIONS_EMAIL_FREQUENCY_USER", AJXP_REPO_SCOPE_ALL,"5");
$nextFrequency = $this->computeEmailSendDate(
$frequencyType,
$frequencyDetail
Expand All @@ -287,7 +317,7 @@ public function processNotification(AJXP_Notification &$notification)
}
} else {
$mailer = PluginsService::getInstance($notification->getNode()->getContext())->getActivePluginsForType("mailer", true);
if ($mailer !== false) {
if ($mailer !== false && $mailer instanceof AjxpMailer) {
try {
$mailer->sendMail(
$notification->getNode()->getContext(),
Expand All @@ -305,6 +335,15 @@ public function processNotification(AJXP_Notification &$notification)
}
}

/**
* @param ContextInterface $ctx
* @param $recipients
* @param $subject
* @param $body
* @param null $from
* @param null $imageLink
* @param bool $useHtml
*/
public function sendMail(ContextInterface $ctx, $recipients, $subject, $body, $from = null, $imageLink = null, $useHtml = true)
{
$prepend = ConfService::getCoreConf("SUBJECT_PREPEND", "mailer");
Expand Down Expand Up @@ -361,9 +400,23 @@ public function sendMail(ContextInterface $ctx, $recipients, $subject, $body, $f
}
}

/**
* @param ContextInterface $ctx
* @param $recipients
* @param $subject
* @param $body
* @param null $from
* @param array $images
* @param bool $useHtml
*/
protected function sendMailImpl(ContextInterface $ctx, $recipients, $subject, $body, $from = null, $images = array(), $useHtml = true){
}

/**
* @param \Psr\Http\Message\ServerRequestInterface $requestInterface
* @param \Psr\Http\Message\ResponseInterface $responseInterface
* @throws Exception
*/
public function sendMailAction(\Psr\Http\Message\ServerRequestInterface &$requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface)
{
$mess = LocaleService::getMessages();
Expand Down Expand Up @@ -397,6 +450,11 @@ public function sendMailAction(\Psr\Http\Message\ServerRequestInterface &$reques
}
}

/**
* @param ContextInterface $ctx
* @param null $fromAdress
* @return array|mixed
*/
public function resolveFrom(ContextInterface $ctx, $fromAdress = null)
{
$fromResult = array();
Expand Down Expand Up @@ -467,24 +525,36 @@ public function resolveAdresses(ContextInterface $ctx, $recipients)
return $realRecipients;
}

public function abstractUserToAdress(AbstractAjxpUser $user)
/**
* @param UserInterface $user
* @return array|bool
*/
public function abstractUserToAdress(UserInterface $user)
{
// SHOULD CHECK THAT THIS USER IS "AUTHORIZED" TO AVOID SPAM
$userEmail = $user->personalRole->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "");
$userEmail = $user->getPersonalRole()->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "");
if (empty($userEmail)) {
return false;
}
$displayName = $user->personalRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, "");
$displayName = $user->getPersonalRole()->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, "");
if(empty($displayName)) $displayName = $user->getId();
return array("name" => $displayName, "adress" => $userEmail);
}


/**
* @param $email
* @return bool
*/
public function validateEmail($email)
{
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

/**
* @param $html
* @return string
*/
public static function simpleHtml2Text($html){

$html = preg_replace('/<br\>/', "\n", $html);
Expand Down

0 comments on commit 27155e1

Please sign in to comment.