Exemplo n.º 1
0
        private static async Task CreateSearchUserCollaboration(BoxFolder topFolder, BoxClient auClient,
                                                                TimeLimiter throttle)
        {
            var requestParams = new BoxCollaborationRequest()
            {
                Item = new BoxRequestEntity()
                {
                    Type = BoxType.folder,
                    Id   = topFolder.Id
                },
                Role         = Config.SearchUserRole,
                AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Id = Config.SearchUserId
                }
            };

            try
            {
                await throttle;
                await auClient.CollaborationsManager.AddCollaborationAsync(requestParams);
            }
            catch (BoxException be)
            {
                if (be.Message.Contains("user_already_collaborator"))
                {
                    // ignore
                    Console.WriteLine("コラボレーション設定済み");
                }
                else
                {
                    throw;
                }
            }
        }
        public async Task EditCollaboration_ValidResponse_ValidCollaboration()
        {
            /*** Arrange ***/
            string responseString = "{\"type\":\"collaboration\",\"id\":\"791293\",\"created_by\":{\"type\":\"user\",\"id\":\"17738362\",\"name\":\"sean rose\",\"login\":\"[email protected]\"},\"created_at\":\"2012-12-12T10:54:37-08:00\",\"modified_at\":\"2012-12-12T11:30:43-08:00\",\"expires_at\":null,\"status\":\"accepted\",\"accessible_by\":{\"type\":\"user\",\"id\":\"18203124\",\"name\":\"sean\",\"login\":\"[email protected]\"},\"role\":\"viewer\",\"acknowledged_at\":\"2012-12-12T11:30:43-08:00\",\"item\":{\"type\":\"folder\",\"id\":\"11446500\",\"sequence_id\":\"0\",\"etag\":\"0\",\"name\":\"Shared Pictures\"}}";

            Handler.Setup(h => h.ExecuteAsync <BoxCollaboration>(It.IsAny <IBoxRequest>()))
            .Returns(Task.FromResult <IBoxResponse <BoxCollaboration> >(new BoxResponse <BoxCollaboration>()
            {
                Status        = ResponseStatus.Success,
                ContentString = responseString
            }));

            /*** Act ***/
            BoxCollaborationRequest request = new BoxCollaborationRequest()
            {
                Id = "fakeId"
            };

            BoxCollaboration collab = await _collaborationsManager.EditCollaborationAsync(request);

            /*** Assert ***/
            Assert.AreEqual("791293", collab.Id);
            Assert.AreEqual("collaboration", collab.Type);
            Assert.AreEqual("user", collab.CreatedBy.Type);
            Assert.AreEqual("17738362", collab.CreatedBy.Id);
            Assert.AreEqual("*****@*****.**", collab.CreatedBy.Login);
        }
Exemplo n.º 3
0
        public async Task CollaborationsOnFolderWorkflow_LiveSession_ValidResponse()
        {
            const string folderId = "1927307787";

            // Add Collaboration
            BoxCollaborationRequest addRequest = new BoxCollaborationRequest()
            {
                Item = new BoxRequestEntity()
                {
                    Id   = folderId,
                    Type = BoxType.folder
                },
                AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Login = "******"
                },
                Role = "viewer"
            };

            BoxCollaboration collab = await _client.CollaborationsManager.AddCollaborationAsync(addRequest, notify : false);

            Assert.AreEqual(folderId, collab.Item.Id, "Folder and collaboration folder id do not match");
            Assert.AreEqual(BoxCollaborationRoles.Viewer, collab.Role, "Incorrect collaboration role");

            // Edit Collaboration
            BoxCollaborationRequest editRequest = new BoxCollaborationRequest()
            {
                Id          = collab.Id,
                Role        = BoxCollaborationRoles.Editor,
                CanViewPath = true
            };

            BoxCollaboration editCollab = await _client.CollaborationsManager.EditCollaborationAsync(editRequest);

            Assert.AreEqual(collab.Id, editCollab.Id, "Id of original collaboration and updated collaboration do not match");
            Assert.AreEqual(BoxCollaborationRoles.Editor, editCollab.Role, "Incorrect updated role");

            // get existing collaboration
            var existingCollab = await _client.CollaborationsManager.GetCollaborationAsync(collab.Id, fields : new List <string>()
            {
                "can_view_path"
            });

            Assert.IsTrue(existingCollab.CanViewPath.Value, "failed to retrieve existing collab with specific fields");

            // test getting list of collaborations on folder
            var collabs = await _client.FoldersManager.GetCollaborationsAsync(folderId);

            Assert.AreEqual(4, collabs.Entries.Count, "Failed to get correct number of folder collabs.");

            // Test Remove Collaboration
            bool success = await _client.CollaborationsManager.RemoveCollaborationAsync(collab.Id);

            Assert.IsTrue(success, "Collaboration deletion was unsucessful");
        }
Exemplo n.º 4
0
        private async Task RunUpdate()
        {
            var fields = base.ProcessFields(this._fieldsOption.Value(), CollaborationSubCommandBase._fields);

            if (!string.IsNullOrEmpty(this._bulkPath.Value()))
            {
                var json = false;
                if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
                {
                    json = true;
                }
                await base.ProcessAddCollaborationsFromFile(_bulkPath.Value(), base._t, commandName, fields : fields,
                                                            save : this._save.HasValue(), overrideSavePath : this._path.Value(),
                                                            overrideSaveFileFormat : this._fileFormat.Value(), json : json);

                return;
            }
            base.CheckForValue(this._id.Value, this._app, "A collaboration ID is required for this command.");
            var    boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value());
            string role;

            if (this._role.HasValue())
            {
                role = this._role.Value();
            }
            else
            {
                role = base.ProcessRoleOptions(editor: this._editor, viewer: this._viewer,
                                               uploader: this._uploader, previewerUploader: this._previewerUploader,
                                               viewerUploader: this._viewerUploader, coOwner: this._coowner, owner: this._owner,
                                               previewer: this._previewer);
            }

            var collabRequest = new BoxCollaborationRequest();

            collabRequest.Id = this._id.Value;
            if (this._canViewPath.HasValue())
            {
                collabRequest.CanViewPath = true;
            }
            if (this._status.HasValue())
            {
                collabRequest.Status = _status.Value();
            }
            collabRequest.Role = role;

            var result = await boxClient.CollaborationsManager.EditCollaborationAsync(collabRequest, fields : fields);

            if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
            {
                base.OutputJson(result);
                return;
            }
            base.PrintCollaboration(result);
        }
Exemplo n.º 5
0
        public async Task CollaborationsOnFileWorkflow_LiveSession_ValidResponse()
        {
            const string fileId = "100699285359";

            // Add Collaboration
            BoxCollaborationRequest addRequest = new BoxCollaborationRequest()
            {
                Item = new BoxRequestEntity()
                {
                    Id   = fileId,
                    Type = BoxType.file
                },
                AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Login = "******"
                },
                Role = "viewer"
            };

            BoxCollaboration collab = await _client.CollaborationsManager.AddCollaborationAsync(addRequest, notify : false);

            Assert.AreEqual(fileId, collab.Item.Id, "File and collaboration file id do not match");
            Assert.AreEqual(BoxCollaborationRoles.Viewer, collab.Role, "Incorrect collaboration role");


            // TODO: Edit Collaboration
            BoxCollaborationRequest editRequest = new BoxCollaborationRequest()
            {
                Id   = collab.Id,
                Role = BoxCollaborationRoles.Editor
            };

            BoxCollaboration editCollab = await _client.CollaborationsManager.EditCollaborationAsync(editRequest);

            Assert.AreEqual(collab.Id, editCollab.Id, "Id of original collaboration and updated collaboration do not match");
            Assert.AreEqual(BoxCollaborationRoles.Editor, editCollab.Role, "Incorrect updated role");

            // get existing collaboration
            var existingCollab = await _client.CollaborationsManager.GetCollaborationAsync(collab.Id);

            Assert.IsTrue(existingCollab.Item.Id == fileId, "failed to retrieve existing collab");

            // test getting list of collaborations on file
            var collabs = await _client.FilesManager.GetCollaborationsAsync(fileId);

            Assert.AreEqual(4, collabs.Entries.Count, "Failed to get correct number of file collabs.");

            // Test Remove Collaboration
            bool success = await _client.CollaborationsManager.RemoveCollaborationAsync(collab.Id);

            Assert.IsTrue(success, "Collaboration deletion was unsucessful");
        }
        /// <summary>
        /// Used to edit an existing collaboration. Descriptions of the various roles can be found
        /// <see cref="https://support.box.com/entries/20366031-what-are-the-different-collaboration-permissions-and-what-access-do-they-provide"/>
        /// </summary>
        /// <param name="collaborationRequest"></param>
        /// <returns></returns>
        public async Task <BoxCollaboration> EditCollaborationAsync(BoxCollaborationRequest collaborationRequest, List <string> fields = null)
        {
            collaborationRequest.ThrowIfNull("collaborationRequest")
            .Id.ThrowIfNullOrWhiteSpace("collaborationRequest.Id");

            BoxRequest request = new BoxRequest(_config.CollaborationsEndpointUri, collaborationRequest.Id)
                                 .Method(RequestMethod.Put)
                                 .Param(ParamFields, fields)
                                 .Payload(_converter.Serialize(collaborationRequest));

            IBoxResponse <BoxCollaboration> response = await ToResponseAsync <BoxCollaboration>(request).ConfigureAwait(false);

            return(response.ResponseObject);
        }
        /// <summary>
        /// Used to add a collaboration for a single user to a folder. Descriptions of the various roles can be found
        /// <see cref="https://support.box.com/entries/20366031-what-are-the-different-collaboration-permissions-and-what-access-do-they-provide"/>
        /// Either an email address or a user ID can be used to create the collaboration.
        /// </summary>
        /// <param name="collaborationRequest"></param>
        /// <returns></returns>
        public async Task <BoxCollaboration> AddCollaborationAsync(BoxCollaborationRequest collaborationRequest, List <string> fields = null)
        {
            collaborationRequest.ThrowIfNull("collaborationRequest")
            .Item.ThrowIfNull("collaborationRequest.Item")
            .Id.ThrowIfNullOrWhiteSpace("collaborationRequest.Item.Id");
            collaborationRequest.AccessibleBy.ThrowIfNull("collaborationRequest.AccessibleBy");

            BoxRequest request = new BoxRequest(_config.CollaborationsEndpointUri)
                                 .Method(RequestMethod.Post)
                                 .Param(ParamFields, fields)
                                 .Payload(_converter.Serialize(collaborationRequest))
                                 .Authorize(_auth.Session.AccessToken);

            IBoxResponse <BoxCollaboration> response = await ToResponseAsync <BoxCollaboration>(request);

            return(response.ResponseObject);
        }
Exemplo n.º 8
0
 private static async Task CreateCollaboration(BoxEntity folder, string searchUserId, BoxClient auClient,
                                               TimeLimiter throttle)
 {
     var requestParams = new BoxCollaborationRequest()
     {
         Item = new BoxRequestEntity()
         {
             Type = BoxType.folder,
             Id   = folder.Id
         },
         Role         = Config.SearchUserRole,
         AccessibleBy = new BoxCollaborationUserRequest()
         {
             Id = searchUserId
         }
     };
     await throttle;
     await auClient.CollaborationsManager.AddCollaborationAsync(requestParams);
 }
        public async Task CollaborationsWorkflow_LiveSession_ValidResponse()
        {
            const string folderId = "1927307787";

            // Add Collaboration
            BoxCollaborationRequest addRequest = new BoxCollaborationRequest()
            {
                Item = new BoxRequestEntity()
                {
                    Id   = folderId,
                    Type = BoxType.folder
                },
                AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Login = "******"
                },
                Role = "viewer"
            };

            BoxCollaboration collab = await _client.CollaborationsManager.AddCollaborationAsync(addRequest, notify : false);

            Assert.AreEqual(folderId, collab.Item.Id, "Folder and collaboration folder id do not match");
            Assert.AreEqual(BoxCollaborationRoles.Viewer, collab.Role, "Incorrect collaboration role");

            // Edit Collaboration
            BoxCollaborationRequest editRequest = new BoxCollaborationRequest()
            {
                Id   = collab.Id,
                Role = BoxCollaborationRoles.Editor
            };

            BoxCollaboration editCollab = await _client.CollaborationsManager.EditCollaborationAsync(editRequest);

            Assert.AreEqual(collab.Id, editCollab.Id, "Id of original collaboration and updated collaboration do not match");
            Assert.AreEqual(BoxCollaborationRoles.Editor, editCollab.Role, "Incorrect updated role");

            // Test Remove Collaboration
            bool success = await _client.CollaborationsManager.RemoveCollaborationAsync(collab.Id);

            Assert.IsTrue(success, "Collaboration deletion was unsucessful");
        }
Exemplo n.º 10
0
        public async Task AddGroupCollaboration_File_Fields_ValidResponse()
        {
            const string fileId  = "238288183114";
            const string groupId = "176708848";
            const string userId  = "349294186";

            // Add Group Collaboration
            BoxCollaborationRequest addGroupRequest = new BoxCollaborationRequest()
            {
                Item = new BoxRequestEntity()
                {
                    Id   = fileId,
                    Type = BoxType.file
                },
                AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Type = BoxType.group,
                    Id   = groupId
                },
                Role = "viewer"
            };

            //Add User Collaboration
            BoxCollaborationRequest addUserRequest = new BoxCollaborationRequest()
            {
                Item = new BoxRequestEntity()
                {
                    Id   = fileId,
                    Type = BoxType.file
                },
                AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Type = BoxType.user,
                    Id   = userId
                },
                Role = "editor"
            };
            var groupFileCollaboration = await _client.CollaborationsManager.AddCollaborationAsync(addGroupRequest, notify : false);

            var userFileCollaboration = await _client.CollaborationsManager.AddCollaborationAsync(addUserRequest, notify : false);
        }
        /// <summary>
        /// Used to add a collaboration for a single user to a folder. Descriptions of the various roles can be found
        /// <see cref="https://support.box.com/entries/20366031-what-are-the-different-collaboration-permissions-and-what-access-do-they-provide"/>
        /// Either an email address or a user ID can be used to create the collaboration.
        /// </summary>
        /// <param name="collaborationRequest"></param>
        /// <param name="fields">Attribute(s) to include in the response</param>
        /// <param name="notify">Determines if the user, (or all the users in the group) should receive email notification of the collaboration.</param>
        /// <returns></returns>
        public async Task <BoxCollaboration> AddCollaborationAsync(BoxCollaborationRequest collaborationRequest, List <string> fields = null, bool?notify = null)
        {
            collaborationRequest.ThrowIfNull("collaborationRequest")
            .Item.ThrowIfNull("collaborationRequest.Item")
            .Id.ThrowIfNullOrWhiteSpace("collaborationRequest.Item.Id");
            collaborationRequest.AccessibleBy.ThrowIfNull("collaborationRequest.AccessibleBy");

            BoxRequest request = new BoxRequest(_config.CollaborationsEndpointUri)
                                 .Method(RequestMethod.Post)
                                 .Param(ParamFields, fields)
                                 .Payload(_converter.Serialize(collaborationRequest));

            if (notify.HasValue)
            {
                var value = notify.Value ? "true" : "false";
                request.Param("notify", value);
            }

            IBoxResponse <BoxCollaboration> response = await ToResponseAsync <BoxCollaboration>(request).ConfigureAwait(false);

            return(response.ResponseObject);
        }
Exemplo n.º 12
0
        public async Task CollaborationsWorkflow_LiveSession_ValidResponse()
        {
            // Test Add Collaboration
            BoxCollaborationRequest addRequest = new BoxCollaborationRequest()
            {
                Item = new BoxRequestEntity()
                {
                    Id   = folderId,
                    Type = BoxType.folder
                },
                AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Login = "******"
                },
                Role = "viewer"
            };

            BoxCollaboration collab = await _client.CollaborationsManager.AddCollaborationAsync(addRequest);

            Assert.AreEqual(folderId, collab.Item.Id);
            Assert.AreEqual(BoxCollaborationRoles.Viewer, collab.Role);

            // Test Edit Collaboration
            BoxCollaborationRequest editRequest = new BoxCollaborationRequest()
            {
                Id   = collab.Id,
                Role = BoxCollaborationRoles.Editor
            };

            BoxCollaboration editCollab = await _client.CollaborationsManager.EditCollaborationAsync(editRequest);

            Assert.AreEqual(collab.Id, editCollab.Id);
            Assert.AreEqual(BoxCollaborationRoles.Editor, editCollab.Role);

            // Test Remove Collaboration
            await _client.CollaborationsManager.RemoveCollaborationAsync(collab.Id);
        }
Exemplo n.º 13
0
        public async Task SetColl(string sFod, string shareMail)
        {
            try
            {
                /*
                 * var config = new BoxConfig(sBoxClientId, sBoxClientSecret, new Uri("http://localhost"));
                 * var session = new OAuthSession(token, "NOT_NEEDED", 3600, "bearer");
                 * var client = new BoxClient(config, session);
                 */



                BoxCollaborationRequest FileRequestParams = new BoxCollaborationRequest()
                {
                    Item = new BoxRequestEntity()
                    {
                        Type = BoxType.file,

                        Id = sFod
                    },
                    Role         = "editor",
                    AccessibleBy = new BoxCollaborationUserRequest()
                    {
                        Type  = BoxType.user,
                        Login = shareMail
                    }
                };
                BoxCollaborationRequest FolderRequestParams = new BoxCollaborationRequest()
                {
                    Item = new BoxRequestEntity()
                    {
                        Type = BoxType.folder,

                        Id = sFod
                    },
                    Role         = "editor",
                    AccessibleBy = new BoxCollaborationUserRequest()
                    {
                        Type  = BoxType.user,
                        Login = shareMail
                    }
                };
                if (shareMail != "" && shareMail != null)
                {
                    BoxCollaboration collab;
                    try
                    {
                        collab = await SetForm.client.CollaborationsManager.AddCollaborationAsync(FolderRequestParams);
                    }
                    catch
                    {
                        collab = await SetForm.client.CollaborationsManager.AddCollaborationAsync(FileRequestParams);
                    }
                }
                else
                {
                    return;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(sFod + "_" + shareMail + "_" + e.Message);
            }
        }
        public async Task GroupMembershipWorkflow_ValidRequest()
        {
            // Get current user
            var user = await _client.UsersManager.GetCurrentUserInformationAsync();

            // Get all the current memberships for this user
            var current_memberships = await _client.GroupsManager.GetAllGroupMembershipsForUserAsync(user.Id);

            // Create a new group
            string groupName = GetUniqueName();

            BoxGroupRequest groupReq = new BoxGroupRequest()
            {
                Name = groupName,
            };

            var newGroup = await _client.GroupsManager.CreateAsync(groupReq);

            // Create a membership
            BoxGroupMembershipRequest request = new BoxGroupMembershipRequest()
            {
                User = new BoxRequestEntity()
                {
                    Id = user.Id
                },
                Group = new BoxGroupRequest()
                {
                    Id = newGroup.Id
                }
            };

            var responseMembership = await _client.GroupsManager.AddMemberToGroupAsync(request);

            Assert.AreEqual("group_membership", responseMembership.Type, "The type is not group_membership");
            Assert.AreEqual("member", responseMembership.Role, "Membership role is not set correctly");
            Assert.AreEqual(user.Id, responseMembership.User.Id, "User id not set correctly for membership");
            Assert.AreEqual(newGroup.Id, responseMembership.Group.Id, "Group id not set correctly for membership");

            // Get the created group membership
            var membership = await _client.GroupsManager.GetGroupMembershipAsync(responseMembership.Id);

            Assert.AreEqual("group_membership", membership.Type, "The type is not group_membership");
            Assert.AreEqual("member", membership.Role, "Membership role is not set correctly");
            Assert.AreEqual(user.Id, membership.User.Id, "User id not set correctly for membership");
            Assert.AreEqual(newGroup.Id, membership.Group.Id, "Group id not set correctly for membership");

            // Update the group membership's role
            request = new BoxGroupMembershipRequest()
            {
                Role = "admin"
            };
            var updatedMembership = await _client.GroupsManager.UpdateGroupMembershipAsync(responseMembership.Id, request);

            Assert.AreEqual("admin", updatedMembership.Role, "Membership role was not updated correctly");

            // Get all memberships for the given groups
            var memberships = await _client.GroupsManager.GetAllGroupMembershipsForGroupAsync(newGroup.Id);

            Assert.AreEqual(1, memberships.Entries.Count, "Wrong count of memberships");
            Assert.AreEqual(1, memberships.TotalCount, "Wrong total count of memberships");
            Assert.AreEqual("group_membership", memberships.Entries[0].Type, "Wrong type");
            Assert.AreEqual(newGroup.Id, memberships.Entries[0].Group.Id, "Wrong Group id");
            Assert.AreEqual(user.Id, memberships.Entries[0].User.Id, "Wrong User id");

            // Add this group to a folder
            const string folderId = "1927307787";

            // Add Collaboration
            BoxCollaborationRequest addRequest = new BoxCollaborationRequest()
            {
                Item = new BoxRequestEntity()
                {
                    Id   = folderId,
                    Type = BoxType.folder
                },
                AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Type = BoxType.group,
                    Id   = newGroup.Id
                },
                Role = "viewer"
            };

            BoxCollaboration collab = await _client.CollaborationsManager.AddCollaborationAsync(addRequest, notify : false);

            Assert.AreEqual(folderId, collab.Item.Id, "Folder and collaboration folder id do not match");
            Assert.AreEqual(BoxCollaborationRoles.Viewer, collab.Role, "Incorrect collaboration role");

            // Get all collaborations for the give group
            var collabs = await _client.GroupsManager.GetCollaborationsForGroupAsync(newGroup.Id);

            Assert.AreEqual(1, collabs.Entries.Count, "Wrong count of collaborations");
            Assert.AreEqual(1, collabs.TotalCount, "Wrong total count of collaborations");

            collab = collabs.Entries[0];
            Assert.AreEqual <string>(newGroup.Id, collab.AccessibleBy.Id, "Wrong Group Id");
            Assert.AreEqual <string>("viewer", collab.Role, "Wrong Role Type");

            // Get memberships for the user
            memberships = await _client.GroupsManager.GetAllGroupMembershipsForUserAsync(user.Id);

            Assert.AreEqual(current_memberships.TotalCount + 1, memberships.TotalCount, "The total count of memberships for user did not increase");
            Assert.IsTrue(memberships.Entries.Exists(m => m.Id.Equals(membership.Id)), "Newly created group membership does not exist in this users list of memberships");

            // Delete the group membership
            bool success = await _client.GroupsManager.DeleteGroupMembershipAsync(membership.Id);

            memberships = await _client.GroupsManager.GetAllGroupMembershipsForGroupAsync(newGroup.Id);

            Assert.AreEqual(0, memberships.Entries.Count, "Count should be 0");
            Assert.AreEqual(0, memberships.TotalCount, "Total count should be 0");

            // Clean up - delete group
            var delResult = await _client.GroupsManager.DeleteAsync(newGroup.Id);
        }
Exemplo n.º 15
0
        private async Task RunCreate()
        {
            var fields = base.ProcessFields(this._fieldsOption.Value(), CollaborationSubCommandBase._fields);

            if (!string.IsNullOrEmpty(this._bulkPath.Value()))
            {
                var json = false;
                if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
                {
                    json = true;
                }
                await base.ProcessAddCollaborationsFromFile(_bulkPath.Value(), base._t, commandName, fields : fields,
                                                            save : this._save.HasValue(), overrideSavePath : this._path.Value(),
                                                            overrideSaveFileFormat : this._fileFormat.Value(), json : json);

                return;
            }
            base.CheckForValue(this._id.Value, this._app, "An ID is required for this command.");
            var     boxClient = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value());
            BoxType type;

            if (base._t == BoxType.enterprise)
            {
                type = base.ProcessType(this._type.Value);
            }
            else
            {
                type = base._t;
            }
            string role;

            if (this._role.HasValue())
            {
                role = this._role.Value();
            }
            else
            {
                role = base.ProcessRoleOptions(editor: this._editor, viewer: this._viewer,
                                               uploader: this._uploader, previewerUploader: this._previewerUploader,
                                               viewerUploader: this._viewerUploader, coOwner: this._coowner,
                                               previewer: this._previewer);
            }
            var collabRequest = new BoxCollaborationRequest();

            if (this._canViewPath.HasValue())
            {
                collabRequest.CanViewPath = true;
            }

            if (this._userId.HasValue())
            {
                collabRequest.AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Id   = this._userId.Value(),
                    Type = BoxType.user
                };
            }
            else if (this._groupId.HasValue())
            {
                collabRequest.AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Id   = this._groupId.Value(),
                    Type = BoxType.group
                };
            }
            else if (this._login.HasValue())
            {
                collabRequest.AccessibleBy = new BoxCollaborationUserRequest()
                {
                    Login = this._login.Value(),
                    Type  = BoxType.user
                };
            }
            collabRequest.Item      = new BoxRequestEntity();
            collabRequest.Item.Type = type;
            collabRequest.Item.Id   = this._id.Value;
            collabRequest.Role      = role;
            var result = await boxClient.CollaborationsManager.AddCollaborationAsync(collabRequest, fields : fields);

            if (this._idOnly.HasValue())
            {
                Reporter.WriteInformation(result.Id);
                return;
            }
            if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
            {
                base.OutputJson(result);
                return;
            }
            base.PrintCollaboration(result);
        }