This commit is contained in:
Felipe Martin Garcia 2022-08-15 18:30:28 +00:00 committed by GitHub
commit 69fc99dd08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 74 additions and 23 deletions

View File

@ -3,6 +3,7 @@ package config
import (
"bufio"
"context"
"fmt"
"os"
"strings"
"time"
@ -61,7 +62,10 @@ type Config struct {
}
LogLevel string `env:"LOG_LEVEL,default=info"`
Notion struct {
IntegrationToken string `env:"NOTION_INTEGRATION_TOKEN,required"`
IntegrationType string `env:"NOTION_INTEGRATION_TYPE,required"`
IntegrationToken string `env:"NOTION_INTEGRATION_TOKEN"`
OAuthID string `env:"NOTION_OAUTH_ID"`
OAuthSecret string `env:"NOTION_OAUTH_SECRET"`
MaxPagination int `env:"NOTION_MAX_PAGINATION,default=2"`
Client *notion.NotionClient // Must be manually set up
}
@ -82,6 +86,22 @@ type Config struct {
}
}
func (c Config) Validate() error {
if c.Notion.IntegrationType != notion.IntegrationTypeInternal && c.Notion.IntegrationType != notion.IntegrationTypePublic {
return fmt.Errorf("Notion's integration type should be %s or %s", notion.IntegrationTypeInternal, notion.IntegrationTypePublic)
}
if c.Notion.IntegrationType == notion.IntegrationTypeInternal && c.Notion.IntegrationToken == "" {
return fmt.Errorf("Notion internal integration requires setting up the integration token")
}
if c.Notion.IntegrationType == notion.IntegrationTypePublic && c.Notion.OAuthID == "" && c.Notion.OAuthSecret == "" {
return fmt.Errorf("Notion's public integration requires setting up the OAuth credentials")
}
return nil
}
func ParseServerConfiguration(ctx context.Context, logger *zap.Logger) *Config {
var cfg Config
@ -95,5 +115,9 @@ func ParseServerConfiguration(ctx context.Context, logger *zap.Logger) *Config {
logger.Fatal("Error parsing configuration: %s", zap.Error(err))
}
if err := cfg.Validate(); err != nil {
logger.Fatal("Error validating configuration: %s", zap.Error(err))
}
return &cfg
}

View File

@ -8,6 +8,11 @@ import (
"go.uber.org/zap"
)
const (
IntegrationTypeInternal = "internal"
IntegrationTypePublic = "public"
)
type NotionClient struct {
Client *notion.Client
logger *zap.Logger

View File

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View File

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -36,6 +36,9 @@ func (s *HttpServer) Setup(cfg *config.Config) {
c.Locals("branding_thanks_message", cfg.Branding.ThanksMessage)
c.Locals("branding_footer_extra", cfg.Branding.FooterExtraMessage)
c.Locals("calendar_cache_time", cfg.Routes.Calendar.CacheExpiration.String())
c.Locals("notion_integration_type", cfg.Notion.IntegrationType)
c.Locals("notion_oauth_id", cfg.Notion.OAuthID)
c.Locals("notion_oauth_secret", cfg.Notion.OAuthSecret)
return c.Next()
}).
Use(recover.New()).

View File

@ -0,0 +1,26 @@
<h3>1.</h3>
<p>
Give access to Notion2iCal to your Notion database by using the <kbd>Share</kbd> button
on the top right of your database and searching for <i>Notion2iCal</i>. Only read permissions
are required.
</p>
<p>
<img src="{{ static("/images/usage-internal.png") }}" srcset="{{ static("/images/usage-internal@2x.png") }} 2x" />
</p>
<h3>2.</h3>
<form action="/wizard" method="post">
<p>
<label for="database_url">After giving access, paste your Notion database URL here to setup your calendar.</label>
<input type="url" name="database_url" placeholder="https://notion.so/workspace/...">
</p>
<h3>3.</h3>
{% if error %}
<p><mark>ERROR: {{ error }}</mark></p>
{% endif %}
<button type="submit">Click here to setup your calendar</button>
</form>

View File

@ -0,0 +1,10 @@
<h3>1.</h3>
<p>First, you need to authenticate youself with Notion2iCal, you will authorize the application within your workspace and then you will select to which databases Notion2iCal can read individually.</p>
<p><img src="{{ static("/images/usage-public.png") }}" srcset="{{ static("/images/usage-public@2x.png") }} 2x" /><p>
<form action="https://api.notion.com/v1/oauth/authorize" method="get">
<input type="hidden" name="owner" value="user" />
<input type="hidden" name="response_type" value="code" />
<input type="hidden" name="client_id" value="{{ notion_oauth_id }}" />
<input type="hidden" name="redirect_url" value="http://localhost:8080" />
<button type="submit">Authorize Notion2iCal</button>
</form>

View File

@ -6,27 +6,10 @@
Online tool to convert a Notion database into an iCalendar subscription URL or downloadable ICS file.
</p>
<h2 id="how-it-works">How it works</h2>
<h3>1.</h3>
<p>
Give access to Notion2iCal to your Notion database by using the <kbd>Share</kbd> button
on the top right of your database and searching for <i>Notion2iCal</i>. Only read permissions
are required.
</p>
<p>
<img src="{{ static("/images/usage.png") }}" srcset="{{ static("/images/usage@2x.png") }} 2x" />
</p>
<form action="/wizard" method="post">
<h3>2.</h3>
<p>
<label>After giving access, paste your Notion database URL here to setup your calendar.</label>
<input type="url" name="database_url" placeholder="https://notion.so/workspace/...">
</p>
<h3>3.</h3>
{% if error %}
<p><mark>ERROR: {{ error }}</mark></p>
{% endif %}
<button type="submit">Click here to setup your calendar</button>
</form>
{% if notion_integration_type == "internal" %}
{% include "auth_internal.django" %}
{% else %}
{% include "auth_public.django" %}
{% endif %}
</div>
{% endblock %}