Skip to content

Commit 5f156d1

Browse files
authored
Merge pull request #55 from gitcomteam/dev
v0.18.0
2 parents 15f4395 + 04ac80c commit 5f156d1

27 files changed

+522
-19
lines changed

App/AL/Config/UserSetting/AllowedValues.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ public static class AllowedValues {
66
public static Dictionary<string, string[]> GetAllowed()
77
=> new Dictionary<string, string[]> {
88
["subscription_currency"] = new[] {
9-
"Usd", "BitCoin", "Ethereum", "Erc20Token", "Waves", "WavesToken", "LiteCoin"
9+
"Usd", "BitCoin", "Ethereum", "Waves", "LiteCoin"
1010
},
11-
["subscription_amount"] = null
11+
["subscription_amount"] = null,
12+
["survey_after_register_redirect"] = new[] {"f", "t"},
1213
};
1314
}
1415
}

App/AL/Controller/Funding/Invoice/InvoiceController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using App.AL.Validation.Entity;
55
using App.AL.Validation.Funding;
66
using App.DL.Enum;
7-
using App.DL.Model.User;
87
using App.DL.Repository.Funding;
8+
using App.DL.Repository.User;
99
using App.PL.Transformer.Funding;
1010
using Micron.AL.Validation.Basic;
1111
using Micron.AL.Validation.Db;
@@ -23,7 +23,7 @@ public sealed class InvoiceController : BaseController {
2323

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

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

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

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

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

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

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

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

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

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

9696
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
9797
new ShouldHaveParameters(new[] {"invoice_guid", "status"}),
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using App.AL.Validation.Permission;
2+
using App.DL.Enum;
3+
using App.DL.Model.Project.Post;
4+
using App.DL.Repository.Project;
5+
using App.DL.Repository.User;
6+
using App.PL.Transformer.Project.Post;
7+
using Micron.AL.Validation.Basic;
8+
using Micron.AL.Validation.Db;
9+
using Micron.DL.Middleware;
10+
using Micron.DL.Middleware.Auth;
11+
using Micron.DL.Module.Controller;
12+
using Micron.DL.Module.Http;
13+
using Micron.DL.Module.Validator;
14+
using Nancy;
15+
16+
namespace App.AL.Controller.Project.Post {
17+
public class ProjectCrudController : BaseController {
18+
protected override IMiddleware[] Middleware() => new IMiddleware[] {
19+
new JwtMiddleware(),
20+
};
21+
22+
public ProjectCrudController() {
23+
Post("/api/v1/project/post/new", _ => {
24+
var me = UserRepository.Find(CurrentRequest.UserId);
25+
var project = ProjectRepository.FindByGuid(GetRequestStr("project_guid"));
26+
if (project == null) return HttpResponse.Error(HttpStatusCode.NotFound, "Project not found");
27+
28+
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
29+
new ShouldHaveParameters(new[] {"project_guid", "title", "content"}),
30+
new ExistsInTable("project_guid", "projects", "guid"),
31+
new HasPermission(me, project.id, EntityType.Project),
32+
}, true);
33+
if (errors.Count > 0) return HttpResponse.Errors(errors);
34+
35+
var post = ProjectPost.Create(
36+
project, GetRequestStr("title"), GetRequestStr("content")
37+
);
38+
39+
return HttpResponse.Item(
40+
"post", new ProjectPostTransformer().Transform(post), HttpStatusCode.Created
41+
);
42+
});
43+
44+
Delete("/api/v1/project/post/delete", _ => {
45+
var post = ProjectPost.FindBy("guid", GetRequestStr("post_guid"));
46+
if (post == null) return HttpResponse.Error(HttpStatusCode.NotFound, "Post not found");
47+
48+
var me = UserRepository.Find(CurrentRequest.UserId);
49+
50+
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
51+
new ShouldHaveParameters(new[] {"post_guid"}),
52+
new HasPermission(me, post.project_id, EntityType.Project),
53+
}, true);
54+
if (errors.Count > 0) return HttpResponse.Errors(errors);
55+
56+
post.Delete();
57+
58+
return HttpResponse.Item("post", new ProjectPostTransformer().Transform(post));
59+
});
60+
}
61+
}
62+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using App.DL.Model.Project.Post;
2+
using App.DL.Repository.Project;
3+
using App.PL.Transformer.Project.Post;
4+
using Micron.AL.Validation.Db;
5+
using Micron.DL.Middleware;
6+
using Micron.DL.Module.Controller;
7+
using Micron.DL.Module.Http;
8+
using Micron.DL.Module.Validator;
9+
10+
namespace App.AL.Controller.Project.Post {
11+
public class ProjectPostsController : BaseController {
12+
protected override IMiddleware[] Middleware() => new IMiddleware[] {};
13+
14+
public ProjectPostsController() {
15+
Get("/api/v1/all_projects/posts/latest/get", _ => {
16+
return HttpResponse.Item(
17+
"posts", new ProjectPostTransformer().Many(ProjectPost.Latest())
18+
);
19+
});
20+
21+
Get("/api/v1/project/posts/get", _ => {
22+
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
23+
new ExistsInTable("project_guid", "projects", "guid"),
24+
});
25+
if (errors.Count > 0) return HttpResponse.Errors(errors);
26+
27+
var project = ProjectRepository.FindByGuid(GetRequestStr("project_guid"));
28+
29+
return HttpResponse.Item("posts", new ProjectPostTransformer().Many(project.Posts()));
30+
});
31+
}
32+
}
33+
}
Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Net.Http;
5+
using App.DL.Enum;
16
using App.DL.Repository.Repo;
27
using App.PL.Transformer.Repo;
38
using Micron.AL.Validation.Db;
49
using Micron.DL.Middleware;
510
using Micron.DL.Module.Controller;
611
using Micron.DL.Module.Http;
712
using Micron.DL.Module.Validator;
13+
using Newtonsoft.Json.Linq;
14+
using Sentry;
15+
using YamlDotNet.Serialization;
816

917
namespace App.AL.Controller.Repo {
1018
public sealed class RepoController : BaseController {
1119
protected override IMiddleware[] Middleware() => new IMiddleware[] { };
12-
20+
1321
public RepoController() {
1422
Get("/api/v1/repository/get", _ => {
1523
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
1624
new ExistsInTable("repo_guid", "repositories", "guid"),
1725
});
1826
if (errors.Count > 0) return HttpResponse.Errors(errors);
19-
27+
2028
return HttpResponse.Item("repository", new RepoTransformer().Transform(
2129
RepoRepository.FindByGuid((string) Request.Query["repo_guid"])
2230
));
2331
});
32+
33+
Get("/api/v1/repository/meta/get", _ => {
34+
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
35+
new ExistsInTable("repo_guid", "repositories", "guid"),
36+
});
37+
if (errors.Count > 0) return HttpResponse.Errors(errors);
38+
39+
var sponsorLinks = new JObject();
40+
41+
var repo = RepoRepository.FindByGuid((string) Request.Query["repo_guid"]);
42+
43+
if (repo.service_type == RepoServiceType.GitHub) {
44+
try {
45+
var splitUrl = repo.repo_url.Split("/");
46+
var response = new HttpClient().GetAsync(
47+
$"https://raw.githubusercontent.com/{splitUrl[3]}/{splitUrl[4]}/master/.github/FUNDING.yml"
48+
).Result.Content.ReadAsStringAsync().Result;
49+
var yamlObject = (Dictionary<object, object>) new DeserializerBuilder().Build()
50+
.Deserialize(new StringReader(response));
51+
sponsorLinks["github"] = yamlObject["github"]?.ToString();
52+
sponsorLinks["patreon"] = yamlObject["patreon"]?.ToString();
53+
sponsorLinks["open_collective"] = yamlObject["open_collective"]?.ToString();
54+
}
55+
catch (Exception e) {
56+
SentrySdk.CaptureException(e);
57+
}
58+
}
59+
60+
return HttpResponse.Data(new JObject() {
61+
["repository"] = new RepoTransformer().Transform(repo)
62+
["meta"] = new JObject() {
63+
["sponsor_links"] = sponsorLinks
64+
}
65+
});
66+
});
2467
}
2568
}
2669
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using App.DL.Repository.User;
2+
using App.PL.Transformer.User.Badge;
3+
using Micron.AL.Validation.Basic;
4+
using Micron.AL.Validation.Db;
5+
using Micron.DL.Middleware;
6+
using Micron.DL.Module.Controller;
7+
using Micron.DL.Module.Http;
8+
using Micron.DL.Module.Validator;
9+
10+
namespace App.AL.Controller.User.Badge {
11+
public class BadgeController : BaseController {
12+
protected override IMiddleware[] Middleware() => new IMiddleware[] { };
13+
14+
public BadgeController() {
15+
Get("/api/v1/user/badges/get", _ => {
16+
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
17+
new ShouldHaveParameters(new[] {"user_guid"}),
18+
new ExistsInTable("user_guid", "users", "guid"),
19+
}, true);
20+
if (errors.Count > 0) return HttpResponse.Errors(errors);
21+
22+
var user = UserRepository.FindByGuid(GetRequestStr("user_guid"));
23+
24+
return HttpResponse.Item("badges", new UserBadgeTransformer().Many(user.Badges()));
25+
});
26+
}
27+
}
28+
}

App/AL/Controller/Settings/MySettingsController.cs renamed to App/AL/Controller/User/Settings/MySettingsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using Micron.DL.Module.Validator;
1313
using Nancy;
1414

15-
namespace App.AL.Controller.Settings {
15+
namespace App.AL.Controller.User.Settings {
1616
public class MySettingsController : BaseController {
1717
protected override IMiddleware[] Middleware() => new IMiddleware[] {
1818
new JwtMiddleware(),
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Micron.DL.Middleware;
2+
using Micron.DL.Module.Config;
3+
using Micron.DL.Module.Http;
4+
using Nancy;
5+
6+
namespace App.AL.Middleware.Schedule {
7+
public class ScheduleAuth : IMiddleware {
8+
public ProcessedRequest Process(ProcessedRequest request) {
9+
var scheduleToken = AppConfig.GetConfiguration("auth:schedule:token");
10+
11+
if (
12+
string.IsNullOrEmpty(scheduleToken) || scheduleToken != request.GetRequestStr("schedule_token")
13+
) {
14+
request.AddError(new HttpError(HttpStatusCode.Unauthorized, "Schedule token is invalid"));
15+
}
16+
17+
return request;
18+
}
19+
}
20+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using App.AL.Middleware.Schedule;
6+
using App.DL.Enum;
7+
using App.DL.Model.Project.Post;
8+
using App.DL.Model.Repo;
9+
using Micron.DL.Middleware;
10+
using Micron.DL.Module.Config;
11+
using Micron.DL.Module.Controller;
12+
using Micron.DL.Module.Http;
13+
using Newtonsoft.Json.Linq;
14+
using Octokit;
15+
using Sentry;
16+
17+
namespace App.AL.Schedule.Project.Post {
18+
public class SyncReleases : BaseController {
19+
protected override IMiddleware[] Middleware() => new IMiddleware[] {
20+
new ScheduleAuth(),
21+
};
22+
23+
public SyncReleases() {
24+
Post("/api/v1/schedule/project/sync_releases/start", _ => {
25+
Task.Run(() => {
26+
var githubClient = new GitHubClient(new ProductHeaderValue("GitCom"));
27+
var githubToken = AppConfig.GetConfiguration("auth:external:github:token");
28+
if (githubToken != null) githubClient.Credentials = new Credentials(githubToken);
29+
30+
int pageIndex = 1;
31+
var repos = Repo.Paginate(pageIndex);
32+
33+
while (repos.Length > 0) {
34+
foreach (var repo in repos) {
35+
try {
36+
if (repo.service_type != RepoServiceType.GitHub) continue;
37+
var splitUrl = repo.repo_url.Split("/");
38+
IEnumerable<Release> releases;
39+
try {
40+
releases = githubClient.Repository.Release.GetAll(
41+
splitUrl[3], splitUrl[4]
42+
).Result.OrderBy(x => x.Id);
43+
}
44+
catch (Exception e) {
45+
continue; // ignored
46+
}
47+
48+
foreach (var release in releases) {
49+
if (release.Body.Length < 100) continue;
50+
51+
var existingPost = ProjectPost.FindBy("origin_id", release.Id.ToString());
52+
if (existingPost != null) continue;
53+
54+
var post = ProjectPost.Create(
55+
repo.Project(), $"Released {release.Name}", release.Body
56+
);
57+
post.UpdateCol("origin_id", release.Id.ToString());
58+
post.UpdateCol(
59+
"created_at", release.PublishedAt.Value.ToUnixTimeSeconds().ToString()
60+
);
61+
}
62+
}
63+
catch (Exception e) {
64+
SentrySdk.CaptureException(e);
65+
}
66+
}
67+
68+
++pageIndex;
69+
repos = Repo.Paginate(pageIndex);
70+
}
71+
});
72+
return HttpResponse.Data(new JObject());
73+
});
74+
}
75+
}
76+
}

App/AL/Tasks/Project/ProjectSetUp.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using App.DL.Repository.BoardColumn;
66
using App.DL.Repository.Card;
77
using App.DL.Repository.ProjectTeamMember;
8+
using App.DL.Repository.UserLibrary;
89

910
namespace App.AL.Tasks.Project {
1011
public static class ProjectSetUp {
@@ -22,8 +23,9 @@ public static void Run(DL.Model.Project.Project project, User creator) {
2223
BoardColumnRepository.CreateAndGet("In progress", board, 2);
2324
BoardColumnRepository.CreateAndGet("Done", board, 3);
2425
CardRepository.CreateAndGet(
25-
"Some task", DefaultCardDescription, 1, todoColumn, creator
26+
"Example card", DefaultCardDescription, 1, todoColumn, creator
2627
);
28+
UserLibraryItemRepository.FindOrCreate(project.Creator(), project);
2729
}
2830
}
2931
}

0 commit comments

Comments
 (0)