UsersGroups table added to config DB, User and Group have ManyToMany relation, ver. 2.25.1400
This commit is contained in:
parent
ab43cabc57
commit
4090bd1618
@ -1,7 +1,8 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2019 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Config.Entities
|
||||
{
|
||||
@ -9,12 +10,16 @@ namespace Config.Entities
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual Users.Entities.GID GID { get; set; }
|
||||
public virtual long AccessFlags { get; set; } /// Bitfield of access flags: bit0 .. bit62
|
||||
public virtual IList<User> Users { get; set; } /// Group can be a member of a list of users
|
||||
|
||||
public Group()
|
||||
{
|
||||
Users = new List<User>();
|
||||
}
|
||||
|
||||
public Group(Users.Entities.GID gid)
|
||||
: this()
|
||||
{
|
||||
GID = gid;
|
||||
}
|
||||
|
||||
@ -145,17 +145,8 @@ namespace Config
|
||||
using (var transaction = session.BeginTransaction())
|
||||
{
|
||||
///
|
||||
/// Prepare all groups
|
||||
/// Create user 'admin'
|
||||
///
|
||||
var testers = new Config.Entities.Group(Users.Entities.GID.Testers);
|
||||
var testingSpecialists = new Config.Entities.Group(Users.Entities.GID.TestingSpecialists);
|
||||
var headOfLab = new Config.Entities.Group(Users.Entities.GID.HeadOfLab);
|
||||
var maintenanceSpecialists = new Config.Entities.Group(Users.Entities.GID.MaintenanceSpecialists);
|
||||
var metrologists = new Config.Entities.Group(Users.Entities.GID.Metrologists);
|
||||
var calibrationSpecialists = new Config.Entities.Group(Users.Entities.GID.CalibrationSpecialists);
|
||||
var administrators = new Config.Entities.Group(Users.Entities.GID.Administrators);
|
||||
|
||||
/// Create the user 'admin' add his groups
|
||||
var admin = new Config.Entities.User
|
||||
{
|
||||
UserName = Data.AdminUsername,
|
||||
@ -163,20 +154,35 @@ namespace Config
|
||||
LastPwChange = DateTime.Now
|
||||
};
|
||||
admin.SetPassword(Data.AdminPassword);
|
||||
admin.AddGroup(testers);
|
||||
admin.AddGroup(testingSpecialists);
|
||||
admin.AddGroup(headOfLab);
|
||||
admin.AddGroup(maintenanceSpecialists);
|
||||
admin.AddGroup(metrologists);
|
||||
admin.AddGroup(calibrationSpecialists);
|
||||
admin.AddGroup(administrators);
|
||||
|
||||
session.SaveOrUpdate(admin);
|
||||
|
||||
///// Create the control board component
|
||||
//var cmpnt = (new BenchControl.Elde.ControlBoardCfg(new BenchControl.Elde.ControlBoardFactory())).CreateDbEntity();
|
||||
//session.SaveOrUpdate(cmpnt);
|
||||
///
|
||||
/// Prepare all groups, add some of them to admin
|
||||
///
|
||||
for (Users.Entities.GID gid = 0; gid < Users.Entities.GID.NrOfGroups; gid++)
|
||||
{
|
||||
Config.Entities.Group group = new Config.Entities.Group(gid);
|
||||
switch (gid)
|
||||
{
|
||||
case Users.Entities.GID.Testers:
|
||||
case Users.Entities.GID.TestingSpecialists:
|
||||
case Users.Entities.GID.HeadOfLab:
|
||||
case Users.Entities.GID.MaintenanceSpecialists:
|
||||
case Users.Entities.GID.Metrologists:
|
||||
case Users.Entities.GID.CalibrationSpecialists:
|
||||
case Users.Entities.GID.Administrators:
|
||||
#if TURA_IPERL || TURA_IPERL_NEW || TURA_SPECIAL
|
||||
case Users.Entities.GID.TraceabilityManagement:
|
||||
#elif KEMPNO_50 || KRAKOW_50 || TORUN_50 || WARSAW_END
|
||||
case Users.Entities.GID.MetrologicalAuthority:
|
||||
case Users.Entities.GID.WaterMeterAuthority:
|
||||
#endif
|
||||
admin.AddGroup(group);
|
||||
session.SaveOrUpdate(group); /// Save this group
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
session.SaveOrUpdate(admin); /// Save user 'admin'
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2019 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using FluentNHibernate.Mapping;
|
||||
|
||||
@ -7,10 +7,18 @@ namespace Config.Mappings
|
||||
{
|
||||
class GroupMap : ClassMap<Entities.Group>
|
||||
{
|
||||
/// <seealso>
|
||||
/// https://stackoverflow.com/questions/9108083/fluent-nhibernate-many-to-many-mapping-way/9125059
|
||||
/// </seealso>
|
||||
public GroupMap()
|
||||
{
|
||||
Id(x => x.Id);
|
||||
Map(x => x.GID).Column("Name"); ;
|
||||
Map(x => x.GID).Column("Name");
|
||||
Map(x => x.AccessFlags);
|
||||
HasManyToMany(x => x.Users)
|
||||
.Cascade.SaveUpdate()
|
||||
.Inverse()
|
||||
.Table("UsersGroups");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2016-2019 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2016-2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using FluentNHibernate.Mapping;
|
||||
|
||||
@ -19,8 +19,9 @@ namespace Config.Mappings
|
||||
Map(x => x.Password4);
|
||||
Map(x => x.FullName).Column("Description");
|
||||
Map(x => x.LastPwChange);
|
||||
HasMany(x => x.Groups)
|
||||
.Cascade.All();
|
||||
HasManyToMany(x => x.Groups)
|
||||
.Cascade.SaveUpdate()
|
||||
.Table("UsersGroups");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.24.1382.0")]
|
||||
[assembly: AssemblyFileVersion("2.24.1382.0")]
|
||||
[assembly: AssemblyVersion("2.25.1400.0")]
|
||||
[assembly: AssemblyFileVersion("2.25.1400.0")]
|
||||
|
||||
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.24.1390.0")]
|
||||
[assembly: AssemblyFileVersion("2.24.1390.0")]
|
||||
[assembly: AssemblyVersion("2.25.1400.0")]
|
||||
[assembly: AssemblyFileVersion("2.25.1400.0")]
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.24.1391.0")]
|
||||
[assembly: AssemblyFileVersion("2.24.1391.0")]
|
||||
[assembly: AssemblyVersion("2.25.1400.0")]
|
||||
[assembly: AssemblyFileVersion("2.25.1400.0")]
|
||||
|
||||
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.24.1368.0")]
|
||||
[assembly: AssemblyFileVersion("2.24.1368.0")]
|
||||
[assembly: AssemblyVersion("2.25.1400.0")]
|
||||
[assembly: AssemblyFileVersion("2.25.1400.0")]
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2016-2019 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2016-2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -11,16 +11,25 @@ namespace Users.Entities
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual GID GID { get; set; }
|
||||
public virtual long AccessFlags { get; set; } /// Bitfield of access flags: bit0 .. bit62
|
||||
public virtual IList<User> Users { get; set; } /// Group can be a member of a list of users
|
||||
|
||||
public Group()
|
||||
{
|
||||
Users = new List<User>();
|
||||
}
|
||||
|
||||
public Group(GID gid)
|
||||
: this()
|
||||
{
|
||||
GID = gid;
|
||||
}
|
||||
|
||||
public virtual string Gid2Str()
|
||||
{
|
||||
return Group.Gid2Str(this.GID);
|
||||
}
|
||||
|
||||
public static string Gid2Str(GID gid)
|
||||
{
|
||||
switch (gid)
|
||||
|
||||
@ -87,7 +87,7 @@ namespace Users.Entities
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ((groupId >= 0) && (groupId < GID.NrOfGroups) && (Groups != null))
|
||||
else if ((groupId >= 0) && (groupId < GID.NrOfGroups))
|
||||
{
|
||||
foreach (var g in Groups)
|
||||
{
|
||||
@ -113,7 +113,7 @@ namespace Users.Entities
|
||||
|
||||
foreach (var gid in groupIds)
|
||||
{
|
||||
if (gid >= 0 && gid < GID.NrOfGroups)
|
||||
if ((gid >= 0) && (gid < GID.NrOfGroups))
|
||||
{
|
||||
/// for all group elements in User.Groups
|
||||
foreach (var grp in Groups)
|
||||
|
||||
@ -17,7 +17,7 @@ namespace Users.Forms
|
||||
{
|
||||
NHibernate.ISession session;
|
||||
User user;
|
||||
GID[] displayedGIDs;
|
||||
IList<Group> displayedGroups;
|
||||
|
||||
|
||||
bool[] oriGroupMember; /// index is gid, size is Grp.Count
|
||||
@ -32,18 +32,18 @@ namespace Users.Forms
|
||||
{
|
||||
InitializeComponent();
|
||||
this.toolTip1.SetToolTip(this.txtName, string.Format(Strings.max_0_alphanum_chars, 20));
|
||||
oriGroupMember = new bool[(displayedGIDs != null) ? displayedGIDs.Length : 0];
|
||||
oriGroupMember = new bool[(displayedGroups != null) ? displayedGroups.Count : 0];
|
||||
okBtn.Enabled = false;
|
||||
}
|
||||
|
||||
public EditSelectedUser(NHibernate.ISession session, User user, GID[] displayedGIDs)
|
||||
public EditSelectedUser(NHibernate.ISession session, User user, IList<Group> displayedGroups)
|
||||
: this()
|
||||
{
|
||||
this.session = session;
|
||||
this.user = user;
|
||||
this.displayedGIDs = displayedGIDs;
|
||||
this.displayedGroups = displayedGroups;
|
||||
|
||||
oriGroupMember = new bool[(displayedGIDs != null) ? displayedGIDs.Length : 0];
|
||||
oriGroupMember = new bool[(displayedGroups != null) ? displayedGroups.Count : 0];
|
||||
}
|
||||
|
||||
private void EditSelectedUser_Load(object sender, EventArgs e)
|
||||
@ -124,12 +124,12 @@ namespace Users.Forms
|
||||
public void ShowGroups()
|
||||
{
|
||||
checkedListBoxGroups.Items.Clear();
|
||||
for (int i= 0; i < displayedGIDs.Length; i++)
|
||||
for (int i= 0; i < displayedGroups.Count; i++)
|
||||
{
|
||||
GID gid = displayedGIDs[i];
|
||||
Group group = displayedGroups[i];
|
||||
|
||||
bool boolIsMember = oriGroupMember[i] = user.IsMemberOf(gid);
|
||||
checkedListBoxGroups.Items.Add(Group.Gid2Str(gid));
|
||||
bool boolIsMember = oriGroupMember[i] = user.IsMemberOf(group.GID);
|
||||
checkedListBoxGroups.Items.Add(group.Gid2Str());
|
||||
checkedListBoxGroups.SetItemCheckState(i, boolIsMember ? CheckState.Checked : CheckState.Unchecked);
|
||||
}
|
||||
}
|
||||
@ -189,30 +189,22 @@ namespace Users.Forms
|
||||
user.LastPwChange = DateTime.MinValue;
|
||||
}
|
||||
|
||||
///
|
||||
/// Groups
|
||||
///
|
||||
IList<Group> groups = user.Groups; /// = session.QueryOver<Group>().Where(x => (x.User.Id == user.Id)).List();
|
||||
for (int i = 0; i < displayedGIDs.Length; i++ )
|
||||
for (int i = 0; i < displayedGroups.Count; i++ )
|
||||
{
|
||||
GID gid = displayedGIDs[i];
|
||||
Group group = displayedGroups[i];
|
||||
bool newIsMember = checkedListBoxGroups.GetItemChecked(i);
|
||||
|
||||
if (!newIsMember && oriGroupMember[i])
|
||||
{
|
||||
for (int j = 0; j < user.Groups.Count; j++)
|
||||
{
|
||||
Group grp = user.Groups[j];
|
||||
if (grp.GID == gid)
|
||||
{
|
||||
session.Delete(user.Groups[j]);
|
||||
user.Groups.RemoveAt(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
user.Groups.Remove(group);
|
||||
}
|
||||
else if (newIsMember && !oriGroupMember[i])
|
||||
{
|
||||
Group newGroup = new Group(gid);
|
||||
user.Groups.Add(newGroup);
|
||||
user.Groups.Add(group);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -26,39 +26,7 @@ namespace Users.Forms
|
||||
const int NameSurnameColumn = 2;
|
||||
|
||||
|
||||
static GID[] DisplayedGIDs = new GID[]
|
||||
{
|
||||
#if TURA_IPERL || TURA_IPERL_NEW || TURA_SPECIAL
|
||||
GID.Testers,
|
||||
GID.TestingSpecialists,
|
||||
GID.HeadOfLab,
|
||||
GID.MaintenanceSpecialists,
|
||||
GID.Metrologists,
|
||||
GID.CalibrationSpecialists,
|
||||
GID.Administrators,
|
||||
GID.TraceabilityManagement,
|
||||
#elif KEMPNO_50 || KRAKOW_50 || TORUN_50 || WARSAW_END
|
||||
GID.Testers,
|
||||
GID.TestingSpecialists,
|
||||
GID.HeadOfLab,
|
||||
GID.MaintenanceSpecialists,
|
||||
GID.Metrologists,
|
||||
GID.CalibrationSpecialists,
|
||||
GID.Administrators,
|
||||
GID.MetrologicalAuthority,
|
||||
GID.WaterMeterAuthority,
|
||||
#else
|
||||
GID.Testers,
|
||||
GID.TestingSpecialists,
|
||||
GID.HeadOfLab,
|
||||
GID.MaintenanceSpecialists,
|
||||
GID.Metrologists,
|
||||
GID.CalibrationSpecialists,
|
||||
GID.Administrators,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
IList<Group> displayedGroups;
|
||||
public string TitleExtension;
|
||||
|
||||
|
||||
@ -77,6 +45,17 @@ namespace Users.Forms
|
||||
this.session = session;
|
||||
this.showExtensions = showLocalExtensions;
|
||||
if (showLocalExtensions) copyFromRemoteButton.Visible = true;
|
||||
|
||||
try
|
||||
{
|
||||
displayedGroups = session.QueryOver<Group>().List();
|
||||
listOfUsers = session.QueryOver<User>().List();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (displayedGroups == null) displayedGroups = new List<Group>();
|
||||
if (listOfUsers == null) listOfUsers = new List<User>();
|
||||
}
|
||||
}
|
||||
|
||||
private void UserManagementDlg_Load(object sender, EventArgs e)
|
||||
@ -97,47 +76,35 @@ namespace Users.Forms
|
||||
listViewUsers.Columns.Add(Strings.Tag, 110);
|
||||
listViewUsers.Columns.Add(Strings.Groups, 370);
|
||||
|
||||
try
|
||||
{
|
||||
listOfUsers = session.QueryOver<User>().List();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
string msg = exc.Message;
|
||||
}
|
||||
|
||||
ListUsers();
|
||||
}
|
||||
|
||||
public void ListUsers()
|
||||
{
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
listViewUsers.Items.Clear();
|
||||
foreach (User u in listOfUsers)
|
||||
{
|
||||
string grps = string.Empty;
|
||||
///
|
||||
foreach (var gid in DisplayedGIDs)
|
||||
{
|
||||
if (u.IsMemberOf(gid))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(grps)) grps += ", ";
|
||||
grps += Group.Gid2Str(gid);
|
||||
}
|
||||
}
|
||||
|
||||
ListViewItem item = new ListViewItem(u.UserName);
|
||||
item.Tag = u;
|
||||
item.SubItems.Add(u.Number.ToString());
|
||||
item.SubItems.Add(u.FullName);
|
||||
item.SubItems.Add(string.IsNullOrEmpty(u.Tag) ? string.Empty : u.Tag);
|
||||
|
||||
/// Show groups of this user
|
||||
string grps = string.Empty;
|
||||
foreach (var group in displayedGroups)
|
||||
{
|
||||
if (u.IsMemberOf(group.GID))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(grps)) grps += ", ";
|
||||
grps += group.Gid2Str();
|
||||
}
|
||||
}
|
||||
item.SubItems.Add(grps);
|
||||
item.Tag = u;
|
||||
|
||||
this.listViewUsers.Items.Add(item);
|
||||
}
|
||||
this.listViewUsers.Refresh();
|
||||
|
||||
Cursor.Current = Cursors.Default;
|
||||
}
|
||||
|
||||
private void closeButton_Click(object sender, EventArgs e)
|
||||
@ -209,7 +176,7 @@ namespace Users.Forms
|
||||
{
|
||||
if (listViewUsers.SelectedItems.Count == 1 && listViewUsers.SelectedItems[0].Tag is User)
|
||||
{
|
||||
new Forms.EditSelectedUser(session, (User)listViewUsers.SelectedItems[0].Tag, DisplayedGIDs).ShowDialog();
|
||||
new Forms.EditSelectedUser(session, (User)listViewUsers.SelectedItems[0].Tag, displayedGroups).ShowDialog();
|
||||
ListUsers();
|
||||
}
|
||||
}
|
||||
@ -222,7 +189,7 @@ namespace Users.Forms
|
||||
private void addButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
User newUser = new User();
|
||||
if (new Forms.EditSelectedUser(session, newUser, DisplayedGIDs).ShowDialog() == DialogResult.OK)
|
||||
if (new Forms.EditSelectedUser(session, newUser, displayedGroups).ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
listOfUsers.Add(newUser);
|
||||
}
|
||||
@ -233,10 +200,10 @@ namespace Users.Forms
|
||||
{
|
||||
if (listViewUsers.SelectedItems.Count == 1 && listViewUsers.SelectedItems[0].Tag is User)
|
||||
{
|
||||
User Selecteduser = listViewUsers.SelectedItems[0].Tag as User;
|
||||
session.Delete(Selecteduser);
|
||||
User selecteduser = session.Get<User>((listViewUsers.SelectedItems[0].Tag as User).Id);
|
||||
session.Delete(selecteduser);
|
||||
session.Flush();
|
||||
listOfUsers.Remove(Selecteduser);
|
||||
listOfUsers.RemoveAt(listViewUsers.SelectedIndices[0]);
|
||||
ListUsers();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2016-2019 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2016-2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using FluentNHibernate.Mapping;
|
||||
|
||||
@ -7,10 +7,18 @@ namespace Users.Mappings
|
||||
{
|
||||
class GroupMap : ClassMap<Entities.Group>
|
||||
{
|
||||
/// <seealso>
|
||||
/// https://stackoverflow.com/questions/9108083/fluent-nhibernate-many-to-many-mapping-way/9125059
|
||||
/// </seealso>
|
||||
public GroupMap()
|
||||
{
|
||||
Id(x => x.Id);
|
||||
Map(x => x.GID).Column("Name"); ;
|
||||
Map(x => x.GID).Column("Name");
|
||||
Map(x => x.AccessFlags);
|
||||
HasManyToMany(x => x.Users)
|
||||
.Cascade.SaveUpdate()
|
||||
.Inverse()
|
||||
.Table("UsersGroups");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2016-2019 Sensus Slovensko a.s.
|
||||
/// Copyright (c) 2016-2020 Sensus Slovensko a.s.
|
||||
///
|
||||
using FluentNHibernate.Mapping;
|
||||
|
||||
@ -19,8 +19,9 @@ namespace Users.Mappings
|
||||
Map(x => x.Password4);
|
||||
Map(x => x.FullName).Column("Description");
|
||||
Map(x => x.LastPwChange);
|
||||
HasMany(x => x.Groups)
|
||||
.Cascade.All();
|
||||
HasManyToMany(x => x.Groups)
|
||||
.Cascade.SaveUpdate()
|
||||
.Table("UsersGroups");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.24.1382.0")]
|
||||
[assembly: AssemblyFileVersion("2.24.1382.0")]
|
||||
[assembly: AssemblyVersion("2.25.1400.0")]
|
||||
[assembly: AssemblyFileVersion("2.25.1400.0")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user