Skip to content

Conversation

@TaylorBeeston
Copy link
Collaborator

Overview

🎟 Relevant Jira Issues

[LC-634] Back-End: Default Role when Claiming

📚 What is the context and goal of this PR?

To ease with the troops setup, we want to be able to set a default role/permissions that you get automatically
when claiming a boost

🥴 TL; RL:

Adds the ability to give a profile default permissions at the time that they claim a boost

💡 Feature Breakdown (screenshots & videos encouraged!)

  • Boosts now have a claimPermissions field on them.
  • claimPermissions is just a regular permissions object that specifies the permissions a user gets when claiming the boost
  • When setting claimPermissions, a new Role node is made and attached with those permissions!

🛠 Important tradeoffs made:

🔍 Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Chore (refactor, documentation update, etc)

💳 Does This Create Any New Technical Debt? ( If yes, please describe and add JIRA TODOs )

  • No
  • Yes

Testing

🔬 How Can Someone QA This?

Just run the test suite =)

If you'd like to try it out yourself, spin up the LCN with docker (cd services/learn-card-network && docker compose up)

Then:

let a = await initLearnCard({
  seed: "a",
  network: "http://localhost:4000/trpc",
  cloud: { url: "http://localhost:5000/trpc" },
});
let b = await initLearnCard({
  seed: "b",
  network: "http://localhost:4000/trpc",
  cloud: { url: "http://localhost:5000/trpc" },
});

await a.invoke.createProfile({ profileId: "usera" });
await b.invoke.createProfile({ profileId: "userb" });

const testUnsignedBoost = {
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    "https://purl.imsglobal.org/spec/ob/v3p0/context.json",
    {
      type: "@type",
      xsd: "https://www.w3.org/2001/XMLSchema#",
      lcn: "https://docs.learncard.com/definitions#",
      BoostCredential: {
        "@id": "lcn:boostCredential",
        "@context": {
          boostId: { "@id": "lcn:boostId", "@type": "xsd:string" },
          display: {
            "@id": "lcn:boostDisplay",
            "@context": {
              backgroundImage: {
                "@id": "lcn:boostBackgroundImage",
                "@type": "xsd:string",
              },
              backgroundColor: {
                "@id": "lcn:boostBackgroundColor",
                "@type": "xsd:string",
              },
            },
          },
          image: { "@id": "lcn:boostImage", "@type": "xsd:string" },
          attachments: {
            "@id": "lcn:boostAttachments",
            "@container": "@set",
            "@context": {
              type: { "@id": "lcn:boostAttachmentType", "@type": "xsd:string" },
              title: {
                "@id": "lcn:boostAttachmentTitle",
                "@type": "xsd:string",
              },
              url: { "@id": "lcn:boostAttachmentUrl", "@type": "xsd:string" },
            },
          },
        },
      },
    },
  ],
  type: ["VerifiableCredential", "OpenBadgeCredential", "BoostCredential"],
  issuer: "did:web:localhost%3A3000:users:test",
  issuanceDate: "2020-08-19T21:41:50Z",
  name: "Example Boost",
  credentialSubject: {
    id: "did:example:d23dd687a7dc6787646f2eb98d0",
    type: ["AchievementSubject"],
    achievement: {
      id: "urn:uuid:123",
      type: ["Achievement"],
      achievementType: "Influencer",
      name: "Awesome Badge",
      description: "Awesome People Earn Awesome Badge",
      image: "",
      criteria: { narrative: "Earned by being awesome." },
    },
  },
};

const claimPermissions = {
  role: "admin",
  canEdit: true,
  canIssue: true,
  canRevoke: true,
  canManagePermissions: true,
  canIssueChildren: "*",
  canCreateChildren: "*",
  canEditChildren: "*",
  canRevokeChildren: "*",
  canManageChildrenPermissions: "*",
  canViewAnalytics: true,
};

const uri = await test.invoke.createBoost(testUnsignedBoost, {
  claimPermissions,
});

// These permissions should be empty
await a.invoke.getBoostPermissions(uri, 'userb');
await b.invoke.getBoostPermissions(uri);

const sentUri = await a.invoke.sendBoost('userb', uri);

// These permissions should still be empty
await a.invoke.getBoostPermissions(uri, 'userb');
await b.invoke.getBoostPermissions(uri);

await b.invoke.acceptCredential(sentUri);

// These permissions should match the claimPermissions object
await a.invoke.getBoostPermissions(uri, 'userb');
await b.invoke.getBoostPermissions(uri);

📱 🖥 Which devices would you like help testing on?

🧪 Code Coverage

I wrote tests for claiming via acceptCredential as well as via a claim link

Documentation

📜 Gitbook

📊 Storybook

✅ PR Checklist

  • Related to a Jira issue (create one if not)
  • My code follows style guidelines (eslint / prettier)
  • I have manually tested common end-2-end cases
  • I have reviewed my code
  • I have commented my code, particularly where ambiguous
  • New and existing unit tests pass locally with my changes
  • I have made corresponding changes to gitbook documentation

🚀 Ready to squash-and-merge?:

  • Code is backwards compatible
  • There is not a "Do Not Merge" label on this PR
  • I have thoughtfully considered the security implications of this change.
  • This change does not expose new public facing endpoints that do not have authentication

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2024

🦋 Changeset detected

Latest commit: 6d3d198

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@learncard/network-brain-service Patch
@learncard/types Patch
@learncard/network-brain-client Patch
@learncard/chapi-example Patch
@learncard/snap-example-dapp Patch
@learncard/create-http-bridge Patch
@learncard/cli Patch
@learncard/core Patch
@learncard/helpers Patch
@learncard/init Patch
@learncard/react Patch
@learncard/learn-cloud-client Patch
@learncard/ceramic-plugin Patch
@learncard/chapi-plugin Patch
@learncard/did-web-plugin Patch
@learncard/didkey-plugin Patch
@learncard/didkit-plugin Patch
@learncard/idx-plugin Patch
@learncard/network-plugin Patch
@learncard/learn-card-plugin Patch
@learncard/learn-cloud-plugin Patch
@learncard/vc-api-plugin Patch
@learncard/vc-templates-plugin Patch
@learncard/vc-plugin Patch
@learncard/vpqr-plugin Patch
learn-card-discord-bot Patch
@learncard/meta-mask-snap Patch
@learncard/learn-cloud-service Patch
@learncard/snap-chapi-example Patch
@learncard/expiration-plugin Patch
@learncard/crypto-plugin Patch
@learncard/dynamic-loader-plugin Patch
@learncard/ethereum-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Nov 12, 2024

Deploy Preview for learn-card-chapi-example canceled.

Name Link
🔨 Latest commit 6d3d198
🔍 Latest deploy log https://app.netlify.com/sites/learn-card-chapi-example/deploys/6734e8d1bc5b960008cc58d0

@netlify
Copy link

netlify bot commented Nov 12, 2024

Deploy Preview for learncarddocs canceled.

Name Link
🔨 Latest commit 6d3d198
🔍 Latest deploy log https://app.netlify.com/sites/learncarddocs/deploys/6734e8d1bc5b960008cc58cc

Copy link
Collaborator

@goblincore goblincore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests passing

@TaylorBeeston TaylorBeeston merged commit 0b0a2c6 into main Nov 25, 2024
11 checks passed
@TaylorBeeston TaylorBeeston deleted the LC-634-Default-Role branch November 25, 2024 19:12
@github-actions github-actions bot mentioned this pull request Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants