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

added security attribute to TenantController Get methods and resolved TenantId on server during Installation #155

Merged
merged 2 commits into from
Oct 23, 2019
Merged
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
4 changes: 1 addition & 3 deletions Oqtane.Client/Shared/Installer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@inject NavigationManager NavigationManager
@inject IInstallationService InstallationService
@inject ISiteService SiteService
@inject ITenantService TenantService
@inject IUserService UserService

<div class="container">
Expand Down Expand Up @@ -172,9 +171,8 @@
GenericResponse response = await InstallationService.Install(connectionstring);
if (response.Success)
{
List<Tenant> tenants = await TenantService.GetTenantsAsync();
Site site = new Site();
site.TenantId = tenants.FirstOrDefault().TenantId;
site.TenantId = -1; // will be populated on server
site.Name = "Default Site";
site.Logo = "oqtane.png";
site.DefaultThemeType = Constants.DefaultTheme;
Expand Down
5 changes: 4 additions & 1 deletion Oqtane.Server/Controllers/SiteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public Site Post([FromBody] Site Site)
bool authorized;
if (!Sites.GetSites().Any())
{
authorized = true; // provision initial site during installation
// provision initial site during installation
authorized = true;
Tenant tenant = Tenants.GetTenant();
Site.TenantId = tenant.TenantId;
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions Oqtane.Server/Controllers/TenantController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public TenantController(ITenantRepository Tenants, ILogManager logger)

// GET: api/<controller>
[HttpGet]
[Authorize(Roles = Constants.HostRole)]
public IEnumerable<Tenant> Get()
{
return Tenants.GetTenants();
}

// GET api/<controller>/5
[HttpGet("{id}")]
[Authorize(Roles = Constants.HostRole)]
public Tenant Get(int id)
{
return Tenants.GetTenant(id);
Expand Down
20 changes: 11 additions & 9 deletions Oqtane.Server/Infrastructure/LogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,29 @@ private Log ProcessStructuredLog(Log Log)
names.Add(message.Substring(index + 1, message.IndexOf("}", index) - index - 1));
if (values.Length > (names.Count - 1))
{
message = message.Replace("{" + names[names.Count - 1] + "}", values[names.Count - 1]?.ToString() ?? "null");
if (values[names.Count - 1] == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you prefer an "IF" instead of "??" operator, readability or technical reason?

{
message = message.Replace("{" + names[names.Count - 1] + "}", "null");
}
else
{
message = message.Replace("{" + names[names.Count - 1] + "}", values[names.Count - 1].ToString());
}
}
}
index = message.IndexOf("{", index + 1);
}
// rebuild properties into dictionary
Dictionary<string, string> propertydictionary = new Dictionary<string, string>();
Dictionary<string, object> propertydictionary = new Dictionary<string, object>();
for (int i = 0; i < values.Length; i++)
{
string value = "";
if (values[i] != null)
{
value = values[i].ToString();
}
if (i < names.Count)
{
propertydictionary.Add(names[i], value);
propertydictionary.Add(names[i], values[i]);
}
else
{
propertydictionary.Add("Property" + i.ToString(), value);
propertydictionary.Add("Property" + i.ToString(), values[i]);
}
}
properties = JsonSerializer.Serialize(propertydictionary);
Expand Down