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

Multiple fixes and add Group Backend support #384

Closed
wants to merge 11 commits into from
Closed
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ In non-SSL environments (like on development setups) it is necessary to set two

`./occ config:app:set circles --value 1 local_is_non_ssl`

## Allow mirroring circles as groups

```bash
./occ maintenance:mode --on

./occ config:app:set circles --value 1 group_backend # Mirroring circles as groups
./occ config:app:set circles --value 0 allow_listed_circles # Hide circles in shared list, useful with the 'group_backend' option

# ./occ config:app:set circles --value "🌀 " group_backend_name_prefix # You can customize group name prefix
# ./occ config:app:set circles --value " " group_backend_name_suffix # Remove default group name suffix with a `space` character

./occ config:app:set circles --value 12 allow_circles # Only show 'public' and 'closed' circles
./occ config:app:set circles --value 1 skip_invitation_to_closed_circles

./occ config:app:set circles --value 0 allow_files_filtered_by_circles # Disable files list filtering by circles in the 'files' application
./occ config:app:set circles --value 0 allow_adding_any_group_members # Adding group members only for groups where the current user is a member or global administrators

./occ maintenance:mode --off
```

# Credits

App Icon by [Madebyoliver](http://www.flaticon.com/authors/madebyoliver) under Creative Commons BY 3.0
5 changes: 1 addition & 4 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,4 @@


$app = \OC::$server->query(Application::class);
$app->registerNavigation();
$app->registerFilesNavigation();
$app->registerFilesPlugin();

$app->register();
21 changes: 18 additions & 3 deletions lib/Activity/ProviderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
use OCA\Circles\Model\FederatedLink;
use OCA\Circles\Model\Member;
use OCA\Circles\Service\MiscService;
use OCA\Circles\Service\ConfigService;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\IL10N;
use OCP\IURLGenerator;

class ProviderParser {


/** @var MiscService */
protected $miscService;

Expand All @@ -52,13 +52,28 @@ class ProviderParser {
/** @var IManager */
protected $activityManager;

/** @var ConfigService */
protected $configService;

/**
* @param IURLGenerator $url
* @param IManager $activityManager
* @param IL10N $l10n
* @param MiscService $miscService
* @param ConfigService $configService
*/
public function __construct(
IURLGenerator $url, IManager $activityManager, IL10N $l10n, MiscService $miscService
IURLGenerator $url,
IManager $activityManager,
IL10N $l10n,
MiscService $miscService,
ConfigService $configService
) {
$this->url = $url;
$this->activityManager = $activityManager;
$this->l10n = $l10n;
$this->miscService = $miscService;
$this->configService = $configService;
}


Expand Down Expand Up @@ -299,7 +314,7 @@ protected function generateViewerParameter(Circle $circle) {
*/
protected function generateExternalMemberParameter(Member $member) {
return [
'type' => 'user',
'type' => $member->getTypeName(),
'id' => $member->getUserId(),
'name' => $member->getDisplayName() . ' (' . $member->getTypeString() . ')',
'_parsed' => $member->getDisplayName()
Expand Down
8 changes: 6 additions & 2 deletions lib/Activity/ProviderSubjectMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public function parseSubjectMemberJoin(IEvent $event, Circle $circle, Member $me
* @throws FakeException
*/
private function parseSubjectMemberJoinClosedCircle(IEvent $event, Circle $circle, Member $member) {
if ($circle->getType() !== Circle::CIRCLES_CLOSED) {
if ($circle->getType() !== Circle::CIRCLES_CLOSED ||
$this->configService->isInvitationSkipped()
) {
return;
}

Expand Down Expand Up @@ -141,7 +143,9 @@ private function parseSubjectMemberAddNotLocalMember(IEvent $event, Circle $circ
* @throws FakeException
*/
private function parseSubjectMemberAddClosedCircle(IEvent $event, Circle $circle, Member $member) {
if ($circle->getType() !== Circle::CIRCLES_CLOSED) {
if ($circle->getType() !== Circle::CIRCLES_CLOSED ||
$this->configService->isInvitationSkipped()
) {
return;
}

Expand Down
13 changes: 11 additions & 2 deletions lib/Api/Sharees.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Circles\Service\CirclesService;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\MiscService;
use OCP\Share;

Expand Down Expand Up @@ -61,12 +62,20 @@ protected static function getContainer() {
// public static function search($search, $limit, $offset) {
public static function search($search) {
$c = self::getContainer();

$type = Circle::CIRCLES_ALL;
$circlesAreVisible = $c->query(ConfigService::class)
->isListedCirclesAllowed();
if (!$circlesAreVisible) {
$type = $type - Circle::CIRCLES_CLOSED - Circle::CIRCLES_PUBLIC;
}

$userId = \OC::$server->getUserSession()
->getUser()
->getUID();

$data = $c->query(CirclesService::class)
->listCircles($userId, Circle::CIRCLES_ALL, $search, Member::LEVEL_MEMBER);
->listCircles($userId, $type, $search, Member::LEVEL_MEMBER);
$result = array(
'exact' => ['circles'],
'circles' => []
Expand Down Expand Up @@ -111,4 +120,4 @@ private static function addResultEntry(&$result, $entry, $exact = false) {

}

}
}
38 changes: 38 additions & 0 deletions lib/Api/v1/Circles.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCA\Circles\Model\Member;
use OCA\Circles\Model\SharingFrame;
use OCA\Circles\Service\CirclesService;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\FederatedLinkService;
use OCA\Circles\Service\MembersService;
use OCA\Circles\Service\MiscService;
Expand Down Expand Up @@ -181,6 +182,43 @@ public static function leaveCircle($circleUniqueId) {
public static function listCircles($type, $name = '', $level = 0, $userId = '', $forceAll = false) {
$c = self::getContainer();

$configService = $c->query(ConfigService::class);
$circlesAreVisible = $configService->isListedCirclesAllowed();
$circlesAllowed = (int)$configService->getAppValue(ConfigService::CIRCLES_ALLOW_CIRCLES);

if (!$circlesAreVisible) {
switch (true) {
case ($type === Circle::CIRCLES_CLOSED):
case ($type === Circle::CIRCLES_PUBLIC):
case (Circle::CIRCLES_CLOSED + Circle::CIRCLES_PUBLIC === $circlesAllowed):
return [];
break;
case ($type === Circle::CIRCLES_ALL &&
$circlesAllowed === Circle::CIRCLES_ALL
):
$type = $type - Circle::CIRCLES_CLOSED - Circle::CIRCLES_PUBLIC;
break;
case ($type > Circle::CIRCLES_CLOSED &&
$type < Circle::CIRCLES_PUBLIC &&
$circlesAllowed === Circle::CIRCLES_ALL
):
$type = $type - Circle::CIRCLES_CLOSED;
break;
case ($type > Circle::CIRCLES_PUBLIC &&
$type < (Circle::CIRCLES_PUBLIC + Circle::CIRCLES_CLOSED) &&
$circlesAllowed === Circle::CIRCLES_ALL
):
$type = $type - Circle::CIRCLES_PUBLIC;
break;
case ($type > (Circle::CIRCLES_PUBLIC + Circle::CIRCLES_CLOSED) &&
$type < Circle::CIRCLES_ALL &&
$circlesAllowed === Circle::CIRCLES_ALL
):
$type = $type - Circle::CIRCLES_PUBLIC - Circle::CIRCLES_CLOSED;
break;
}
}

if ($userId === '') {
$userId = \OC::$server->getUserSession()
->getUser()
Expand Down
108 changes: 91 additions & 17 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@

namespace OCA\Circles\AppInfo;

use OC;
use OCA\Circles\Api\v1\Circles;
use OCA\Circles\Notification\Notifier;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\DavService;
use OCA\Circles\Service\GroupsBackendService;
use OCA\Files\App as FilesApp;
use OCP\App\ManagerEvent;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\AppFramework\QueryException;
use OCP\IGroup;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Util;

require_once __DIR__ . '/../../appinfo/autoload.php';
Expand All @@ -56,22 +58,36 @@ class Application extends App {
/** @var IAppContainer */
private $container;

/** @var \OC\ServerServer */
private $server;

/** @var IEventDispatcher */
private $dispatcher;

/**
* @param array $params
*/
public function __construct(array $params = array()) {
parent::__construct(self::APP_NAME, $params);
}

public function register()
{
$this->container = $this->getContainer();
$this->server = $this->container->getServer();
$this->dispatcher = $this->server->query(IEventDispatcher::class);

$manager = OC::$server->getNotificationManager();
$manager = $this->server->getNotificationManager();
$manager->registerNotifierService(Notifier::class);

$this->registerNavigation();
$this->registerFilesNavigation();
$this->registerFilesPlugin();
$this->registerHooks();
$this->registerDavHooks();
$this->registerGroupsBackendHooks();
}


/**
* Register Hooks
*/
Expand All @@ -91,7 +107,7 @@ public function registerHooks() {
public function registerNavigation() {
/** @var ConfigService $configService */
try {
$configService = OC::$server->query(ConfigService::class);
$configService = $this->server->query(ConfigService::class);
} catch (QueryException $e) {
return;
}
Expand All @@ -104,8 +120,8 @@ public function registerNavigation() {
->getNavigationManager();
$appManager->add(
function() {
$urlGen = OC::$server->getURLGenerator();
$navName = OC::$server->getL10N(self::APP_NAME)
$urlGen = $this->server->getURLGenerator();
$navName = $this->server->getL10N(self::APP_NAME)
->t('Circles');

return [
Expand All @@ -121,8 +137,17 @@ function() {
}

public function registerFilesPlugin() {
$eventDispatcher = OC::$server->getEventDispatcher();
$eventDispatcher->addListener(
try {
/** @var ConfigService $configService */
$configService = $this->server->query(ConfigService::class);
if (!$configService->isFilesFilteredCirclesAllowed()) {
return;
}
} catch (QueryException $e) {
return;
}

$this->dispatcher->addListener(
'OCA\Files::loadAdditionalScripts',
function() {
Circles::addJavascriptAPI();
Expand All @@ -140,10 +165,20 @@ function() {
*
*/
public function registerFilesNavigation() {
try {
/** @var ConfigService $configService */
$configService = $this->server->query(ConfigService::class);
if (!$configService->isFilesFilteredCirclesAllowed()) {
return;
}
} catch (QueryException $e) {
return;
}

$appManager = FilesApp::getNavigationManager();
$appManager->add(
function() {
$l = OC::$server->getL10N('circles');
$l = $this->server->getL10N('circles');

return [
'id' => 'circlesfilter',
Expand All @@ -160,24 +195,63 @@ function() {
public function registerDavHooks() {
try {
/** @var ConfigService $configService */
$configService = OC::$server->query(ConfigService::class);
$configService = $this->server->query(ConfigService::class);
if (!$configService->isContactsBackend()) {
return;
}

/** @var DavService $davService */
$davService = OC::$server->query(DavService::class);
$davService = $this->server->query(DavService::class);
} catch (QueryException $e) {
return;
}

$event = OC::$server->getEventDispatcher();
$this->dispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, [$davService, 'onAppEnabled']);
$this->dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', [$davService, 'onCreateCard']);
$this->dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', [$davService, 'onUpdateCard']);
$this->dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', [$davService, 'onDeleteCard']);
}

$event->addListener(ManagerEvent::EVENT_APP_ENABLE, [$davService, 'onAppEnabled']);
$event->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', [$davService, 'onCreateCard']);
$event->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', [$davService, 'onUpdateCard']);
$event->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', [$davService, 'onDeleteCard']);
public function registerGroupsBackendHooks() {
try {
/** @var ConfigService $configService */
$configService = $this->server->query(ConfigService::class);
if (!$configService->isGroupsBackend()) {
return;
}

/** @var GroupsBackendService $groupsBackendService */
$groupsBackendService = $this->server->query(GroupsBackendService::class);
} catch (QueryException $e) {
return;
}

$this->dispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, [$groupsBackendService, 'onAppEnabled']);
$this->dispatcher->addListener('\OCA\Circles::onCircleCreation', [$groupsBackendService, 'onCircleCreation']);
$this->dispatcher->addListener('\OCA\Circles::onCircleDestruction', [$groupsBackendService, 'onCircleDestruction']);
$this->dispatcher->addListener('\OCA\Circles::onMemberNew', [$groupsBackendService, 'onMemberNew']);
$this->dispatcher->addListener('\OCA\Circles::onMemberInvited', [$groupsBackendService, 'onMemberInvited']);
$this->dispatcher->addListener('\OCA\Circles::onMemberRequesting', [$groupsBackendService, 'onMemberRequesting']);
$this->dispatcher->addListener('\OCA\Circles::onMemberLeaving', [$groupsBackendService, 'onMemberLeaving']);
$this->dispatcher->addListener('\OCA\Circles::onMemberLevel', [$groupsBackendService, 'onMemberLevel']);
$this->dispatcher->addListener('\OCA\Circles::onMemberOwner', [$groupsBackendService, 'onMemberOwner']);
$this->dispatcher->addListener('\OCA\Circles::onGroupLink', [$groupsBackendService, 'onGroupLink']);
$this->dispatcher->addListener('\OCA\Circles::onGroupUnlink', [$groupsBackendService, 'onGroupUnlink']);
$this->dispatcher->addListener('\OCA\Circles::onGroupLevel', [$groupsBackendService, 'onGroupLevel']);
$this->dispatcher->addListener('\OCA\Circles::onLinkRequestSent', [$groupsBackendService, 'onLinkRequestSent']);
$this->dispatcher->addListener('\OCA\Circles::onLinkRequestReceived', [$groupsBackendService, 'onLinkRequestReceived']);
$this->dispatcher->addListener('\OCA\Circles::onLinkRequestRejected', [$groupsBackendService, 'onLinkRequestRejected']);
$this->dispatcher->addListener('\OCA\Circles::onLinkRequestCanceled', [$groupsBackendService, 'onLinkRequestCanceled']);
$this->dispatcher->addListener('\OCA\Circles::onLinkRequestAccepted', [$groupsBackendService, 'onLinkRequestAccepted']);
$this->dispatcher->addListener('\OCA\Circles::onLinkRequestAccepting', [$groupsBackendService, 'onLinkRequestAccepting']);
$this->dispatcher->addListener('\OCA\Circles::onLinkUp', [$groupsBackendService, 'onLinkUp']);
$this->dispatcher->addListener('\OCA\Circles::onLinkDown', [$groupsBackendService, 'onLinkDown']);
$this->dispatcher->addListener('\OCA\Circles::onLinkRemove', [$groupsBackendService, 'onLinkRemove']);
$this->dispatcher->addListener('\OCA\Circles::onSettingsChange', [$groupsBackendService, 'onSettingsChange']);

$this->dispatcher->addListener(IGroup::class . '::postAddUser', [$groupsBackendService, 'onGroupPostAddUser']);
$this->dispatcher->addListener(IGroup::class . '::postRemoveUser', [$groupsBackendService, 'onGroupPostRemoveUser']);
$this->dispatcher->addListener(IGroup::class . '::postDelete', [$groupsBackendService, 'onGroupPostDelete']);
}

}

Loading