public ActionResult <DatabaseGroupUser> Post(GroupUserModel groupUserModel) { // Vérification de l'appelant if (!this.SecurityCheckRoleAdminOrUser()) { return(Forbid()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // L'appelant doit être un administrateur de la base de données if (!_service.IsAdministrateur(GetJWTIdentity().Name, groupUserModel.DbId)) { return(Forbid()); } DatabaseGroupUser databaseGroupUser = _service.AddContributor(GetJWTIdentity().Name, groupUserModel); if (databaseGroupUser == null) { return(Conflict()); } // L'utilisateur a tous les droits databaseGroupUser.CanBeDeleted = databaseGroupUser.CanBeUpdated = true; //return CreatedAtRoute("DefaultApi", new { id = databaseGroupUser. }, databaseGroupUser); return(Ok(databaseGroupUser)); }
public IHttpActionResult GroupDelMember(GroupUserModel model) { ApiServerMsg result = new ApiServerMsg(); try { if (_dicSockets.ContainsKey(model.uuid)) { var res = _dicSockets[model.uuid].weChatThread.Wx_DeleteChatRoomMember(model.chatroomid, model.user); result.Success = true; result.Context = res; return(Ok(result)); } else { result.Success = false; result.Context = "不存在该websocket连接"; return(Ok(result)); } } catch (Exception e) { result.Success = false; result.ErrContext = e.Message; return(Ok(result)); } }
public IActionResult Put(String id, GroupUserModel groupUserModel) { if (!ModelState.IsValid || !id.Equals(groupUserModel.SqlLogin, StringComparison.InvariantCultureIgnoreCase)) { return(BadRequest(ModelState)); } // Vérification de l'appelant if (!this.SecurityCheckRoleAdminOrUser()) { return(Forbid()); } // L'appelant doit être un administrateur de la base de données if (!_service.IsAdministrateur(GetJWTIdentity().Name, groupUserModel.DbId)) { return(Forbid()); } if (_service.UpdateContributor(groupUserModel)) { return(StatusCode(StatusCodes.Status204NoContent)); } return(StatusCode(StatusCodes.Status404NotFound)); }
// GET: GroupUser public async Task <ActionResult> Index(string groupId) { string accessToken = Session["MicrosoftAccessToken"] as string; var roleTypeService = new RoleTypeService(accessToken); var userDataService = new UserService(accessToken); var userGroupService = new UserGroupService(accessToken); var allRoleTypes = await roleTypeService.GetAllRoleTypes(); var usersFromGroup = await userDataService.GetUsersFromGroup(groupId); List <GroupUserModel> guModelsList = new List <GroupUserModel>(); foreach (var user in usersFromGroup) { var userGroup = await userGroupService.GetUserGroup(user.Id, groupId); GroupUserModel guModel = new GroupUserModel(); guModel.UserGroupId = userGroup.Id; guModel.UserEmail = user.Email; guModel.RoleTypeId = userGroup.RoleTypeId; guModel.RoleName = allRoleTypes.Single(r => r.Id == userGroup.RoleTypeId).RoleName; guModelsList.Add(guModel); } ViewBag.GroupId = groupId; return(View(guModelsList)); }
public IActionResult Delete(String id, GroupUserModel groupUserModel) { string userLogin = GetJWTIdentity().Name; // Vérification de l'appelant if (!this.SecurityCheckRoleAdminOrUser()) { return(Forbid()); } DatabaseGroupUser databaseGroupUser = _service.GetDatabaseGroupUserWithSqlLogin(id, groupUserModel.DbId); if (databaseGroupUser == null) { return(NotFound()); } // L'utilisateur doit être un administrateur de la base de données if (!_service.IsAdministrateur(userLogin, groupUserModel.DbId)) { return(Forbid()); } databaseGroupUser = _service.RemoveContributor(id, groupUserModel.DbId); return(Ok(databaseGroupUser)); }
public IHttpActionResult Put(String id, GroupUserModel groupUserModel) { if (!ModelState.IsValid || !id.Equals(groupUserModel.SqlLogin, StringComparison.InvariantCultureIgnoreCase)) { return(BadRequest(ModelState)); } // Vérification de l'appelant IHttpActionResult result = this.SecurityCheckRoleAdminOrOwner(this.GetJWTIdentity().Name); if (result != null) { return(result); } // L'appelant doit être un administrateur de la base de données if (!service.IsAdministrateur(this.GetJWTIdentity().Name, groupUserModel.DbId)) { return(ResponseMessage(new System.Net.Http.HttpResponseMessage(HttpStatusCode.Forbidden) { ReasonPhrase = "Vous n'êtes pas administrateur de la base de données" })); } if (service.UpdateContributor(groupUserModel)) { return(StatusCode(HttpStatusCode.NoContent)); } return(StatusCode(HttpStatusCode.NotFound)); }
// GET: GroupUser/Delete/5 public async Task <ActionResult> Delete(string userGroupId) { string accessToken = Session["MicrosoftAccessToken"] as string; var roleTypeService = new RoleTypeService(accessToken); var userService = new UserService(accessToken); var userGroupService = new UserGroupService(accessToken); var allRoleTypes = await roleTypeService.GetAllRoleTypes(); var userGroup = await userGroupService.GetUserGroupById(userGroupId); var user = await userService.GetUserById(userGroup.UserId); GroupUserModel guModel = new GroupUserModel(); guModel.UserEmail = user.Email; guModel.RoleTypeId = userGroup.RoleTypeId; guModel.RoleName = allRoleTypes.Single(r => r.Id == userGroup.RoleTypeId).RoleName; guModel.UserGroupId = userGroup.Id; ViewBag.GroupId = userGroup.GroupId; GroupService groupService = new GroupService(accessToken); string groupName = await groupService.GroupNameByGroupId(userGroup.GroupId); if (await AccessAdmin(userGroup.GroupId) && !userGroup.IsUserDefaultGroup) { return(View(guModel)); } else { return(View("AccessDenied")); } }
public IHttpActionResult Delete(String id, GroupUserModel groupUserModel) { string userLogin = this.GetJWTIdentity().Name; // Vérification de l'appelant IHttpActionResult result = this.SecurityCheckRoleAdminOrOwner(userLogin); if (result != null) { return(result); } DatabaseGroupUser databaseGroupUser = service.GetDatabaseGroupUserWithSqlLogin(id, groupUserModel.DbId); if (databaseGroupUser == null) { return(NotFound()); } // L'utilisateur doit être un administrateur de la base de données if (!service.IsAdministrateur(userLogin, groupUserModel.DbId)) { return(ResponseMessage(new System.Net.Http.HttpResponseMessage(HttpStatusCode.Forbidden) { ReasonPhrase = "Vous n'êtes pas administrateur de la base de données" })); } databaseGroupUser = service.RemoveContributor(id, groupUserModel.DbId); return(Ok(databaseGroupUser)); }
public bool UpdateContributor(GroupUserModel groupUserModel) { DatabaseGroupUser databaseGroupUser = GetDatabaseGroupUserWithSqlLogin(groupUserModel.SqlLogin, groupUserModel.DbId); if (databaseGroupUser == null) { return(false); } // Modification du mot de passe sur le serveur string serverName = null; try { // Obtention de la base de données DatabaseDB databaseDB = GetDatabase(groupUserModel.DbId); if (databaseDB == null) { return(false); } // Obtention du serveur DatabaseServerName databaseServerName = this.db.DatabaseServerNames.Find(databaseDB.ServerId); if (databaseServerName == null) { return(false); } serverName = databaseServerName.Name; // Obtention du serveur réel : MySQL, SQL Server, ... avec son adresse IP DatabaseManagement management = DatabaseManagement.CreateDatabaseManagement(databaseServerName.Code, databaseServerName.IPLocale, databaseServerName.PortLocal); if (management == null) { return(false); } management.UpdateContributor(databaseDB.NomBD, groupUserModel.SqlLogin, groupUserModel.GroupType, groupUserModel.Password); } catch (Exception ex) { LogManager.GetLogger().Error(ex); throw new DatabaseException(string.Format("Erreur dans l'ajout du contributeur {0} sur le serveur '{1}'", groupUserModel.ToString(), serverName), ex); } try { // Maj du type databaseGroupUser.GroupType = groupUserModel.GroupType; // Modification du contributeur dans le groupe db.Entry(databaseGroupUser).State = EntityState.Modified; this.db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { LogManager.GetLogger().Error(ex); throw new DatabaseException(string.Format("Erreur dans la modification du contributeur {0} dans le référentiel", groupUserModel.ToString()), ex); } return(true); }
public int Add(GroupUserModel model) { try { var groupUser = new GroupUser() { GroupId = model.GroupId, UserId = model.UserId, RoleId = model.RoleId, LastSeenOn = UnixTimeBaseClass.UnixTimeNow, CreatedBy = model.CreatedBy, CreatedOn = UnixTimeBaseClass.UnixTimeNow }; _db.GroupUsers.Add(groupUser); _db.SaveChanges(); return(groupUser.GroupUserId); } catch (Exception ex) { JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(model); Log.Error("Group User - Add- " + json, ex); throw; } }
public int Add(GroupUserModel model) { if (_groupUser.IsUserExisted(model.UserId, model.GroupId)) { throw new ReturnExceptionModel(new CustomExceptionModel() { StatusCode = HttpStatusCode.BadRequest, Message = "User already added in the group" }); } return(_groupUser.Add(model)); }
public void TestUpdateContributor() { GroupUserModel groupUserModel = new GroupUserModel { DbId = 11, SqlLogin = "******", Password = "******", GroupType = DatabaseValues.ECRITURE }; Assert.IsTrue(service.UpdateContributor(groupUserModel)); }
private void AddUserGroup(IEnumerable <UserModel> users, IEnumerable <GroupModel> groups) { var user = users.FirstOrDefault(); foreach (var group in groups) { var userGroup = new GroupUserModel { UserId = user.Id, GroupId = group.Id }; _context.Add(userGroup); var result = _context.SaveChanges(); //Console.WriteLine($"result: {result}"); } }
public void TestAddContributor() { GroupUserModel groupUserModel = new GroupUserModel { DbId = 11, SqlLogin = "******", Password = "******", GroupType = 2 }; DatabaseGroupUser databaseGroupUser = service.AddContributor("test.v8", groupUserModel); Assert.IsNotNull(databaseGroupUser); Assert.IsNotNull(databaseGroupUser.SqlLogin); Assert.IsTrue(databaseGroupUser.AddedByUserLogin.Equals("test.v8")); Assert.IsNull(databaseGroupUser.UserLogin); Assert.IsTrue(databaseGroupUser.GroupType == groupUserModel.GroupType); }
public async Task <ActionResult> Delete(string userGroupId, GroupUserModel groupUserModel) { try { string accessToken = Session["MicrosoftAccessToken"] as string; var userGroupService = new UserGroupService(accessToken); var userGroup = await userGroupService.GetUserGroupById(userGroupId); await userGroupService.DeleteUserGroup(userGroup.Id); return(RedirectToAction("Index", new { groupId = userGroup.GroupId })); } catch { return(View()); } }
public async Task <ActionResult> Create(string groupId, GroupUserModel groupUserModel) { try { string accessToken = Session["MicrosoftAccessToken"] as string; var userService = new UserService(accessToken); var user = await userService.GetUsersByEmail(groupUserModel.UserEmail); if (user == null) { ModelState.AddModelError("Error", "User with this email does not exist!"); ViewBag.Error = TempData["Error"]; var roleTypeService = new RoleTypeService(accessToken); var allRoleTypes = await roleTypeService.GetAllRoleTypes(); var defaultRole = allRoleTypes.Single(r => r.RoleKey == (int)RoleTypeEnum.Viewer); ViewBag.RoleTypeId = new SelectList(allRoleTypes, "Id", "RoleName", defaultRole.Id); ViewBag.GroupId = groupId; return(View(groupUserModel)); } else { UserGroup userGroup = new UserGroup { Id = Guid.NewGuid().ToString(), GroupId = groupId, RoleTypeId = groupUserModel.RoleTypeId, UserId = user.Id, IsUserDefaultGroup = false }; var userGroupService = new UserGroupService(accessToken); await userGroupService.Insert(userGroup); return(RedirectToAction("Index", new { groupId })); } } catch { return(View()); } }
// GET: GroupUser/Details/5 public async Task <ActionResult> Details(string userGroupId) { string accessToken = Session["MicrosoftAccessToken"] as string; var roleTypeService = new RoleTypeService(accessToken); var userService = new UserService(accessToken); var userGroupService = new UserGroupService(accessToken); var allRoleTypes = await roleTypeService.GetAllRoleTypes(); var userGroup = await userGroupService.GetUserGroupById(userGroupId); var user = await userService.GetUserById(userGroup.UserId); GroupUserModel guModel = new GroupUserModel(); guModel.UserEmail = user.Email; guModel.RoleTypeId = userGroup.RoleTypeId; guModel.RoleName = allRoleTypes.Single(r => r.Id == userGroup.RoleTypeId).RoleName; guModel.UserGroupId = userGroup.Id; ViewBag.GroupId = userGroup.GroupId; return(View(guModel)); }
public IHttpActionResult Post(GroupUserModel groupUserModel) { // Vérification de l'appelant IHttpActionResult result = this.SecurityCheckRoleAdminOrUser(); if (result != null) { return(result); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // L'appelant doit être un administrateur de la base de données if (!service.IsAdministrateur(this.GetJWTIdentity().Name, groupUserModel.DbId)) { return(ResponseMessage(new System.Net.Http.HttpResponseMessage(HttpStatusCode.Forbidden) { ReasonPhrase = "Vous n'êtes pas administrateur de la base de données" })); } DatabaseGroupUser databaseGroupUser = service.AddContributor(this.GetJWTIdentity().Name, groupUserModel); if (databaseGroupUser == null) { return(Conflict()); } //return CreatedAtRoute("DefaultApi", new { id = databaseGroupUser. }, databaseGroupUser); // L'utilisateur a tous les droits databaseGroupUser.CanBeDeleted = databaseGroupUser.CanBeUpdated = true; return(Ok(databaseGroupUser)); }
public IHttpActionResult GroupDelMember(GroupUserModel model) { ApiServerMsg apiServerMsg = new ApiServerMsg(); try { if (XzyWebSocket._dicSockets.ContainsKey(model.uuid)) { string context = XzyWebSocket._dicSockets[model.uuid].weChatThread.Wx_DeleteChatRoomMember(model.chatroomid, model.user); apiServerMsg.Success = true; apiServerMsg.Context = context; return(Ok(apiServerMsg)); } apiServerMsg.Success = false; apiServerMsg.Context = "不存在该websocket连接"; return(Ok(apiServerMsg)); } catch (Exception ex) { apiServerMsg.Success = false; apiServerMsg.ErrContext = ex.Message; return(Ok(apiServerMsg)); } }
public int Add(GroupUserModel model) { return(_groupUser.Add(model)); }
public DatabaseGroupUser AddContributor(string userLogin, GroupUserModel groupUserModel) { string serverName = null; try { // Obtention de la base de données DatabaseDB databaseDB = GetDatabase(groupUserModel.DbId); if (databaseDB == null) { return(null); } // Obtention du serveur DatabaseServerName databaseServerName = this.db.DatabaseServerNames.Find(databaseDB.ServerId); if (databaseServerName == null) { return(null); } serverName = databaseServerName.Name; // Obtention du serveur réel : MySQL, SQL Server, ... avec son adresse IP DatabaseManagement management = DatabaseManagement.CreateDatabaseManagement(databaseServerName.Code, databaseServerName.IPLocale, databaseServerName.PortLocal); if (management == null) { return(null); } management.AddContributor(databaseDB.NomBD, groupUserModel.SqlLogin, groupUserModel.GroupType, groupUserModel.Password); } catch (Exception ex) { LogManager.GetLogger().Error(ex); throw new DatabaseException(string.Format("Erreur dans l'ajout du contributeur {0} sur le serveur '{1}'", groupUserModel.ToString(), serverName), ex); } DatabaseGroupUser contributor = new DatabaseGroupUser { DbId = groupUserModel.DbId, SqlLogin = groupUserModel.SqlLogin, AddedByUserLogin = userLogin, GroupType = groupUserModel.GroupType, UserLogin = groupUserModel.UserLogin, UserFullName = groupUserModel.UserFullName }; try { // Ajout du contributeur dans le groupe this.db.DatabaseGroupUsers.Add(contributor); this.db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { LogManager.GetLogger().Error(ex); throw new DatabaseException(string.Format("Erreur dans l'ajout du contributeur {0} dans le référentiel", groupUserModel.ToString()), ex); } // Envoi du mail /* * if (userLoginSQL != null) * contributor.UserLoginSQL = userLoginSQL; * * * if (userEpsi != null) * { * contributor.UserEpsiFullName = userEpsi.Nom + " " + userEpsi.Prenom; * * // Envoi du mail * if (!string.IsNullOrWhiteSpace(userEpsi.Mail)) * { * StringBuilder body = new StringBuilder(); * body.AppendFormat("Bonjour, </b><br /><br />Vous avez été ajouté comme contributeur dans la base de données '{0}' par l'utilisateur '{1}'", infos.Name, infos.Createur); * if (accountAdded) * { * body.AppendFormat("<br /><br />Un compte a été créé sur le serveur '{0}' avec un mot de passe aléatoire.<br />", infos.DatabaseServerName.Name); * body.Append("Vous devez vous connecter à <a href='https://ingenium.montpellier.epsi.fr/'>Ingénium</a> pour modifier le mot de passe de ce compte."); * } * body.Append("Connectez-vous à <a href='https://ingenium.montpellier.epsi.fr/'>Ingénium</a> pour voir vos base de données."); * body.Append(@"</b><br /><br />L'administrateur réseau<br />EPSI Montpellier"); * * SendMail(userEpsi.Mail, "EPSI - Base de données - Ajout de contributeur", body.ToString()); * } * } * }*/ return(contributor); /* * { * Message = message, * Status = status, * UserEpsiFullName = contributor.UserEpsiFullName, * UserId = userId, * LoginSQL = contributor.UserLoginSQL, * GroupType = groupType, * GroupTypeDescription = DatabaseService.GetGroupDescription(groupType) * });*/ }