Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/discord slack bots #60

Merged
merged 45 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e5ca2c8
Merge migrations
aralyekta Jan 27, 2025
04ecc07
Add tooltip to integration list
aralyekta Jan 27, 2025
fd0e302
Add modal for integration disconnect
aralyekta Jan 27, 2025
5c9f2b7
Move access token revoke to signal
aralyekta Jan 27, 2025
74d5856
Add signal to manage channels on slack bot
aralyekta Jan 27, 2025
85cb773
Prevent test button clickability until save
aralyekta Jan 27, 2025
90d6acc
Only save the added channels in integration
aralyekta Jan 27, 2025
9721e85
Add guild disconnection for discord bots and merge integration deleti…
aralyekta Jan 27, 2025
8f55672
Remove unnecessary param (textPageHeader) from header
aralyekta Jan 27, 2025
25b0fb8
Remove conditional spacing when guru type is passed to header
aralyekta Jan 27, 2025
4e900d1
Fix header spacings
aralyekta Jan 27, 2025
9f06c98
Improve sidebar on mobile
aralyekta Jan 27, 2025
06c67a7
Fix mobile-desktop views
aralyekta Jan 27, 2025
6754fa8
Update sidebar to select "Integrations" when a specific integration i…
aralyekta Jan 27, 2025
179c711
Remove web widget headers
aralyekta Jan 27, 2025
df5df9e
Fix integration list padding on mobile
aralyekta Jan 27, 2025
ea96340
Fix paddings on mobile
aralyekta Jan 27, 2025
6410fda
Improve spacings
aralyekta Jan 27, 2025
ed7de12
Send final version
aralyekta Jan 27, 2025
0eabf56
Remove dev components
aralyekta Jan 27, 2025
29f27aa
Merge branch 'develop' of https://github.com/Gurubase/gurubase into t…
aralyekta Jan 27, 2025
840b385
Fix integration connection buttons
aralyekta Jan 27, 2025
9b293d2
Improve spacing and size
aralyekta Jan 27, 2025
b827d27
Fix loading skeletons
aralyekta Jan 27, 2025
242d634
Order channel list
aralyekta Jan 27, 2025
8e5e341
Fix dropdowns
aralyekta Jan 28, 2025
bdcea30
Add not found redirection on invalid integration types
aralyekta Jan 28, 2025
aee289f
Add error logs
aralyekta Jan 28, 2025
7523185
Update slack bot permissions in instruction
aralyekta Jan 28, 2025
fbb8170
Fix thread handling and channel validation on discord
aralyekta Jan 28, 2025
34518af
Make discord bot debuggable
aralyekta Jan 28, 2025
9d4f9ba
Update readme for minimal permissions
aralyekta Jan 28, 2025
5209f17
Update question admin page to link binge questions appropriately
aralyekta Jan 28, 2025
e719b5e
Implement logic for viewing bot questions on frontend
aralyekta Jan 28, 2025
dab960b
Merge migrations
aralyekta Jan 28, 2025
3515c48
Add unit tests for the updated question search
aralyekta Jan 28, 2025
ec44f3f
Add support for linking bot questions to the frontend
aralyekta Jan 28, 2025
cc3b58f
Order selected channels alphabetically
aralyekta Jan 28, 2025
0403c28
Fix ss for discord and minimize permissions for slack
aralyekta Jan 28, 2025
b87d870
Add info for discord
aralyekta Jan 28, 2025
02b9218
Add private channel support for slack
aralyekta Jan 28, 2025
c964006
Fix infos of integrations
aralyekta Jan 28, 2025
ae45b56
Fix sidebar while creating a guru
aralyekta Jan 29, 2025
f8aa58c
Hide slack/discord integrations on selfhosted
aralyekta Jan 29, 2025
a9d1867
Remove console logs
fatihbaltaci Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement logic for viewing bot questions on frontend
  • Loading branch information
aralyekta committed Jan 28, 2025
commit e719b5e4ad8d30ef3a9fe8c5ee90b367210903ea
15 changes: 13 additions & 2 deletions src/gurubase-backend/backend/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2664,8 +2664,17 @@ def check_binge_auth(binge, user):
return True
if settings.ENV == 'selfhosted':
return True
if user.is_admin:
if user and user.is_authenticated and user.is_admin:
return True

# Allow access to SLACK and DISCORD questions for everyone
root_question = binge.root_question
if root_question and root_question.source in [Question.Source.SLACK.value, Question.Source.DISCORD.value]:
return True

# For other sources, check ownership
if not user:
return False
return binge.owner == user

def search_question(user, guru_type_object, binge, slug=None, question=None, will_check_binge_auth=True, include_api=False, only_widget=False):
Expand All @@ -2675,6 +2684,7 @@ def get_source_conditions(user):
# For anonymous users
# API requests are not allowed
# Widget requests are allowed
# SLACK and DISCORD questions are allowed
if only_widget:
return Q(source__in=[Question.Source.WIDGET_QUESTION.value])
else:
Expand All @@ -2690,7 +2700,8 @@ def get_source_conditions(user):
if include_api:
return (
~Q(source__in=[Question.Source.API.value, Question.Source.WIDGET_QUESTION.value]) |
Q(source__in=[Question.Source.API.value], user=user)
Q(source__in=[Question.Source.API.value], user=user) |
Q(source__in=[Question.Source.SLACK.value, Question.Source.DISCORD.value])
)
else:
return ~Q(source__in=[Question.Source.API.value, Question.Source.WIDGET_QUESTION.value])
Expand Down
5 changes: 3 additions & 2 deletions src/gurubase-backend/backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ def question_detail(request, guru_type, slug):
'date_updated': format_date_updated(question.date_updated),
'date_created_meta': question.date_created,
'date_updated_meta': question.date_updated,
'follow_up_questions': question.follow_up_questions
'follow_up_questions': question.follow_up_questions,
'source': question.source
}

return Response(question_data)
Expand Down Expand Up @@ -1178,7 +1179,7 @@ def follow_up_examples(request, guru_type):


@api_view(['GET'])
@jwt_auth
@combined_auth
def follow_up_graph(request, guru_type):
user = request.user
validate_guru_type(guru_type, only_active=True)
Expand Down
24 changes: 17 additions & 7 deletions src/gurubase-frontend/src/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,24 @@ export async function createBinge({ guruType, rootSlug }) {
}

export async function getBingeData(guruType, bingeId) {
const response = await makeAuthenticatedRequest(
// const response = await makePublicRequest(
`${process.env.NEXT_PUBLIC_BACKEND_FETCH_URL}/${guruType}/follow_up/graph/?binge_id=${bingeId}`
);

if (!response) return null;
try {
const session = await getUserSession();
const url = `${process.env.NEXT_PUBLIC_BACKEND_FETCH_URL}/${guruType}/follow_up/graph/?binge_id=${bingeId}`;

return await response.json();
if (session?.user) {
// Authenticated request
const response = await makeAuthenticatedRequest(url);
if (!response) return null;
return await response.json();
} else {
// Public request
const response = await makePublicRequest(url);
if (!response) return null;
return await response.json();
}
} catch (error) {
return handleRequestError(error, { guruType, bingeId });
}
}

export async function getBingeHistory(page = 1, query = "") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ const Result = async ({ params, searchParams }) => {
references,
similar_questions,
date_updated,
trust_score
trust_score,
source
} = JSON.parse(response);

const isInstantContentExist = !(
Expand All @@ -196,6 +197,7 @@ const Result = async ({ params, searchParams }) => {
similarQuestions={isInstantContentExist ? similar_questions : []}
slug={searchParams.question_slug}
trustScore={trust_score}
source={source}
/>
);
};
Expand Down
14 changes: 11 additions & 3 deletions src/gurubase-frontend/src/app/g/[guruType]/[slug]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ const Result = async ({ params, searchParams }) => {

// Get all data first
const [response, allGuruTypes] = await Promise.all([
getDataForSlugDetails(params.slug, params.guruType, null, searchParams.question),
getDataForSlugDetails(
params.slug,
params.guruType,
null,
searchParams.question
),
getGuruTypes()
]);

Expand All @@ -179,15 +184,17 @@ const Result = async ({ params, searchParams }) => {
similar_questions,
trust_score,
dirty,
date_updated
date_updated,
source
} = parsedResponse;

const headersList = headers();
const userAgent = headersList.get("user-agent") || "";
const isBot = isbot(userAgent);

const reload = dirty && !isBot;
const isInstantContentExist = !(response && msg?.toLowerCase() === "question not found") && !reload;
const isInstantContentExist =
!(response && msg?.toLowerCase() === "question not found") && !reload;

return (
<ResultClient
Expand All @@ -203,6 +210,7 @@ const Result = async ({ params, searchParams }) => {
similarQuestions={isInstantContentExist ? similar_questions : []}
slug={params.slug}
trustScore={trust_score}
source={source}
/>
);
};
Expand Down
Loading