本文整理汇总了C#中Group.IsAuthorized方法的典型用法代码示例。如果您正苦于以下问题:C# Group.IsAuthorized方法的具体用法?C# Group.IsAuthorized怎么用?C# Group.IsAuthorized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Group
的用法示例。
在下文中一共展示了Group.IsAuthorized方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnInit
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
protected override void OnInit( EventArgs e )
{
base.OnInit( e );
RegisterScript();
_rockContext = new RockContext();
int groupId = PageParameter( "GroupId" ).AsInteger();
_group = new GroupService( _rockContext )
.Queryable( "GroupType,Schedule" ).AsNoTracking()
.FirstOrDefault( g => g.Id == groupId );
if ( _group != null && _group.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
{
lHeading.Text = _group.Name + " Attendance";
_canEdit = true;
}
_allowAdd = GetAttributeValue( "AllowAdd" ).AsBoolean();
_allowCampusFilter = GetAttributeValue( "AllowCampusFilter" ).AsBoolean();
bddlCampus.Visible = _allowCampusFilter;
if ( _allowCampusFilter )
{
bddlCampus.DataSource = CampusCache.All();
bddlCampus.DataBind();
bddlCampus.Items.Insert( 0, new ListItem( "All Campuses", "0" ) );
}
}
示例2: ShowReadonlyDetails
//.........这里部分代码省略.........
{
hlCampus.Visible = true;
hlCampus.Text = group.Campus.Name;
}
else
{
hlCampus.Visible = false;
}
lblMainDetails.Text = descriptionList.Html;
var attributes = new List<Rock.Web.Cache.AttributeCache>();
// Get the attributes inherited from group type
GroupType groupType = new GroupTypeService( rockContext ).Get( group.GroupTypeId );
groupType.LoadAttributes();
attributes = groupType.Attributes.Select( a => a.Value ).OrderBy( a => a.Order ).ThenBy( a => a.Name ).ToList();
// Combine with the group attributes
group.LoadAttributes();
attributes.AddRange( group.Attributes.Select( a => a.Value ).OrderBy( a => a.Order ).ThenBy( a => a.Name ) );
// display attribute values
var attributeCategories = Helper.GetAttributeCategories( attributes );
Rock.Attribute.Helper.AddDisplayControls( group, attributeCategories, phAttributes );
// Get Map Style
phMaps.Controls.Clear();
var mapStyleValue = DefinedValueCache.Read( GetAttributeValue( "MapStyle" ) );
if ( mapStyleValue == null )
{
mapStyleValue = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.MAP_STYLE_ROCK );
}
if ( mapStyleValue != null )
{
string mapStyle = mapStyleValue.GetAttributeValue( "StaticMapStyle" );
if ( !string.IsNullOrWhiteSpace( mapStyle ) )
{
// Get all the group locations and group all those that have a geo-location into either points or polygons
var points = new List<GroupLocation>();
var polygons = new List<GroupLocation>();
foreach ( GroupLocation groupLocation in group.GroupLocations )
{
if ( groupLocation.Location != null )
{
if ( groupLocation.Location.GeoPoint != null )
{
points.Add( groupLocation );
}
else if ( groupLocation.Location.GeoFence != null )
{
polygons.Add( groupLocation );
}
}
}
if ( points.Any() )
{
foreach ( var groupLocation in points )
{
string markerPoints = string.Format( "{0},{1}", groupLocation.Location.GeoPoint.Latitude, groupLocation.Location.GeoPoint.Longitude );
string mapLink = System.Text.RegularExpressions.Regex.Replace( mapStyle, @"\{\s*MarkerPoints\s*\}", markerPoints );
mapLink = System.Text.RegularExpressions.Regex.Replace( mapLink, @"\{\s*PolygonPoints\s*\}", string.Empty );
mapLink += "&sensor=false&size=350x200&zoom=13&format=png";
var literalcontrol = new Literal()
{
Text = string.Format(
"<div class='group-location-map'>{0}<img src='{1}'/></div>",
groupLocation.GroupLocationTypeValue != null ? ( "<h4>" + groupLocation.GroupLocationTypeValue.Name + "</h4>" ) : string.Empty,
mapLink ),
Mode = LiteralMode.PassThrough
};
phMaps.Controls.Add( literalcontrol );
}
}
if ( polygons.Any() )
{
foreach ( var groupLocation in polygons )
{
string polygonPoints = "enc:" + groupLocation.Location.EncodeGooglePolygon();
string mapLink = System.Text.RegularExpressions.Regex.Replace( mapStyle, @"\{\s*MarkerPoints\s*\}", string.Empty );
mapLink = System.Text.RegularExpressions.Regex.Replace( mapLink, @"\{\s*PolygonPoints\s*\}", polygonPoints );
mapLink += "&sensor=false&size=350x200&format=png";
phMaps.Controls.Add(
new LiteralControl( string.Format(
"<div class='group-location-map'>{0}<img src='{1}'/></div>",
groupLocation.GroupLocationTypeValue != null ? ( "<h4>" + groupLocation.GroupLocationTypeValue.Name + "</h4>" ) : string.Empty,
mapLink ) ) );
}
}
}
}
btnSecurity.Visible = group.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );
btnSecurity.Title = group.Name;
btnSecurity.EntityId = group.Id;
}
示例3: OnInit
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
protected override void OnInit( EventArgs e )
{
base.OnInit( e );
_rockContext = new RockContext();
int groupId = PageParameter( "GroupId" ).AsInteger();
_group = new GroupService( _rockContext )
.Queryable( "GroupLocations" ).AsNoTracking()
.FirstOrDefault( g => g.Id == groupId );
if ( _group != null && _group.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
{
_group.LoadAttributes( _rockContext );
_canView = true;
rFilter.ApplyFilterClick += rFilter_ApplyFilterClick;
gOccurrences.DataKeyNames = new string[] { "Date", "ScheduleId", "LocationId" };
gOccurrences.Actions.AddClick += gOccurrences_Add;
gOccurrences.GridRebind += gOccurrences_GridRebind;
gOccurrences.RowDataBound += gOccurrences_RowDataBound;
// make sure they have Auth to edit the block OR edit to the Group
bool canEditBlock = IsUserAuthorized( Authorization.EDIT ) || _group.IsAuthorized( Authorization.EDIT, this.CurrentPerson );
gOccurrences.Actions.ShowAdd = canEditBlock && GetAttributeValue( "AllowAdd" ).AsBoolean();
gOccurrences.IsDeleteEnabled = canEditBlock;
}
_allowCampusFilter = GetAttributeValue( "AllowCampusFilter" ).AsBoolean();
bddlCampus.Visible = _allowCampusFilter;
if ( _allowCampusFilter )
{
bddlCampus.DataSource = CampusCache.All();
bddlCampus.DataBind();
bddlCampus.Items.Insert( 0, new ListItem( "All Campuses", "0" ) );
}
}
示例4: ShowReadonlyDetails
//.........这里部分代码省略.........
hlType.Text = group.GroupType.Name;
lGroupDescription.Text = group.Description;
DescriptionList descriptionList = new DescriptionList();
if ( group.ParentGroup != null )
{
descriptionList.Add( "Parent Group", group.ParentGroup.Name );
}
if ( group.Campus != null )
{
hlCampus.Visible = true;
hlCampus.Text = group.Campus.Name;
}
else
{
hlCampus.Visible = false;
}
lblMainDetails.Text = descriptionList.Html;
var attributes = new List<Rock.Web.Cache.AttributeCache>();
// Get the attributes inherited from group type
GroupType groupType = new GroupTypeService().Get( group.GroupTypeId );
groupType.LoadAttributes();
attributes = groupType.Attributes.Select( a => a.Value ).OrderBy( a => a.Order ).ThenBy( a => a.Name ).ToList();
// Combine with the group attributes
group.LoadAttributes();
attributes.AddRange( group.Attributes.Select( a => a.Value ).OrderBy( a => a.Order ).ThenBy( a => a.Name ) );
// display attribute values
var attributeCategories = Helper.GetAttributeCategories( attributes );
Rock.Attribute.Helper.AddDisplayControls( group, attributeCategories, phAttributes );
// Get all the group locations and group all those that have a geo-location into either points or polygons
var points = new List<GroupLocation>();
var polygons = new List<GroupLocation>();
foreach ( GroupLocation groupLocation in group.GroupLocations )
{
if ( groupLocation.Location != null )
{
if ( groupLocation.Location.GeoPoint != null )
{
points.Add( groupLocation );
}
else if ( groupLocation.Location.GeoFence != null )
{
polygons.Add( groupLocation );
}
}
}
var dict = new Dictionary<string, object>();
if ( points.Any() )
{
var pointsList = new List<Dictionary<string, object>>();
foreach ( var groupLocation in points)
{
var pointsDict = new Dictionary<string, object>();
if ( groupLocation.GroupLocationTypeValue != null )
{
pointsDict.Add( "type", groupLocation.GroupLocationTypeValue.Name );
}
pointsDict.Add( "latitude", groupLocation.Location.GeoPoint.Latitude );
pointsDict.Add( "longitude", groupLocation.Location.GeoPoint.Longitude );
pointsList.Add( pointsDict );
}
dict.Add( "points", pointsList );
}
if ( polygons.Any() )
{
var polygonsList = new List<Dictionary<string, object>>();
foreach ( var groupLocation in polygons )
{
var polygonDict = new Dictionary<string, object>();
if ( groupLocation.GroupLocationTypeValue != null )
{
polygonDict.Add( "type", groupLocation.GroupLocationTypeValue.Name );
}
polygonDict.Add( "polygon_wkt", groupLocation.Location.GeoFence.AsText());
polygonDict.Add( "google_encoded_polygon", groupLocation.Location.EncodeGooglePolygon() );
polygonsList.Add( polygonDict );
}
dict.Add( "polygons", polygonsList );
}
phMaps.Controls.Clear();
phMaps.Controls.Add( new LiteralControl( GetAttributeValue( "MapHTML" ).ResolveMergeFields( dict ) ) );
btnSecurity.Visible = group.IsAuthorized( "Administrate", CurrentPerson );
btnSecurity.Title = group.Name;
btnSecurity.EntityId = group.Id;
}
示例5: OnInit
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
protected override void OnInit( EventArgs e )
{
base.OnInit( e );
_rockContext = new RockContext();
_group = new GroupService( _rockContext ).Get( PageParameter( "GroupId" ).AsInteger() );
if ( _group != null && _group.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
{
_group.LoadAttributes( _rockContext );
_canView = true;
gOccurrences.DataKeyNames = new string[] { "StartDateTime" };
gOccurrences.Actions.AddClick += gOccurrences_Add;
gOccurrences.GridRebind += gOccurrences_GridRebind;
// make sure they have Auth to edit the block OR edit to the Group
bool canEditBlock = IsUserAuthorized( Authorization.EDIT ) || _group.IsAuthorized( Authorization.EDIT, this.CurrentPerson );
gOccurrences.Actions.ShowAdd = canEditBlock && GetAttributeValue("AllowAdd").AsBoolean();
gOccurrences.IsDeleteEnabled = canEditBlock;
}
}
示例6: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="groupId">The group identifier.</param>
/// <param name="parentGroupId">The parent group identifier.</param>
public void ShowDetail( int groupId, int? parentGroupId )
{
Group group = null;
bool viewAllowed = false;
bool editAllowed = IsUserAuthorized( Authorization.EDIT );
RockContext rockContext = null;
if ( !groupId.Equals( 0 ) )
{
group = GetGroup( groupId, rockContext );
}
if ( group == null )
{
group = new Group { Id = 0, IsActive = true, ParentGroupId = parentGroupId, Name = "" };
wpGeneral.Expanded = true;
if ( parentGroupId.HasValue )
{
rockContext = rockContext ?? new RockContext();
// Set the new group's parent group (so security checks work)
var parentGroup = new GroupService( rockContext ).Get(parentGroupId.Value);
if ( parentGroup != null )
{
// Start by setting the group type to the same as the parent
group.ParentGroup = parentGroup;
group.GroupTypeId = parentGroup.GroupTypeId;
group.GroupType = parentGroup.GroupType;
if ( !editAllowed )
{
// If user is not allowed to edit this new group (with paren't group type),
// check to see if they'd be allowed to edit any other of the allowed
// child group types
editAllowed = group.IsAuthorized( Authorization.EDIT, CurrentPerson );
if ( !editAllowed )
{
foreach( var groupType in GetAllowedGroupTypes( parentGroup, rockContext )
.Where( g => g.Id != parentGroup.GroupTypeId ) )
{
group.GroupTypeId = groupType.Id;
group.GroupType = groupType;
if ( group.IsAuthorized(Authorization.EDIT, CurrentPerson))
{
// Once a group type is found that allows user to edit, keep that
// group type by default
editAllowed = true;
break;
}
}
}
}
}
}
}
viewAllowed = editAllowed || group.IsAuthorized( Authorization.VIEW, CurrentPerson );
editAllowed = IsUserAuthorized( Authorization.EDIT ) || group.IsAuthorized( Authorization.EDIT, CurrentPerson );
pnlDetails.Visible = viewAllowed;
hfGroupId.Value = group.Id.ToString();
// render UI based on Authorized and IsSystem
bool readOnly = false;
nbEditModeMessage.Text = string.Empty;
if ( !editAllowed )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Group.FriendlyTypeName );
}
if ( group.IsSystem )
{
nbEditModeMessage.Text = EditModeMessage.System( Group.FriendlyTypeName );
}
var roleLimitWarnings = new StringBuilder();
if ( group.GroupType != null && group.GroupType.Roles != null && group.GroupType.Roles.Any() )
{
foreach ( var role in group.GroupType.Roles )
{
int curCount = 0;
if ( group.Members != null )
{
curCount = group.Members
.Where( m => m.GroupRoleId == role.Id && m.GroupMemberStatus == GroupMemberStatus.Active )
.Count();
}
//.........这里部分代码省略.........
示例7: ShowReadonlyDetails
//.........这里部分代码省略.........
var linkages = group.Linkages.ToList();
if ( linkages.Any() )
{
linkages
.Where( l =>
l.RegistrationInstanceId.HasValue )
.ToList()
.ForEach( l => registrations
.AddOrIgnore( l.RegistrationInstanceId.Value, l.ToString( true, true, false ) ) );
linkages
.Where( l =>
l.EventItemOccurrence != null &&
l.EventItemOccurrence.EventItem != null )
.ToList()
.ForEach( l => eventItemOccurrences
.AddOrIgnore( l.EventItemOccurrence.Id, string.Format( "{0} - {1}", l.EventItemOccurrence.EventItem.Name, l.EventItemOccurrence.Campus != null ? l.EventItemOccurrence.Campus.Name : "All Campuses" ) ) );
linkages
.Where( l =>
l.EventItemOccurrence != null &&
l.EventItemOccurrence.EventItem != null &&
l.EventItemOccurrence.ContentChannelItems.Any() )
.SelectMany( l => l.EventItemOccurrence.ContentChannelItems.Where( i => i.ContentChannelItem != null ) )
.ToList()
.ForEach( i => contentItems
.AddOrIgnore( i.ContentChannelItem.Id, string.Format( "{0} <small>({1})</small>", i.ContentChannelItem.Title, i.ContentChannelItem.ContentChannelType.Name ) ) );
rptLinkedRegistrations.DataSource = registrations;
rptLinkedRegistrations.DataBind();
rptEventItemOccurrences.DataSource = eventItemOccurrences;
rptEventItemOccurrences.DataBind();
rptContentItems.DataSource = contentItems;
rptContentItems.DataBind();
}
rcwLinkedRegistrations.Visible = registrations.Any();
rcwEventItemOccurrences.Visible = eventItemOccurrences.Any();
rcwContentItems.Visible = contentItems.Any();
// Get Map Style
phMaps.Controls.Clear();
var mapStyleValue = DefinedValueCache.Read( GetAttributeValue( "MapStyle" ) );
if ( mapStyleValue == null )
{
mapStyleValue = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.MAP_STYLE_ROCK );
}
if ( mapStyleValue != null )
{
string mapStyle = mapStyleValue.GetAttributeValue( "StaticMapStyle" );
if ( !string.IsNullOrWhiteSpace( mapStyle ) )
{
foreach ( GroupLocation groupLocation in group.GroupLocations.OrderBy( gl => ( gl.GroupLocationTypeValue != null ) ? gl.GroupLocationTypeValue.Order : int.MaxValue ) )
{
if ( groupLocation.Location != null )
{
if ( groupLocation.Location.GeoPoint != null )
{
string markerPoints = string.Format( "{0},{1}", groupLocation.Location.GeoPoint.Latitude, groupLocation.Location.GeoPoint.Longitude );
string mapLink = System.Text.RegularExpressions.Regex.Replace( mapStyle, @"\{\s*MarkerPoints\s*\}", markerPoints );
mapLink = System.Text.RegularExpressions.Regex.Replace( mapLink, @"\{\s*PolygonPoints\s*\}", string.Empty );
mapLink += "&sensor=false&size=450x250&zoom=13&format=png";
var literalcontrol = new Literal()
{
Text = string.Format(
"<div class='group-location-map'>{0}<a href='{1}'><img class='img-thumbnail' src='{2}'/></a></div>",
groupLocation.GroupLocationTypeValue != null ? ( "<h4>" + groupLocation.GroupLocationTypeValue.Value + "</h4>" ) : string.Empty,
groupMapUrl,
mapLink ),
Mode = LiteralMode.PassThrough
};
phMaps.Controls.Add( literalcontrol );
}
else if ( groupLocation.Location.GeoFence != null )
{
string polygonPoints = "enc:" + groupLocation.Location.EncodeGooglePolygon();
string mapLink = System.Text.RegularExpressions.Regex.Replace( mapStyle, @"\{\s*MarkerPoints\s*\}", string.Empty );
mapLink = System.Text.RegularExpressions.Regex.Replace( mapLink, @"\{\s*PolygonPoints\s*\}", polygonPoints );
mapLink += "&sensor=false&size=350x200&format=png";
phMaps.Controls.Add(
new LiteralControl( string.Format(
"<div class='group-location-map'>{0}<a href='{1}'><img class='img-thumbnail' src='{2}'/></a></div>",
groupLocation.GroupLocationTypeValue != null ? ( "<h4>" + groupLocation.GroupLocationTypeValue.Value + "</h4>" ) : string.Empty,
groupMapUrl,
mapLink ) ) );
}
}
}
}
}
hlMap.Visible = !string.IsNullOrWhiteSpace( groupMapUrl );
hlMap.NavigateUrl = groupMapUrl;
btnSecurity.Visible = group.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );
btnSecurity.EntityId = group.Id;
}
示例8: ShowEditDetails
/// <summary>
/// Shows the edit details.
/// </summary>
/// <param name="group">The group.</param>
private void ShowEditDetails( Group group )
{
if ( group.Id == 0 )
{
lReadOnlyTitle.Text = ActionTitle.Add( Group.FriendlyTypeName ).FormatAsHtmlTitle();
// hide the panel drawer that show created and last modified dates
pdAuditDetails.Visible = false;
}
else
{
lReadOnlyTitle.Text = group.Name.FormatAsHtmlTitle();
}
SetHighlightLabelVisibility( group, false );
ddlGroupType.Visible = group.Id == 0;
lGroupType.Visible = group.Id != 0;
SetEditMode( true );
tbName.Text = group.Name;
tbDescription.Text = group.Description;
nbGroupCapacity.Text = group.GroupCapacity.ToString();
cbIsSecurityRole.Checked = group.IsSecurityRole;
cbIsActive.Checked = group.IsActive;
cbIsPublic.Checked = group.IsPublic;
var rockContext = new RockContext();
var groupService = new GroupService( rockContext );
var attributeService = new AttributeService( rockContext );
LoadDropDowns( rockContext );
ddlSignatureDocumentTemplate.SetValue( group.RequiredSignatureDocumentTemplateId );
gpParentGroup.SetValue( group.ParentGroup ?? groupService.Get( group.ParentGroupId ?? 0 ) );
// hide sync and requirements panel if no admin access
bool canAdministrate = group.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );
wpGroupSync.Visible = canAdministrate;
wpGroupRequirements.Visible = canAdministrate;
wpGroupMemberAttributes.Visible = canAdministrate;
var systemEmails = new SystemEmailService( rockContext ).Queryable().OrderBy( e => e.Title )
.Select( a => new
{
a.Id,
a.Title
} );
// add a blank for the first option
ddlWelcomeEmail.Items.Add( new ListItem() );
ddlExitEmail.Items.Add( new ListItem() );
if ( systemEmails.Any() )
{
foreach ( var systemEmail in systemEmails )
{
ddlWelcomeEmail.Items.Add( new ListItem( systemEmail.Title, systemEmail.Id.ToString() ) );
ddlExitEmail.Items.Add( new ListItem( systemEmail.Title, systemEmail.Id.ToString() ) );
}
}
// set dataview
dvpSyncDataview.EntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id;
dvpSyncDataview.SetValue( group.SyncDataViewId );
if ( group.AddUserAccountsDuringSync.HasValue )
{
rbCreateLoginDuringSync.Checked = group.AddUserAccountsDuringSync.Value;
}
if ( group.WelcomeSystemEmailId.HasValue )
{
ddlWelcomeEmail.SetValue( group.WelcomeSystemEmailId );
}
if ( group.ExitSystemEmailId.HasValue )
{
ddlExitEmail.SetValue( group.ExitSystemEmailId );
}
// GroupType depends on Selected ParentGroup
ddlParentGroup_SelectedIndexChanged( null, null );
gpParentGroup.Label = "Parent Group";
if ( group.Id == 0 && group.GroupType == null && ddlGroupType.Items.Count > 1 )
{
if ( GetAttributeValue( "LimittoSecurityRoleGroups" ).AsBoolean() )
{
// default GroupType for new Group to "Security Roles" if LimittoSecurityRoleGroups
var securityRoleGroupType = GroupTypeCache.GetSecurityRoleGroupType();
if ( securityRoleGroupType != null )
{
CurrentGroupTypeId = securityRoleGroupType.Id;
//.........这里部分代码省略.........
示例9: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="groupId">The group identifier.</param>
/// <param name="parentGroupId">The parent group identifier.</param>
public void ShowDetail( int groupId, int? parentGroupId )
{
Group group = null;
bool viewAllowed = false;
bool editAllowed = IsUserAuthorized( Authorization.EDIT );
RockContext rockContext = new RockContext();
if ( !groupId.Equals( 0 ) )
{
group = GetGroup( groupId, rockContext );
}
if ( group == null )
{
group = new Group { Id = 0, IsActive = true, IsPublic = true, ParentGroupId = parentGroupId, Name = string.Empty };
wpGeneral.Expanded = true;
if ( parentGroupId.HasValue )
{
// Set the new group's parent group (so security checks work)
var parentGroup = new GroupService( rockContext ).Get( parentGroupId.Value );
if ( parentGroup != null )
{
// Start by setting the group type to the same as the parent
group.ParentGroup = parentGroup;
// get all the allowed GroupTypes as defined by the parent group type
var allowedChildGroupTypesOfParentGroup = GetAllowedGroupTypes( parentGroup, rockContext ).ToList();
// narrow it down to group types that the current user is allowed to edit
var authorizedGroupTypes = new List<GroupType>();
foreach ( var allowedGroupType in allowedChildGroupTypesOfParentGroup )
{
// to see if the user is authorized for the group type, test by setting the new group's grouptype and see if they are authorized
group.GroupTypeId = allowedGroupType.Id;
group.GroupType = allowedGroupType;
if ( group.IsAuthorized( Authorization.EDIT, CurrentPerson ) )
{
authorizedGroupTypes.Add( allowedGroupType );
// they have EDIT auth to at least one GroupType, so they are allowed to try to add this group
editAllowed = true;
}
}
// exactly one grouptype is allowed/authorized, so it is safe to default this new group to it
if ( authorizedGroupTypes.Count() == 1 )
{
group.GroupType = authorizedGroupTypes.First();
group.GroupTypeId = group.GroupType.Id;
}
else
{
// more than one grouptype is allowed/authorized, so don't default it so they are forced to pick which one
group.GroupType = null;
group.GroupTypeId = 0;
}
}
}
}
viewAllowed = editAllowed || group.IsAuthorized( Authorization.VIEW, CurrentPerson );
editAllowed = editAllowed || group.IsAuthorized( Authorization.EDIT, CurrentPerson );
pnlDetails.Visible = viewAllowed;
hfGroupId.Value = group.Id.ToString();
// render UI based on Authorized and IsSystem
bool readOnly = false;
nbEditModeMessage.Text = string.Empty;
if ( !editAllowed )
{
readOnly = true;
nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Group.FriendlyTypeName );
}
if ( group.IsSystem )
{
nbEditModeMessage.Text = EditModeMessage.System( Group.FriendlyTypeName );
}
var roleLimitWarnings = new StringBuilder();
if ( group.GroupType != null && group.GroupType.Roles != null && group.GroupType.Roles.Any() )
{
foreach ( var role in group.GroupType.Roles.Where( a => a.MinCount.HasValue || a.MaxCount.HasValue ) )
{
var groupMemberService = new GroupMemberService( rockContext );
int curCount = groupMemberService.Queryable().Where( m => m.GroupId == group.Id && m.GroupRoleId == role.Id && m.GroupMemberStatus == GroupMemberStatus.Active ).Count();
//.........这里部分代码省略.........