Skip to content

Commit 778d5e7

Browse files
- Updated the Fundraising Participant block so participants can continue to act on their own group requirements.
1 parent f5a0002 commit 778d5e7

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎Rock.Blocks/Fundraising/FundraisingParticipant.cs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
using Rock.Data;
2727
using Rock.Model;
2828
using Rock.Obsidian.UI;
29+
using Rock.Security;
30+
using Rock.Security.SecurityGrantRules;
2931
using Rock.Utility;
3032
using Rock.ViewModels.Blocks.Fundraising.FundraisingParticipant;
3133
using Rock.ViewModels.Controls;
@@ -306,6 +308,7 @@ private void GetFundraisingParticipantBox( FundraisingParticipantInitializationB
306308

307309
box.RequirementsHeaderHtml = GetAttributeValue( AttributeKey.RequirementsHeaderLavaTemplate ).ResolveMergeFields( mergeFields );
308310
box.Requirements = GetRequirementsBag( group, groupMember );
311+
box.SecurityGrantToken = GetSecurityGrantToken( groupMember );
309312
}
310313
}
311314

@@ -387,6 +390,32 @@ private string GetProfileWarningText( GroupMember groupMember )
387390
return $"Edit your profile to add a {missingItems.AsDelimited( ", ", " and " )}.";
388391
}
389392

393+
/// <summary>
394+
/// Gets a security grant token that lets the viewer act on the participant's requirements.
395+
/// </summary>
396+
/// <param name="groupMember">The participant group member.</param>
397+
/// <returns>A security grant token covering the participant's group member and person records.</returns>
398+
private string GetSecurityGrantToken( GroupMember groupMember )
399+
{
400+
return new SecurityGrant()
401+
.AddRule( new EntitySecurityGrantRule( groupMember.TypeId, groupMember.Id, Authorization.EDIT ) )
402+
.AddRule( new EntitySecurityGrantRule( groupMember.Person.TypeId, groupMember.PersonId ) )
403+
.ToToken();
404+
}
405+
406+
/// <inheritdoc/>
407+
protected override string RenewSecurityGrantToken()
408+
{
409+
var groupMember = GetGroupMember();
410+
411+
if ( groupMember == null || !IsViewerAuthorized() )
412+
{
413+
return string.Empty;
414+
}
415+
416+
return GetSecurityGrantToken( groupMember );
417+
}
418+
390419
/// <summary>
391420
/// Builds the configuration the group member requirements container needs to load and
392421
/// display the participant's requirement statuses.

‎Rock.JavaScript.Obsidian.Blocks/src/Fundraising/fundraisingParticipant.obs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<script setup lang="ts">
1919
import { ref } from "vue";
20-
import { useConfigurationValues } from "@Obsidian/Utility/block";
20+
import { getSecurityGrant, provideSecurityGrant, useConfigurationValues } from "@Obsidian/Utility/block";
2121
import { AlertType } from "@Obsidian/Enums/Controls/alertType";
2222
import NotificationBox from "@Obsidian/Controls/notificationBox.obs";
2323
import EditPanel from "./fundraisingParticipant/editPanel.partial.obs";
@@ -30,6 +30,9 @@
3030
// updated payload (no full page reload needed).
3131
const box = ref(useConfigurationValues<FundraisingParticipantInitializationBox>());
3232

33+
const securityGrant = getSecurityGrant(box.value.securityGrantToken);
34+
provideSecurityGrant(securityGrant);
35+
3336
const isEditMode = ref(false);
3437

3538
// #endregion Values
@@ -49,6 +52,7 @@
4952
*/
5053
function onEditSave(updatedBox: FundraisingParticipantInitializationBox): void {
5154
box.value = updatedBox;
55+
securityGrant.updateToken(updatedBox.securityGrantToken);
5256
isEditMode.value = false;
5357
}
5458

‎Rock.JavaScript.Obsidian/Framework/ViewModels/Blocks/Fundraising/FundraisingParticipant/fundraisingParticipantInitializationBox.d.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ export type FundraisingParticipantInitializationBox = {
9090
/** Gets or sets the resolved Requirements Header Lava Template HTML. */
9191
requirementsHeaderHtml?: string | null;
9292

93+
/**
94+
* Gets or sets the security grant token used by controls on the block.
95+
* null when the viewer is not authorized to act on the participant's requirements.
96+
*/
97+
securityGrantToken?: string | null;
98+
9399
/** Gets or sets the resolved Updates Lava Template HTML (content channel items). */
94100
updatesHtml?: string | null;
95101

‎Rock.ViewModels/Blocks/Fundraising/FundraisingParticipant/FundraisingParticipantInitializationBox.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public class FundraisingParticipantInitializationBox
5959
/// </summary>
6060
public FundraisingParticipantRequirementsBag Requirements { get; set; }
6161

62+
/// <summary>
63+
/// Gets or sets the security grant token used by controls on the block.
64+
/// <c>null</c> when the viewer is not authorized to act on the participant's requirements.
65+
/// </summary>
66+
public string SecurityGrantToken { get; set; }
67+
6268
/// <summary>
6369
/// Gets or sets the profile-completeness tip shown to the participant (for example,
6470
/// to add a photo or a personal introduction). <c>null</c> when nothing is missing.

0 commit comments

Comments
 (0)