Skip to content
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
5 changes: 3 additions & 2 deletions App/AL/Config/UserSetting/AllowedValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ public static class AllowedValues {
public static Dictionary<string, string[]> GetAllowed()
=> new Dictionary<string, string[]> {
["subscription_currency"] = new[] {
"Usd", "BitCoin", "Ethereum", "Erc20Token", "Waves", "WavesToken", "LiteCoin"
"Usd", "BitCoin", "Ethereum", "Waves", "LiteCoin"
},
["subscription_amount"] = null
["subscription_amount"] = null,
["survey_after_register_redirect"] = new[] {"f", "t"},
};
}
}
12 changes: 6 additions & 6 deletions App/AL/Controller/Funding/Invoice/InvoiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using App.AL.Validation.Entity;
using App.AL.Validation.Funding;
using App.DL.Enum;
using App.DL.Model.User;
using App.DL.Repository.Funding;
using App.DL.Repository.User;
using App.PL.Transformer.Funding;
using Micron.AL.Validation.Basic;
using Micron.AL.Validation.Db;
Expand All @@ -23,7 +23,7 @@ public sealed class InvoiceController : BaseController {

public InvoiceController() {
Post("/api/v1/invoice/new", _ => {
var me = User.Find(CurrentRequest.UserId);
var me = DL.Model.User.User.Find(CurrentRequest.UserId);

var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ShouldHaveParameters(new[] {"entity_guid", "entity_type", "amount", "currency_type"}),
Expand Down Expand Up @@ -56,7 +56,7 @@ public InvoiceController() {
});

Get("/api/v1/me/invoice/get", _ => {
var me = User.Find(CurrentRequest.UserId);
var me = UserRepository.Find(CurrentRequest.UserId);

var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ShouldHaveParameters(new[] {"invoice_guid"}),
Expand All @@ -73,7 +73,7 @@ public InvoiceController() {
});

Get("/api/v1/me/invoices/finished", _ => {
var me = User.Find(CurrentRequest.UserId);
var me = UserRepository.Find(CurrentRequest.UserId);

var invoices = DL.Model.Funding.Invoice.GetForUserByStatuses(me, new [] {
InvoiceStatus.Confirmed, InvoiceStatus.Failed, InvoiceStatus.Done
Expand All @@ -83,15 +83,15 @@ public InvoiceController() {
});

Get("/api/v1/me/invoices/active", _ => {
var me = User.Find(CurrentRequest.UserId);
var me = UserRepository.Find(CurrentRequest.UserId);

var invoices = DL.Model.Funding.Invoice.GetActiveForUser(me, 25);

return HttpResponse.Item("invoices", new InvoiceTransformer().Many(invoices));
});

Patch("/api/v1/me/invoice/status/update", _ => {
var me = User.Find(CurrentRequest.UserId);
var me = UserRepository.Find(CurrentRequest.UserId);

var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ShouldHaveParameters(new[] {"invoice_guid", "status"}),
Expand Down
62 changes: 62 additions & 0 deletions App/AL/Controller/Project/Post/ProjectCrudController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using App.AL.Validation.Permission;
using App.DL.Enum;
using App.DL.Model.Project.Post;
using App.DL.Repository.Project;
using App.DL.Repository.User;
using App.PL.Transformer.Project.Post;
using Micron.AL.Validation.Basic;
using Micron.AL.Validation.Db;
using Micron.DL.Middleware;
using Micron.DL.Middleware.Auth;
using Micron.DL.Module.Controller;
using Micron.DL.Module.Http;
using Micron.DL.Module.Validator;
using Nancy;

namespace App.AL.Controller.Project.Post {
public class ProjectCrudController : BaseController {
protected override IMiddleware[] Middleware() => new IMiddleware[] {
new JwtMiddleware(),
};

public ProjectCrudController() {
Post("/api/v1/project/post/new", _ => {
var me = UserRepository.Find(CurrentRequest.UserId);
var project = ProjectRepository.FindByGuid(GetRequestStr("project_guid"));
if (project == null) return HttpResponse.Error(HttpStatusCode.NotFound, "Project not found");

var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ShouldHaveParameters(new[] {"project_guid", "title", "content"}),
new ExistsInTable("project_guid", "projects", "guid"),
new HasPermission(me, project.id, EntityType.Project),
}, true);
if (errors.Count > 0) return HttpResponse.Errors(errors);

var post = ProjectPost.Create(
project, GetRequestStr("title"), GetRequestStr("content")
);

return HttpResponse.Item(
"post", new ProjectPostTransformer().Transform(post), HttpStatusCode.Created
);
});

Delete("/api/v1/project/post/delete", _ => {
var post = ProjectPost.FindBy("guid", GetRequestStr("post_guid"));
if (post == null) return HttpResponse.Error(HttpStatusCode.NotFound, "Post not found");

var me = UserRepository.Find(CurrentRequest.UserId);

var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ShouldHaveParameters(new[] {"post_guid"}),
new HasPermission(me, post.project_id, EntityType.Project),
}, true);
if (errors.Count > 0) return HttpResponse.Errors(errors);

post.Delete();

return HttpResponse.Item("post", new ProjectPostTransformer().Transform(post));
});
}
}
}
33 changes: 33 additions & 0 deletions App/AL/Controller/Project/Post/ProjectPostsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using App.DL.Model.Project.Post;
using App.DL.Repository.Project;
using App.PL.Transformer.Project.Post;
using Micron.AL.Validation.Db;
using Micron.DL.Middleware;
using Micron.DL.Module.Controller;
using Micron.DL.Module.Http;
using Micron.DL.Module.Validator;

namespace App.AL.Controller.Project.Post {
public class ProjectPostsController : BaseController {
protected override IMiddleware[] Middleware() => new IMiddleware[] {};

public ProjectPostsController() {
Get("/api/v1/all_projects/posts/latest/get", _ => {
return HttpResponse.Item(
"posts", new ProjectPostTransformer().Many(ProjectPost.Latest())
);
});

Get("/api/v1/project/posts/get", _ => {
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ExistsInTable("project_guid", "projects", "guid"),
});
if (errors.Count > 0) return HttpResponse.Errors(errors);

var project = ProjectRepository.FindByGuid(GetRequestStr("project_guid"));

return HttpResponse.Item("posts", new ProjectPostTransformer().Many(project.Posts()));
});
}
}
}
47 changes: 45 additions & 2 deletions App/AL/Controller/Repo/RepoController.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,69 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using App.DL.Enum;
using App.DL.Repository.Repo;
using App.PL.Transformer.Repo;
using Micron.AL.Validation.Db;
using Micron.DL.Middleware;
using Micron.DL.Module.Controller;
using Micron.DL.Module.Http;
using Micron.DL.Module.Validator;
using Newtonsoft.Json.Linq;
using Sentry;
using YamlDotNet.Serialization;

namespace App.AL.Controller.Repo {
public sealed class RepoController : BaseController {
protected override IMiddleware[] Middleware() => new IMiddleware[] { };

public RepoController() {
Get("/api/v1/repository/get", _ => {
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ExistsInTable("repo_guid", "repositories", "guid"),
});
if (errors.Count > 0) return HttpResponse.Errors(errors);

return HttpResponse.Item("repository", new RepoTransformer().Transform(
RepoRepository.FindByGuid((string) Request.Query["repo_guid"])
));
});

Get("/api/v1/repository/meta/get", _ => {
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ExistsInTable("repo_guid", "repositories", "guid"),
});
if (errors.Count > 0) return HttpResponse.Errors(errors);

var sponsorLinks = new JObject();

var repo = RepoRepository.FindByGuid((string) Request.Query["repo_guid"]);

if (repo.service_type == RepoServiceType.GitHub) {
try {
var splitUrl = repo.repo_url.Split("/");
var response = new HttpClient().GetAsync(
$"https://raw.githubusercontent.com/{splitUrl[3]}/{splitUrl[4]}/master/.github/FUNDING.yml"
).Result.Content.ReadAsStringAsync().Result;
var yamlObject = (Dictionary<object, object>) new DeserializerBuilder().Build()
.Deserialize(new StringReader(response));
sponsorLinks["github"] = yamlObject["github"]?.ToString();
sponsorLinks["patreon"] = yamlObject["patreon"]?.ToString();
sponsorLinks["open_collective"] = yamlObject["open_collective"]?.ToString();
}
catch (Exception e) {
SentrySdk.CaptureException(e);
}
}

return HttpResponse.Data(new JObject() {
["repository"] = new RepoTransformer().Transform(repo)
["meta"] = new JObject() {
["sponsor_links"] = sponsorLinks
}
});
});
}
}
}
28 changes: 28 additions & 0 deletions App/AL/Controller/User/Badge/BadgeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using App.DL.Repository.User;
using App.PL.Transformer.User.Badge;
using Micron.AL.Validation.Basic;
using Micron.AL.Validation.Db;
using Micron.DL.Middleware;
using Micron.DL.Module.Controller;
using Micron.DL.Module.Http;
using Micron.DL.Module.Validator;

namespace App.AL.Controller.User.Badge {
public class BadgeController : BaseController {
protected override IMiddleware[] Middleware() => new IMiddleware[] { };

public BadgeController() {
Get("/api/v1/user/badges/get", _ => {
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ShouldHaveParameters(new[] {"user_guid"}),
new ExistsInTable("user_guid", "users", "guid"),
}, true);
if (errors.Count > 0) return HttpResponse.Errors(errors);

var user = UserRepository.FindByGuid(GetRequestStr("user_guid"));

return HttpResponse.Item("badges", new UserBadgeTransformer().Many(user.Badges()));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Micron.DL.Module.Validator;
using Nancy;

namespace App.AL.Controller.Settings {
namespace App.AL.Controller.User.Settings {
public class MySettingsController : BaseController {
protected override IMiddleware[] Middleware() => new IMiddleware[] {
new JwtMiddleware(),
Expand Down
20 changes: 20 additions & 0 deletions App/AL/Middleware/Schedule/ScheduleAuth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Micron.DL.Middleware;
using Micron.DL.Module.Config;
using Micron.DL.Module.Http;
using Nancy;

namespace App.AL.Middleware.Schedule {
public class ScheduleAuth : IMiddleware {
public ProcessedRequest Process(ProcessedRequest request) {
var scheduleToken = AppConfig.GetConfiguration("auth:schedule:token");

if (
string.IsNullOrEmpty(scheduleToken) || scheduleToken != request.GetRequestStr("schedule_token")
) {
request.AddError(new HttpError(HttpStatusCode.Unauthorized, "Schedule token is invalid"));
}

return request;
}
}
}
76 changes: 76 additions & 0 deletions App/AL/Schedule/Project/Post/SyncReleases.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using App.AL.Middleware.Schedule;
using App.DL.Enum;
using App.DL.Model.Project.Post;
using App.DL.Model.Repo;
using Micron.DL.Middleware;
using Micron.DL.Module.Config;
using Micron.DL.Module.Controller;
using Micron.DL.Module.Http;
using Newtonsoft.Json.Linq;
using Octokit;
using Sentry;

namespace App.AL.Schedule.Project.Post {
public class SyncReleases : BaseController {
protected override IMiddleware[] Middleware() => new IMiddleware[] {
new ScheduleAuth(),
};

public SyncReleases() {
Post("/api/v1/schedule/project/sync_releases/start", _ => {
Task.Run(() => {
var githubClient = new GitHubClient(new ProductHeaderValue("GitCom"));
var githubToken = AppConfig.GetConfiguration("auth:external:github:token");
if (githubToken != null) githubClient.Credentials = new Credentials(githubToken);

int pageIndex = 1;
var repos = Repo.Paginate(pageIndex);

while (repos.Length > 0) {
foreach (var repo in repos) {
try {
if (repo.service_type != RepoServiceType.GitHub) continue;
var splitUrl = repo.repo_url.Split("/");
IEnumerable<Release> releases;
try {
releases = githubClient.Repository.Release.GetAll(
splitUrl[3], splitUrl[4]
).Result.OrderBy(x => x.Id);
}
catch (Exception e) {
continue; // ignored
}

foreach (var release in releases) {
if (release.Body.Length < 100) continue;

var existingPost = ProjectPost.FindBy("origin_id", release.Id.ToString());
if (existingPost != null) continue;

var post = ProjectPost.Create(
repo.Project(), $"Released {release.Name}", release.Body
);
post.UpdateCol("origin_id", release.Id.ToString());
post.UpdateCol(
"created_at", release.PublishedAt.Value.ToUnixTimeSeconds().ToString()
);
}
}
catch (Exception e) {
SentrySdk.CaptureException(e);
}
}

++pageIndex;
repos = Repo.Paginate(pageIndex);
}
});
return HttpResponse.Data(new JObject());
});
}
}
}
4 changes: 3 additions & 1 deletion App/AL/Tasks/Project/ProjectSetUp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using App.DL.Repository.BoardColumn;
using App.DL.Repository.Card;
using App.DL.Repository.ProjectTeamMember;
using App.DL.Repository.UserLibrary;

namespace App.AL.Tasks.Project {
public static class ProjectSetUp {
Expand All @@ -22,8 +23,9 @@ public static void Run(DL.Model.Project.Project project, User creator) {
BoardColumnRepository.CreateAndGet("In progress", board, 2);
BoardColumnRepository.CreateAndGet("Done", board, 3);
CardRepository.CreateAndGet(
"Some task", DefaultCardDescription, 1, todoColumn, creator
"Example card", DefaultCardDescription, 1, todoColumn, creator
);
UserLibraryItemRepository.FindOrCreate(project.Creator(), project);
}
}
}
Loading