Skip to content

Commit

Permalink
Add community roles (cambiatus#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucca65 authored Dec 9, 2022
1 parent 5d7b79a commit 5663ccf
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 98 deletions.
46 changes: 19 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ on:
branches: [ master ]

jobs:
build:

test:
name: Build and test
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
otp: ['24.2']
elixir: ['1.14.2']

services:
db:
Expand All @@ -25,27 +28,16 @@ jobs:
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24
with:
elixir-version: '1.11.3'
otp-version: '23'
- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install exiftool
run: sudo apt -y install exiftool
- name: Install dependencies
run: mix deps.get
- name: Check Formatting
run: mix format --check-formatted
- name: Check format, compile and credo warnings
run: mix do compile --warnings-as-errors --all warnings, format --check-formatted, credo --strict --only warning
- name: Look for security vulnerabilities
run: mix sobelow --config
- name: Run tests
run: mix test
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: '24.2'
elixir-version: '1.14.2'

- run: sudo apt -y install exiftool
- run: mix deps.get
- run: mix format --check-formatted
- run: mix do format --check-formatted, credo --strict --only warning
- run: mix sobelow --config
- run: mix test

2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
elixir 1.11.3
elixir 1.14.2
1 change: 1 addition & 0 deletions lib/cambiatus/commune/community.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ defmodule Cambiatus.Commune.Community do
has_many(:uploads, CommunityPhotos, foreign_key: :community_id, on_replace: :delete)
has_many(:contributions, Contribution, foreign_key: :community_id)
has_many(:rewards, through: [:objectives, :actions, :rewards])
has_many(:roles, Cambiatus.Commune.Role, foreign_key: :community_id)

has_many(:contacts, Contact,
foreign_key: :community_id,
Expand Down
58 changes: 34 additions & 24 deletions lib/cambiatus_web/schema/commune_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -187,56 +187,70 @@ defmodule CambiatusWeb.Schema.CommuneTypes do
@desc "A community on Cambiatus"
object :community do
field(:symbol, non_null(:string))

# Basic information
field(:creator, non_null(:string))
field(:name, non_null(:string))
field(:description, non_null(:string))
field(:logo, :string)
field(:website, :string)

# Token
field(:inviter_reward, non_null(:float))
field(:invited_reward, non_null(:float))
field(:uploads, non_null(list_of(non_null(:upload))), resolve: dataloader(Cambiatus.Commune))

field(:logo, :string)
field(:type, :string)
field(:issuer, :string)
field(:supply, :float)
field(:max_supply, :float)
field(:min_balance, :float)
field(:type, :string)

field(:website, :string)
# Configuration
field(:has_objectives, non_null(:boolean))
field(:has_shop, non_null(:boolean))
field(:has_kyc, non_null(:boolean))
field(:has_news, non_null(:boolean))
field(:highlighted_news, :news, resolve: dataloader(Cambiatus.Social))
field(:auto_invite, non_null(:boolean))
field(:subdomain, :subdomain, resolve: dataloader(Cambiatus.Commune))

field(:contribution_configuration, :contribution_config,
resolve: dataloader(Cambiatus.Commune)
)

# Sync data
field(:created_block, non_null(:integer))
field(:created_tx, non_null(:string))
field(:created_eos_account, non_null(:string))
field(:created_at, non_null(:datetime))

field(:has_objectives, non_null(:boolean))
field(:has_shop, non_null(:boolean))
field(:has_kyc, non_null(:boolean))

field(:has_news, non_null(:boolean))
field(:highlighted_news, :news, resolve: dataloader(Cambiatus.Social))
field(:uploads, non_null(list_of(non_null(:upload))), resolve: dataloader(Cambiatus.Commune))

connection field(:transfers, node_type: :transfer) do
resolve(&Commune.get_transfers/3)
end

field(:objectives, non_null(list_of(non_null(:objective))),
resolve: dataloader(Cambiatus.Objectives)
)
# Calculated fields
field(:member_count, non_null(:integer), resolve: &Commune.get_members_count/3)
field(:transfer_count, non_null(:integer), resolve: &Commune.get_transfer_count/3)
field(:product_count, non_null(:integer), resolve: &Commune.get_product_count/3)
field(:order_count, non_null(:integer), resolve: &Commune.get_order_count/3)
field(:action_count, non_null(:integer), resolve: &Objectives.get_action_count/3)
field(:claim_count, non_null(:integer), resolve: &Objectives.get_claim_count/3)

@desc "List of users that are claim validators"
field(:validators, non_null(list_of(non_null(:user))), resolve: &Commune.get_validators/3)
field(:roles, non_null(list_of(non_null(:role))), resolve: dataloader(Cambiatus.Commune))

field(:mints, non_null(list_of(non_null(:mint))), resolve: dataloader(Cambiatus.Commune))
field(:members, non_null(list_of(non_null(:user))), resolve: dataloader(Cambiatus.Commune))
field(:orders, non_null(list_of(non_null(:order))), resolve: dataloader(Cambiatus.Shop))
field(:news, non_null(list_of(non_null(:news))), resolve: dataloader(Cambiatus.Social))

field(:objectives, non_null(list_of(non_null(:objective))),
resolve: dataloader(Cambiatus.Objectives)
)

# Earning methods
field(:mints, non_null(list_of(non_null(:mint))), resolve: dataloader(Cambiatus.Commune))

field(:rewards, non_null(list_of(non_null(:reward))),
resolve: dataloader(Cambiatus.Objectives)
)
Expand All @@ -247,18 +261,14 @@ defmodule CambiatusWeb.Schema.CommuneTypes do
resolve(dataloader(Cambiatus.Payments))
end

field(:member_count, non_null(:integer), resolve: &Commune.get_members_count/3)
field(:transfer_count, non_null(:integer), resolve: &Commune.get_transfer_count/3)
field(:product_count, non_null(:integer), resolve: &Commune.get_product_count/3)
field(:order_count, non_null(:integer), resolve: &Commune.get_order_count/3)
field(:action_count, non_null(:integer), resolve: &Objectives.get_action_count/3)
field(:claim_count, non_null(:integer), resolve: &Objectives.get_claim_count/3)
# Shop
field(:orders, non_null(list_of(non_null(:order))), resolve: dataloader(Cambiatus.Shop))

field(:categories, non_null(list_of(non_null(:category))), resolve: dataloader(Cambiatus.Shop))

field(:contacts, non_null(list_of(non_null(:contact))),
resolve: dataloader(Cambiatus.Accounts)
)

field(:categories, non_null(list_of(non_null(:category))), resolve: dataloader(Cambiatus.Shop))
end

@desc "Community Preview data, public data of a community"
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule Cambiatus.Mixfile do
{:number, "~> 1.0"},
{:earmark, "~> 1.4"},
{:html_sanitize_ex, "~> 1.4"},
{:ex_cldr, "~> 2.32"},
{:ex_cldr, "~> 2.33"},
{:ex_cldr_dates_times, "~> 2.12"},

# Email capabilities
Expand Down
Loading

0 comments on commit 5663ccf

Please sign in to comment.