Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.16] Update method of checking friendship humhub/humhub#6745 #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions models/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use humhub\modules\file\libs\FileHelper;
use humhub\modules\file\models\File as BaseFile;
use humhub\modules\file\models\FileUpload;
use humhub\modules\friendship\Module as FriendshipModule;
use humhub\modules\search\events\SearchAddEvent;
use humhub\modules\topic\models\Topic;
use Yii;
Expand Down Expand Up @@ -98,7 +99,7 @@ public function rules()
['hidden', 'boolean'],
];

if($this->parentFolder && $this->parentFolder->content->isPublic()) {
if ($this->parentFolder && $this->parentFolder->content->isPublic()) {
$rules[] = ['visibility', 'integer', 'min' => 0, 'max' => 1];
}

Expand All @@ -110,7 +111,7 @@ public function rules()
*/
public function attributeLabels()
{
return array_merge(parent::attributeLabels(),[
return array_merge(parent::attributeLabels(), [
'id' => 'ID',
'parent_folder_id' => Yii::t('CfilesModule.models_File', 'Folder ID')
]);
Expand All @@ -125,11 +126,11 @@ public function getSearchAttributes()
'description' => $this->description
];

if($this->getCreator()) {
if ($this->getCreator()) {
$attributes['creator'] = $this->getCreator()->getDisplayName();
}

if($this->getEditor()) {
if ($this->getEditor()) {
$attributes['editor'] = $this->getEditor()->getDisplayName();
}

Expand Down Expand Up @@ -207,16 +208,17 @@ public function updateVisibility($visibility)
return;
}

if(!$this->parentFolder->content->isPrivate() || $visibility == Content::VISIBILITY_PRIVATE) {
if (!$this->parentFolder->content->isPrivate() || $visibility == Content::VISIBILITY_PRIVATE) {
// For user profile files we use Content::VISIBILITY_OWNER isntead of private
$this->content->visibility = $visibility;
}
}

public function getVisibilityTitle()
{
if(Yii::$app->getModule('friendship')->getIsEnabled() && $this->content->container instanceof User) {
if($this->content->container->isCurrentuser()) {
$module = Yii::$app->getModule('friendship');
if ($module instanceof FriendshipModule && $module->isFriendshipEnabled() && $this->content->container instanceof User) {
if ($this->content->container->isCurrentuser()) {
$privateText = Yii::t('CfilesModule.base', 'This file is only visible for you and your friends.');
} else {
$privateText = Yii::t('CfilesModule.base', 'This file is protected.');
Expand Down Expand Up @@ -324,7 +326,7 @@ public function getFullUrl()
*/
public function getDownloadUrl($forceDownload = false, $scheme = true)
{
if(!$scheme) {
if (!$scheme) {
return DownloadFileHandler::getUrl($this->baseFile, $forceDownload);
} else {
// Todo can be removed after v1.2.3 then call DownloadFileHandler::getUrl($this->baseFile, $forceDownload, $scheme)
Expand Down Expand Up @@ -385,7 +387,7 @@ public static function getPathFromId($id, $parentFolderPath = false, $separator
}
$counter = 0;
// break at maxdepth 20 to avoid hangs
while (!empty($tempFolder) && $counter ++ <= 20) {
while (!empty($tempFolder) && $counter++ <= 20) {
$path = $separator . $tempFolder->title . $path;
$tempFolder = $tempFolder->parentFolder;
}
Expand Down Expand Up @@ -415,7 +417,7 @@ public static function getPostedFiles($contentContainer, $filesOrder = ['file.up

$query->andWhere(['content.contentcontainer_id' => $contentContainer->contentContainerRecord->id]);

if(!$contentContainer->canAccessPrivateContent()) {
if (!$contentContainer->canAccessPrivateContent()) {
// Note this will cut comment images, but including the visibility of comments is pretty complex...
$query->andWhere(['content.visibility' => Content::VISIBILITY_PUBLIC]);
}
Expand All @@ -424,10 +426,11 @@ public static function getPostedFiles($contentContainer, $filesOrder = ['file.up

// only accept Posts as the base content, so stuff from sumbmodules like files itsself or gallery will be excluded
$query->andWhere(
['or',
['or',
['=', 'comment.object_model', \humhub\modules\post\models\Post::className()],
['=', 'file.object_model', \humhub\modules\post\models\Post::className()]
]);
]
);

// Get Files from comments
return $query->orderBy($filesOrder);
Expand Down
19 changes: 10 additions & 9 deletions models/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use humhub\modules\file\libs\ImageHelper;
use humhub\modules\file\models\FileContent;
use humhub\modules\file\libs\FileHelper;
use humhub\modules\friendship\Module as FriendshipModule;
use humhub\modules\user\models\User;
use humhub\modules\search\events\SearchAddEvent;
use humhub\modules\space\models\Space;
Expand Down Expand Up @@ -34,7 +35,6 @@
*/
class Folder extends FileSystemItem
{

const TYPE_FOLDER_ROOT = 'root';
const TYPE_FOLDER_POSTED = 'posted';
const ROOT_TITLE = 'Root';
Expand Down Expand Up @@ -155,11 +155,11 @@ public function getSearchAttributes()
'description' => $this->description
];

if($this->getCreator()) {
if ($this->getCreator()) {
$attributes['creator'] = $this->getCreator()->getDisplayName();
}

if($this->getEditor()) {
if ($this->getEditor()) {
$attributes['editor'] = $this->getEditor()->getDisplayName();
}
}
Expand All @@ -174,7 +174,7 @@ public function beforeSave($insert)
{
if ($insert && $this->visibility !== null) {
$this->content->visibility = $this->visibility;
} else if ($this->visibility !== null && $this->visibility != $this->content->visibility) {
} elseif ($this->visibility !== null && $this->visibility != $this->content->visibility) {
$this->updateVisibility($this->visibility);
}
return parent::beforeSave($insert);
Expand Down Expand Up @@ -281,7 +281,8 @@ public function beforeDelete()

public function getVisibilityTitle()
{
if (Yii::$app->getModule('friendship')->getIsEnabled() && $this->content->container instanceof User) {
$module = Yii::$app->getModule('friendship');
if ($module instanceof FriendshipModule && $module->isFriendshipEnabled() && $this->content->container instanceof User) {
if ($this->content->container->isCurrentuser()) {
$privateText = Yii::t('CfilesModule.base', 'This folder is only visible for you and your friends.');
} else {
Expand Down Expand Up @@ -432,7 +433,7 @@ private static function getContainerOwnerId(ContentContainerActiveRecord $conten
{
if ($contentContainer instanceof User) {
return $contentContainer->id;
} else if ($contentContainer instanceof Space) {
} elseif ($contentContainer instanceof Space) {
return $contentContainer->created_by;
}

Expand Down Expand Up @@ -524,7 +525,7 @@ public function getTitle()
{
if ($this->isRoot()) {
return Yii::t('CfilesModule.base', 'Root');
} else if ($this->isAllPostedFiles()) {
} elseif ($this->isAllPostedFiles()) {
return Yii::t('CfilesModule.base', 'Files from the stream');
}

Expand All @@ -535,7 +536,7 @@ public function getDescription()
{
if ($this->isRoot()) {
return Yii::t('CfilesModule.base', 'The root folder is the entry point that contains all available files.');
} else if ($this->isAllPostedFiles()) {
} elseif ($this->isAllPostedFiles()) {
return Yii::t('CfilesModule.base', 'You can find all files that have been posted to this stream here.');
}

Expand Down Expand Up @@ -912,7 +913,7 @@ private function checkForDuplicate(FileSystemItem $item)
if ($item instanceof File) {
$item->setTitle($this->getAddedFileName($item->getTitle()));
$result = $item;
} else if ($item instanceof Folder) {
} elseif ($item instanceof Folder) {
$result = $item;

$existingFolderWithTitle = $this->findFolderByName($item->title);
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"version": "0.16.3",
"humhub": {
"minVersion": "1.14"
"minVersion": "1.16"
},
"homepage": "https://github.com/humhub/cfiles",
"authors": [
Expand Down