Skip to content

Commit

Permalink
Teams API methods, prepare for 2.5.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
vvgrem@gmail.com authored and vvgrem@gmail.com committed May 15, 2021
1 parent c4409e8 commit a3ffafa
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 32 deletions.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ $web = $client->getWeb();
$list = $web->getLists()->getByTitle("{list-title}"); //init List resource
$items = $list->getItems(); //prepare a query to retrieve from the
$client->load($items); //save a query to retrieve list items from the server
$client->executeQuery(); //submit query to SharePoint Online REST service
$client->executeQuery(); //submit query to SharePoint server
/** @var ListItem $item */
foreach($items as $item) {
print "Task: {$item->getProperty('Title')}\r\n";
Expand Down Expand Up @@ -198,6 +198,31 @@ $client->executeQuery();

### Working with Teams API

#### Example: create a Team
The following is an example of a minimal request to create a Team (via delegated permissions)

```php

use Office365\GraphServiceClient;
use Office365\Runtime\Auth\AADTokenProvider;
use Office365\Runtime\Auth\UserCredentials;

function acquireToken()
{
$tenant = "{tenant}.onmicrosoft.com";
$resource = "https://graph.microsoft.com";

$provider = new AADTokenProvider($tenant);
return $provider->acquireTokenForPassword($resource, "{clientId}",
new UserCredentials("{UserName}", "{Password}"));
}

$client = new GraphServiceClient("acquireToken");
$teamName = "My Sample Team";
$newTeam = $client->getTeams()->add($teamName)->executeQuery();

```



### Working with Outlook API
Expand Down
6 changes: 4 additions & 2 deletions src/Common/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
*/
namespace Office365\Common;

use Office365\Runtime\ClientObject;
use Office365\Entity;

/**
* ". Deleted items will remain available to restore for up to 30 days. After 30 days, the items are permanently deleted."
*/
class Directory extends ClientObject
class Directory extends Entity
{


}
21 changes: 18 additions & 3 deletions src/Common/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
*/
class Group extends DirectoryObject
{

/**
* Create a new team under a group.
*/
public function addTeam(){

}


/**
* Describes a classification for the group (such as low, medium or high business impact). Valid values for this property are defined by creating a ClassificationList [setting](groupsetting.md) value, based on the [template definition](groupsettingtemplate.md).<br><br>Returned by default.
* @return string
Expand All @@ -44,13 +53,16 @@ public function getDescription()
{
return $this->getProperty("Description");
}

/**
* An optional description for the group. <br><br>Returned by default.
*
* @return self
* @var string
*/
public function setDescription($value)
{
$this->setProperty("Description", $value, true);
return $this->setProperty("Description", $value, true);
}
/**
* The display name for the group. This property is required when a group is created and cannot be cleared during updates. <br><br>Returned by default. Supports $filter and $orderby.
Expand All @@ -60,13 +72,16 @@ public function getDisplayName()
{
return $this->getProperty("DisplayName");
}

/**
* The display name for the group. This property is required when a group is created and cannot be cleared during updates. <br><br>Returned by default. Supports $filter and $orderby.
* The display name for the group. This property is required when a group is created and cannot be cleared during updates. <br><br>Returned by default. Supports $filter and $orderby.
*
* @return self
* @var string
*/
public function setDisplayName($value)
{
$this->setProperty("DisplayName", $value, true);
return $this->setProperty("DisplayName", $value, true);
}
/**
* Indicates whether there are members in this group that have license errors from its group-based license assignment. <br><br>This property is never returned on a GET operation. You can use it as a $filter argument to get groups that have members with license errors (that is, filter for this property being true). See an [example](../api/group-list.md).
Expand Down
3 changes: 0 additions & 3 deletions src/SharePoint/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,9 +874,6 @@ public function setValidationFormula($value)
*/
public function getValidationMessage()
{
if (!$this->isPropertyAvailable("ValidationMessage")) {
return null;
}
return $this->getProperty("ValidationMessage");
}
/**
Expand Down
3 changes: 0 additions & 3 deletions src/SharePoint/ListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ public function setIconOverlay($value)
*/
public function getId()
{
if (!$this->isPropertyAvailable("Id")) {
return null;
}
return $this->getProperty("Id");
}
/**
Expand Down
22 changes: 9 additions & 13 deletions src/SharePoint/UserProfiles/HashTagCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,22 @@
*/
namespace Office365\SharePoint\UserProfiles;

use Office365\Runtime\ClientObject;

use Office365\Runtime\ResourcePath;
use Office365\SharePoint\BaseEntity;
use Office365\SharePoint\BaseEntityCollection;

class HashTagCollection extends ClientObject

class HashTagCollection extends BaseEntity
{
/**
* @return HashTagCollection
*/
public function getItems()
{
if (!$this->isPropertyAvailable("Items")) {
return null;
}
return $this->getProperty("Items");
}
/**
* @var HashTagCollection
*/
public function setItems($value)
{
$this->setProperty("Items", $value, true);
return $this->getProperty("Items",
new BaseEntityCollection($this->getContext(),
new ResourcePath("items",$this->resourcePath), HashTag::class));
}

}
8 changes: 3 additions & 5 deletions src/SharePoint/UserProfiles/UserProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@

class UserProfile extends BaseEntity
{
/*public function __construct(ClientRuntimeContext $ctx)
{
parent::__construct($ctx, new ResourcePath("SP.UserProfiles.ProfileLoader.getProfileLoader/getUserProfile"));
}*/

/**
* Enqueues creating a personal site for this user, which can be used to share documents, web pages, and other files.
*/
public function createPersonalSiteEnque()
{
$qry = new InvokePostMethodQuery($this, "createPersonalSiteEnque", array(false));
$this->getContext()->addQuery($qry);
return $this;
}
/**
* @return string
Expand Down Expand Up @@ -396,7 +394,7 @@ public function getUrlToCreatePersonalSite()

/**
* @param $value
* @return $this
* @return self
*/
public function setUrlToCreatePersonalSite($value)
{
Expand Down
40 changes: 39 additions & 1 deletion src/Teams/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
*/
namespace Office365\Teams;

use Office365\Common\DirectoryObject;
use Office365\Common\User;
use Office365\Entity;
use Office365\EntityCollection;
use Office365\Runtime\Actions\InvokePostMethodQuery;
use Office365\Runtime\Http\RequestOptions;
use Office365\Runtime\ResourcePath;


/**
Expand Down Expand Up @@ -129,9 +134,42 @@ public function setFunSettings($value)
return $this->setProperty("FunSettings", $value, true);
}

/**
* @return EntityCollection
*/
public function getMembers()
{
return $this->getProperty("Members",
new EntityCollection($this->getContext(),
new ResourcePath("Members",$this->getResourcePath()),DirectoryObject::class));
}


/**
* @param User $user
* @param string[] $roles
* @return Entity
*/
public function addMember($user, $roles){
$returnType = new Entity($this->getContext());
$this->getMembers()->addChild($returnType);

$user->ensureProperty("Id",function () use ($user, $returnType, $roles){
$payload = array(
"@odata.type" => "#microsoft.graph.aadUserConversationMember",
"roles" => $roles,
"user@odata.bind" => "https://graph.microsoft.com/v1.0/users('{$user->getId()}')"
);
$qry = new InvokePostMethodQuery($this->getMembers(),null,null,null,$payload);
$this->getContext()->addQueryAndResultObject($qry, $returnType);

});
return $returnType;
}

/**
* Deletes a Team
* @return Team
* @return self
*/
public function deleteObject()
{
Expand Down
38 changes: 37 additions & 1 deletion tests/teams/TeamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Office365;


use Office365\Common\User;
use Office365\Runtime\Http\RequestException;
use Office365\Teams\Team;
use Office365\Teams\TeamGuestSettings;
Expand Down Expand Up @@ -58,6 +59,41 @@ public function testUpdateTeam(Team $team)
self::assertNotNull($team->getResourcePath());
}

/**
* @depends testGetTeam
* @param Team $team
* @throws \Exception
*/
public function testAddTeamMember(Team $team)
{
/** @var User $user */
$user = self::$graphClient->getUsers()->getById(self::$testAccountName);
$member = $team->addMember($user, ["owner"])->executeQuery();
self::assertNotNull($member->getResourcePath());
return $member;
}

/**
* @depends testGetTeam
* @param Team $team
* @throws \Exception
*/
public function testListTeamMembers(Team $team)
{
$members = $team->getMembers()->get()->executeQueryRetry(3,5);
self::assertNotNull($members->getResourcePath());
}

/**
* @depends testAddTeamMember
* @param Entity $member
* @throws \Exception
*/
public function testRemoveTeamMember(Entity $member)
{
$member->deleteObject()->executeQuery();
}

/**
* @depends testGetTeam
* @param Team $team
Expand All @@ -66,7 +102,7 @@ public function testUpdateTeam(Team $team)
public function testDeleteTeam(Team $team)
{
$deletedId = $team->getId();
$team->deleteObject()->executeQuery();
$team->deleteObject()->executeQueryRetry();
try {
self::$graphClient->getGroups()->getById($deletedId)->get()->executeQuery();
}
Expand Down

0 comments on commit a3ffafa

Please sign in to comment.