re-organize Nextcloud project structure
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud
|
||||
{
|
||||
public class CloudClient : ClientBase
|
||||
{
|
||||
public CloudClient(NextcloudClient client) : base(client)
|
||||
{
|
||||
}
|
||||
|
||||
public UserInfo? GetUserInfo()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Client.CurrentLogin?.LoginName))
|
||||
return GetUserInfo(Client.CurrentLogin.LoginName);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserInfo? GetUserInfo(string username)
|
||||
{
|
||||
var result = Client.Ocs.Cloud.GetUserMeta(username);
|
||||
|
||||
if (result?.Data != null)
|
||||
return new UserInfo(result.Data);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model
|
||||
{
|
||||
public class UserBackendCapabilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines if the display name can be changed.
|
||||
/// </summary>
|
||||
public bool SetDisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines if the password can be changed.
|
||||
/// </summary>
|
||||
public bool SetPassword { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model
|
||||
{
|
||||
public class UserInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines if the user is enabled.
|
||||
/// </summary>
|
||||
public bool Enabled { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The location of the user's storage directory.
|
||||
/// </summary>
|
||||
public string? StorageLocation { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The uniquie user id that infos are for.
|
||||
/// </summary>
|
||||
public string? ID { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The last time when the user has logged in to its account.
|
||||
/// </summary>
|
||||
public DateTime LastLogin { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The backend of the user. Common values are "Database" or "LDAP".
|
||||
/// </summary>
|
||||
public string? Backend { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The Email address of the user.
|
||||
/// </summary>
|
||||
public string? Email { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The displayname of the user.
|
||||
/// </summary>
|
||||
public string? Displayname { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The displayname of the user.
|
||||
/// </summary>
|
||||
public string? Displayname2 { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The phone number of the user.
|
||||
/// </summary>
|
||||
public string? Phone { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The address of the user.
|
||||
/// </summary>
|
||||
public string? Address { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The Website of the user.
|
||||
/// </summary>
|
||||
public string? Website { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The twitter profile name of the user.
|
||||
/// </summary>
|
||||
public string? Twitter { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the groups the user is member of.
|
||||
/// </summary>
|
||||
public string[] Groups { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The configured language of the user.
|
||||
/// </summary>
|
||||
public string? Language { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The configured location of the user.
|
||||
/// </summary>
|
||||
public string? Locale { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Quota informations for the user.
|
||||
/// </summary>
|
||||
public UserQuota Quota { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Backend capabilities of the user.
|
||||
/// </summary>
|
||||
public UserBackendCapabilities BackendCapabilities { get; } = new();
|
||||
|
||||
public UserInfo(OcsResponseDataUser responseData)
|
||||
{
|
||||
Enabled = Convert.ToBoolean(responseData.Enabled);
|
||||
StorageLocation = responseData.StorageLocation;
|
||||
ID = responseData.ID;
|
||||
LastLogin = DateTimeOffset.FromUnixTimeMilliseconds(responseData.LastLogin ?? 0).LocalDateTime;
|
||||
Backend = responseData.Backend;
|
||||
Email = responseData.Email;
|
||||
Displayname = responseData.Displayname;
|
||||
Displayname2 = responseData.Displayname2;
|
||||
Phone = responseData.Phone;
|
||||
Address = responseData.Address;
|
||||
Website = responseData.Website;
|
||||
Twitter = responseData.Twitter;
|
||||
Groups = responseData.Groups ?? Array.Empty<string>();
|
||||
Language = responseData.Language;
|
||||
Locale = responseData.Locale;
|
||||
|
||||
if (responseData.Quota != null)
|
||||
{
|
||||
Quota.Free = responseData.Quota.Free ?? 0;
|
||||
Quota.Used = responseData.Quota.Used ?? 0;
|
||||
Quota.Total = responseData.Quota.Total ?? 0;
|
||||
Quota.Relative = responseData.Quota.Relative ?? 0.0F;
|
||||
Quota.Quota = responseData.Quota.Quota ?? 0;
|
||||
}
|
||||
|
||||
if (responseData.BackendCapabilities != null)
|
||||
{
|
||||
BackendCapabilities.SetDisplayName = Convert.ToBoolean(responseData.BackendCapabilities.SetDisplayName);
|
||||
BackendCapabilities.SetPassword = Convert.ToBoolean(responseData.BackendCapabilities.SetPassword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model
|
||||
{
|
||||
public class UserQuota
|
||||
{
|
||||
/// <summary>
|
||||
/// Amount of free bytes left.
|
||||
/// </summary>
|
||||
public long Free { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Amount of already used bytes.
|
||||
/// </summary>
|
||||
public long Used { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total amount of all bytes (free + used).
|
||||
/// </summary>
|
||||
public long Total { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Relative amount of used quota in percent.
|
||||
/// </summary>
|
||||
public float Relative { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total amount of bytes available.
|
||||
/// </summary>
|
||||
public long Quota { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.OCS.Responses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs
|
||||
{
|
||||
public class OcsResponseDataUser : OcsResponseData
|
||||
{
|
||||
public class ResponseQuota
|
||||
{
|
||||
[JsonProperty("free")]
|
||||
public long? Free { get; set; }
|
||||
|
||||
[JsonProperty("used")]
|
||||
public long? Used { get; set; }
|
||||
|
||||
[JsonProperty("total")]
|
||||
public long? Total { get; set; }
|
||||
|
||||
[JsonProperty("relative")]
|
||||
public float? Relative { get; set; }
|
||||
|
||||
[JsonProperty("quota")]
|
||||
public long? Quota { get; set; }
|
||||
}
|
||||
|
||||
public class ResponseBackendCapabilities
|
||||
{
|
||||
[JsonProperty("setDisplayName")]
|
||||
public bool? SetDisplayName { get; set; }
|
||||
|
||||
[JsonProperty("setPassword")]
|
||||
public bool? SetPassword { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("enabled")]
|
||||
public bool? Enabled { get; set; }
|
||||
|
||||
[JsonProperty("storageLocation")]
|
||||
public string? StorageLocation { get; set; }
|
||||
|
||||
[JsonProperty("id")]
|
||||
public string? ID { get; set; }
|
||||
|
||||
[JsonProperty("lastLogin")]
|
||||
public long? LastLogin { get; set; }
|
||||
|
||||
[JsonProperty("backend")]
|
||||
public string? Backend { get; set; }
|
||||
|
||||
[JsonProperty("quota")]
|
||||
public ResponseQuota? Quota { get; set; }
|
||||
|
||||
[JsonProperty("email")]
|
||||
public string? Email { get; set; }
|
||||
|
||||
[JsonProperty("displayname")]
|
||||
public string? Displayname { get; set; }
|
||||
|
||||
[JsonProperty("display-name")]
|
||||
public string? Displayname2 { get; set; }
|
||||
|
||||
[JsonProperty("phone")]
|
||||
public string? Phone { get; set; }
|
||||
|
||||
[JsonProperty("address")]
|
||||
public string? Address { get; set; }
|
||||
|
||||
[JsonProperty("website")]
|
||||
public string? Website { get; set; }
|
||||
|
||||
[JsonProperty("twitter")]
|
||||
public string? Twitter { get; set; }
|
||||
|
||||
[JsonProperty("groups")]
|
||||
public string[]? Groups { get; set; }
|
||||
|
||||
[JsonProperty("language")]
|
||||
public string? Language { get; set; }
|
||||
|
||||
[JsonProperty("locale")]
|
||||
public string? Locale { get; set; }
|
||||
|
||||
[JsonProperty("backendCapabilities")]
|
||||
public ResponseBackendCapabilities? BackendCapabilities { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.OCS.Responses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs
|
||||
{
|
||||
public class OcsResponseUser : OcsResponse<OcsResponseDataUser>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.OCS;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud
|
||||
{
|
||||
public class OcsApiCloud : OcsApiBase
|
||||
{
|
||||
public readonly static OcsApiUrlPath OCS_CLOUD_USER_METADATA = new("/ocs/v1.php/cloud/users/{0}");
|
||||
|
||||
public OcsApiCloud(OcsApi manager) : base(manager)
|
||||
{
|
||||
}
|
||||
|
||||
public OcsResponseUser? GetUserMeta(string username)
|
||||
{
|
||||
return Manager.MakeRequestOcs<OcsResponseUser>(HttpMethod.Get, OCS_CLOUD_USER_METADATA.FillParameters(username));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user