Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit713677c

Browse files
authored
Merge pull request#255 from Resgrid/develop
Develop
2 parents298b09b +e2aeecc commit713677c

File tree

15 files changed

+262
-53
lines changed

15 files changed

+262
-53
lines changed

‎Core/Resgrid.Model/MobileCarriers.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ public static class Carriers
302302
MobileCarriers.Vodacom,
303303
MobileCarriers.MTN,
304304
MobileCarriers.TelkomMobile,
305-
MobileCarriers.CellC
305+
MobileCarriers.CellC,
306+
MobileCarriers.TMobile
306307
};
307308

308309
publicstaticHashSet<MobileCarriers>OnPremSmsGatewayCarriers=newHashSet<MobileCarriers>()

‎Core/Resgrid.Services/MessageService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task<Message> GetMessageByIdAsync(int messageId)
5050
publicasyncTask<List<Message>>GetInboxMessagesByUserIdAsync(stringuserId)
5151
{
5252
varlist=await_messageRepository.GetInboxMessagesByUserIdAsync(userId);
53-
returnlist.ToList();
53+
returnlist.OrderByDescending(x=>x.SentOn).ToList();
5454
}
5555

5656
publicasyncTask<List<Message>>GetUnreadInboxMessagesByUserIdAsync(stringuserId)
@@ -65,7 +65,7 @@ public async Task<List<Message>> GetSentMessagesByUserIdAsync(string userId)
6565
varitems=await_messageRepository.GetSentMessagesByUserIdAsync(userId);
6666

6767
if(items!=null&&items.Any())
68-
returnitems.ToList();
68+
returnitems.OrderByDescending(x=>x.SentOn).ToList();
6969

7070
returnnewList<Message>();
7171
}

‎Providers/Resgrid.Providers.Claims/ClaimsLogic.cs‎

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,16 +1101,18 @@ public static void AddContactsClaims(ClaimsIdentity identity, bool isAdmin, List
11011101
}
11021102
elseif(permission.Action==(int)PermissionActions.DepartmentAdminsAndSelectRoles&&!isAdmin)
11031103
{
1104-
varroleIds=permission.Data.Split(char.Parse(",")).Select(int.Parse);
1105-
varrole=fromrinroles
1106-
whereroleIds.Contains(r.PersonnelRoleId)
1107-
selectr;
1108-
1109-
if(role.Any())
1104+
if(!String.IsNullOrWhiteSpace(permission.Data))
11101105
{
1111-
identity.AddClaim(newClaim(ResgridClaimTypes.Resources.Contacts,ResgridClaimTypes.Actions.View));
1112-
}
1106+
varroleIds=permission.Data.Split(char.Parse(",")).Select(int.Parse);
1107+
varrole=fromrinroles
1108+
whereroleIds.Contains(r.PersonnelRoleId)
1109+
selectr;
11131110

1111+
if(role.Any())
1112+
{
1113+
identity.AddClaim(newClaim(ResgridClaimTypes.Resources.Contacts,ResgridClaimTypes.Actions.View));
1114+
}
1115+
}
11141116
}
11151117
elseif(permission.Action==(int)PermissionActions.Everyone)
11161118
{
@@ -1143,17 +1145,19 @@ where roleIds.Contains(r.PersonnelRoleId)
11431145
}
11441146
elseif(permission.Action==(int)PermissionActions.DepartmentAdminsAndSelectRoles&&!isAdmin)
11451147
{
1146-
varroleIds=permission.Data.Split(char.Parse(",")).Select(int.Parse);
1147-
varrole=fromrinroles
1148-
whereroleIds.Contains(r.PersonnelRoleId)
1149-
selectr;
1150-
1151-
if(role.Any())
1148+
if(!String.IsNullOrWhiteSpace(permission.Data))
11521149
{
1153-
identity.AddClaim(newClaim(ResgridClaimTypes.Resources.Contacts,ResgridClaimTypes.Actions.Update));
1154-
identity.AddClaim(newClaim(ResgridClaimTypes.Resources.Contacts,ResgridClaimTypes.Actions.Create));
1155-
}
1150+
varroleIds=permission.Data.Split(char.Parse(",")).Select(int.Parse);
1151+
varrole=fromrinroles
1152+
whereroleIds.Contains(r.PersonnelRoleId)
1153+
selectr;
11561154

1155+
if(role.Any())
1156+
{
1157+
identity.AddClaim(newClaim(ResgridClaimTypes.Resources.Contacts,ResgridClaimTypes.Actions.Update));
1158+
identity.AddClaim(newClaim(ResgridClaimTypes.Resources.Contacts,ResgridClaimTypes.Actions.Create));
1159+
}
1160+
}
11571161
}
11581162
elseif(permission.Action==(int)PermissionActions.Everyone)
11591163
{
@@ -1186,16 +1190,18 @@ where roleIds.Contains(r.PersonnelRoleId)
11861190
}
11871191
elseif(permission.Action==(int)PermissionActions.DepartmentAdminsAndSelectRoles&&!isAdmin)
11881192
{
1189-
varroleIds=permission.Data.Split(char.Parse(",")).Select(int.Parse);
1190-
varrole=fromrinroles
1191-
whereroleIds.Contains(r.PersonnelRoleId)
1192-
selectr;
1193-
1194-
if(role.Any())
1193+
if(!String.IsNullOrWhiteSpace(permission.Data))
11951194
{
1196-
identity.AddClaim(newClaim(ResgridClaimTypes.Resources.Contacts,ResgridClaimTypes.Actions.Delete));
1197-
}
1195+
varroleIds=permission.Data.Split(char.Parse(",")).Select(int.Parse);
1196+
varrole=fromrinroles
1197+
whereroleIds.Contains(r.PersonnelRoleId)
1198+
selectr;
11981199

1200+
if(role.Any())
1201+
{
1202+
identity.AddClaim(newClaim(ResgridClaimTypes.Resources.Contacts,ResgridClaimTypes.Actions.Delete));
1203+
}
1204+
}
11991205
}
12001206
elseif(permission.Action==(int)PermissionActions.Everyone)
12011207
{
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
usingMicrosoft.AspNetCore.Http;
2+
usingMicrosoft.AspNetCore.Mvc;
3+
usingResgrid.Framework;
4+
usingResgrid.Model;
5+
usingResgrid.Model.Services;
6+
usingSystem;
7+
usingSystem.IO;
8+
usingSystem.Net.Mime;
9+
usingSystem.Threading.Tasks;
10+
11+
usingResgrid.Web.Services.Models;
12+
usingResgrid.Web.ServicesCore.Helpers;
13+
usingSixLabors.ImageSharp;
14+
usingSixLabors.ImageSharp.Processing;
15+
16+
17+
namespaceResgrid.Web.Services.Controllers.v4
18+
{
19+
/// <summary>
20+
/// Used to interact with the user avatars (profile pictures) in the Resgrid system. The authentication header isn't required to access this method.
21+
/// </summary>
22+
[Route("api/v{VersionId:apiVersion}/[controller]")]
23+
[ApiVersion("4.0")]
24+
[ApiExplorerSettings(GroupName="v4")]
25+
//[EnableCors("_resgridWebsiteAllowSpecificOrigins")]
26+
publicclassAvatarsController:ControllerBase
27+
{
28+
privatereadonlyIImageService_imageService;
29+
privatestaticbyte[]_defaultProfileImage;
30+
31+
publicAvatarsController(IImageServiceimageService)
32+
{
33+
_imageService=imageService;
34+
}
35+
36+
/// <summary>
37+
/// Get a users avatar from the Resgrid system based on their ID
38+
/// </summary>
39+
/// <param name="id">ID of the user</param>
40+
/// <returns></returns>
41+
[HttpGet("Get")]
42+
[Produces(MediaTypeNames.Image.Jpeg)]
43+
[ProducesResponseType(StatusCodes.Status200OK)]
44+
[ProducesResponseType(StatusCodes.Status404NotFound)]
45+
publicasyncTask<ActionResult>Get(stringid,int?type)
46+
{
47+
byte[]data=null;
48+
if(type==null)
49+
data=await_imageService.GetImageAsync(ImageTypes.Avatar,id);
50+
else
51+
data=await_imageService.GetImageAsync((ImageTypes)type.Value,id);
52+
53+
if(data==null||data.Length<=0)
54+
returnFile(GetDefaultProfileImage(),"image/png");
55+
56+
returnFile(data,"image/jpeg");
57+
}
58+
59+
[HttpPost("Upload")]
60+
[ProducesResponseType(StatusCodes.Status200OK)]
61+
[ProducesResponseType(StatusCodes.Status201Created)]
62+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
63+
publicasyncTask<ActionResult>Upload([FromQuery]stringid,int?type)
64+
{
65+
varimg=HttpContext.Request.Form.Files.Count>0?
66+
HttpContext.Request.Form.Files[0]:null;
67+
68+
// check for a valid mediatype
69+
if(!img.ContentType.StartsWith("image/"))
70+
returnBadRequest();
71+
72+
// load the image from the upload and generate a new filename
73+
//var image = Image.FromStream(img.OpenReadStream());
74+
varextension=Path.GetExtension(img.FileName);
75+
byte[]imgArray;
76+
intwidth=0;
77+
intheight=0;
78+
79+
using(Imageimage=Image.Load(img.OpenReadStream()))
80+
{
81+
//image.Mutate(x => x
82+
// .Resize(image.Width / 2, image.Height / 2)
83+
// .Grayscale());
84+
85+
width=image.Width;
86+
height=image.Height;
87+
88+
MemoryStreamms=newMemoryStream();
89+
awaitimage.SaveAsPngAsync(ms);
90+
imgArray=ms.ToArray();
91+
92+
//image.Save()"output/fb.png"); // Automatic encoder selected based on extension.
93+
}
94+
95+
//ImageConverter converter = new ImageConverter();
96+
//byte[] imgArray = (byte[])converter.ConvertTo(image, typeof(byte[]));
97+
98+
if(type==null)
99+
await_imageService.SaveImageAsync(ImageTypes.Avatar,id,imgArray);
100+
else
101+
await_imageService.SaveImageAsync((ImageTypes)type.Value,id,imgArray);
102+
103+
varbaseUrl=Config.SystemBehaviorConfig.ResgridApiBaseUrl;
104+
105+
stringurl;
106+
107+
if(type==null)
108+
url=baseUrl+"/api/v4/Avatars/Get?id="+id;
109+
else
110+
url=baseUrl+"/api/v4/Avatars/Get?id="+id+"&type="+type.Value;
111+
112+
varobj=new
113+
{
114+
status=CroppicStatuses.Success,
115+
url=url,
116+
width=width,
117+
height=height
118+
};
119+
120+
returnCreatedAtAction(nameof(Upload),new{id=obj.url},obj);
121+
}
122+
123+
[HttpPut("Crop")]
124+
[ProducesResponseType(StatusCodes.Status200OK)]
125+
[ProducesResponseType(StatusCodes.Status201Created)]
126+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
127+
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
128+
publicasyncTask<ActionResult>Crop([FromBody]CropRequestmodel)
129+
{
130+
// extract original image ID and generate a new filename for the cropped result
131+
varoriginalUri=newUri(model.imgUrl);
132+
varoriginalId=originalUri.Query.Replace("?id=","");
133+
134+
try
135+
{
136+
byte[]imgArray;
137+
138+
using(varms=newMemoryStream(await_imageService.GetImageAsync(ImageTypes.Avatar,originalId)))
139+
using(varimage=Image.Load(ms))
140+
{
141+
// load the original picture and resample it to the scaled values
142+
varbitmap=ImageUtils.Resize(image,(int)model.imgW,(int)model.imgH);
143+
144+
varcroppedBitmap=ImageUtils.Crop(bitmap,model.imgX1,model.imgY1,model.cropW,model.cropH);
145+
146+
using(varms2=newMemoryStream())
147+
{
148+
awaitcroppedBitmap.SaveAsPngAsync(ms2);
149+
imgArray=ms2.ToArray();
150+
}
151+
}
152+
153+
await_imageService.SaveImageAsync(ImageTypes.Avatar,originalId,imgArray);
154+
}
155+
catch(Exceptionex)
156+
{
157+
Logging.LogException(ex,$"Error cropping avatar image for ID:{originalId}");
158+
returnStatusCode(StatusCodes.Status500InternalServerError,"An error occurred while cropping the image");
159+
}
160+
161+
varobj=new
162+
{
163+
status=CroppicStatuses.Success,
164+
url=originalId
165+
};
166+
167+
returnCreatedAtAction(nameof(Crop),new{id=obj.url},obj);
168+
}
169+
170+
privatebyte[]GetDefaultProfileImage()
171+
{
172+
if(_defaultProfileImage==null)
173+
_defaultProfileImage=EmbeddedResources.GetApiRequestFile(typeof(AvatarsController),"Resgrid.Web.Services.Properties.Resources.defaultProfile.png");
174+
175+
return_defaultProfileImage;
176+
}
177+
}
178+
179+
internalstaticclassCroppicStatuses
180+
{
181+
publicconststringSuccess="success";
182+
publicconststringError="error";
183+
}
184+
}

‎Web/Resgrid.Web.Services/Controllers/v4/MessagesController.cs‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,19 @@ public async Task<ActionResult<SendMessageResult>> SendMessage([FromBody] NewMes
312312
// Add all the explict people
313313
foreach(varpersoninnewMessageInput.Recipients.Where(x=>x.Type==1))
314314
{
315-
if(usersToSendTo.All(x=>x!=person.Id)&&person.Id!=UserId)
315+
if(!String.IsNullOrWhiteSpace(person.Id))
316316
{
317-
// Ensure the user is in the same department
318-
if(departmentUsers.Any(x=>x.UserId==person.Id))
317+
// New RN Apps add a prefix to ID's from the Recipients list, guard against the prefix here.
318+
varuserIdToSendTo=person.Id.Replace("P:","").Trim();
319+
320+
if(usersToSendTo.All(x=>x!=userIdToSendTo)&&userIdToSendTo!=UserId)
319321
{
320-
usersToSendTo.Add(person.Id);
321-
message.AddRecipient(person.Id);
322+
// Ensure the user is in the same department
323+
if(departmentUsers.Any(x=>x.UserId==userIdToSendTo))
324+
{
325+
usersToSendTo.Add(userIdToSendTo);
326+
message.AddRecipient(userIdToSendTo);
327+
}
322328
}
323329
}
324330
}
@@ -328,8 +334,11 @@ public async Task<ActionResult<SendMessageResult>> SendMessage([FromBody] NewMes
328334
{
329335
if(!String.IsNullOrWhiteSpace(group.Id))
330336
{
337+
// New RN Apps add a prefix to ID's from the Recipients list, guard against the prefix here.
338+
vargroupIdToSendTo=group.Id.Replace("G:","").Trim();
339+
331340
intgroupId=0;
332-
if(int.TryParse(group.Id.Trim(),outgroupId))
341+
if(int.TryParse(groupIdToSendTo,outgroupId))
333342
{
334343
if(departmentGroups.Any(x=>x.DepartmentGroupId==groupId))
335344
{
@@ -356,8 +365,11 @@ public async Task<ActionResult<SendMessageResult>> SendMessage([FromBody] NewMes
356365
{
357366
if(!String.IsNullOrWhiteSpace(role.Id))
358367
{
368+
// New RN Apps add a prefix to ID's from the Recipients list, guard against the prefix here.
369+
varroleIdToSendTo=role.Id.Replace("R:","").Trim();
370+
359371
introleId=0;
360-
if(int.TryParse(role.Id.Trim(),outroleId))
372+
if(int.TryParse(roleIdToSendTo,outroleId))
361373
{
362374
if(departmentRoles.Any(x=>x.PersonnelRoleId==roleId))
363375
{

‎Web/Resgrid.Web.Services/Resgrid.Web.Services.xml‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Web/Resgrid.Web/Areas/User/Controllers/ConnectController.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task<IActionResult> Index()
4343
varmodel=newIndexView();
4444
model.Department=await_departmentsService.GetDepartmentByIdAsync(DepartmentId);
4545
model.Profile=_departmentProfileService.GetOrInitializeDepartmentProfile(DepartmentId);
46-
model.ImageUrl=$"{Config.SystemBehaviorConfig.ResgridApiBaseUrl}/api/v3/Avatars/Get?id={model.Profile.DepartmentId}&type=1";
46+
model.ImageUrl=$"{Config.SystemBehaviorConfig.ResgridApiBaseUrl}/api/v4/Avatars/Get?id={model.Profile.DepartmentId}&type=1";
4747

4848
varposts=_departmentProfileService.GetArticlesForDepartment(model.Profile.DepartmentProfileId);
4949
varvisiblePosts=_departmentProfileService.GetVisibleArticlesForDepartment(model.Profile.DepartmentProfileId);
@@ -67,7 +67,7 @@ public async Task<IActionResult> Profile()
6767

6868
model.ApiUrl=Config.SystemBehaviorConfig.ResgridApiBaseUrl;
6969
model.Department=await_departmentsService.GetDepartmentByUserIdAsync(UserId);
70-
model.ImageUrl=$"{model.ApiUrl}/api/v3/Avatars/Get?id={model.Department.DepartmentId}&type=1";
70+
model.ImageUrl=$"{model.ApiUrl}/api/v4/Avatars/Get?id={model.Department.DepartmentId}&type=1";
7171

7272

7373
varprofile=_departmentProfileService.GetOrInitializeDepartmentProfile(DepartmentId);
@@ -98,7 +98,7 @@ public async Task<IActionResult> Profile(ProfileView model)
9898
{
9999
model.ApiUrl=Config.SystemBehaviorConfig.ResgridApiBaseUrl;
100100
model.Department=await_departmentsService.GetDepartmentByUserIdAsync(UserId);
101-
model.ImageUrl=$"{model.ApiUrl}/api/v3/Avatars/Get?id={model.Department.DepartmentId}&type=1";
101+
model.ImageUrl=$"{model.ApiUrl}/api/v4/Avatars/Get?id={model.Department.DepartmentId}&type=1";
102102

103103
if(ModelState.IsValid)
104104
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp