diff --git a/assets/js/components/channels/ChannelIndex.jsx b/assets/js/components/channels/ChannelIndex.jsx index 78442c540..fdd75f78f 100644 --- a/assets/js/components/channels/ChannelIndex.jsx +++ b/assets/js/components/channels/ChannelIndex.jsx @@ -29,7 +29,6 @@ type State = { modalSurveys: Array, modalProvider: ?string, modalIndex: ?number, - modalError: ?Object, } class ChannelIndex extends Component { @@ -42,7 +41,6 @@ class ChannelIndex extends Component { modalSurveys: [], modalProvider: null, modalIndex: null, - modalError: null, } } @@ -64,7 +62,6 @@ class ChannelIndex extends Component { modalSurveys: [], modalProvider: provider, modalIndex: index, - modalError: null, }) const { baseUrl } = config[provider][index] api.fetchActiveSurveys(provider, baseUrl) @@ -75,17 +72,6 @@ class ChannelIndex extends Component { modalSurveys: surveys, modalProvider: provider, modalIndex: index, - modalError: null, - }) - }) - .catch((error) => { - console.log(error) - this.setState({ - modalLoading: false, - modalSurveys: [], - modalProvider: provider, - modalIndex: index, - modalError: error, }) }) } else { @@ -185,7 +171,6 @@ class ChannelIndex extends Component { const providerModal = (provider, index, friendlyName, multiple) => { const loading = provider === modalProvider && index === modalIndex ? modalLoading : false const surveys = provider === modalProvider && index === modalIndex ? modalSurveys : [] - const error = provider === modalProvider && index === modalIndex ? modalError : null return ( { onConfirm={() => this.deleteProvider(provider, index)} loading={loading} surveys={surveys} - error={error} /> ) } diff --git a/assets/js/components/channels/ProviderModal.jsx b/assets/js/components/channels/ProviderModal.jsx index 332af657b..8887e1c96 100644 --- a/assets/js/components/channels/ProviderModal.jsx +++ b/assets/js/components/channels/ProviderModal.jsx @@ -11,7 +11,6 @@ export const ProviderModal = ({ onConfirm, loading, surveys, - error, }) => { let name = `${provider[0].toUpperCase()}${provider.slice(1)}` if (multiple) name = `${name} (${friendlyName})` @@ -30,7 +29,6 @@ export const ProviderModal = ({
{loading ? {t("Searching active surveys...")} : - error ? {t("Error searching active surveys...")} : surveys.length == 0 ? {t("No active surveys")} :
{t("These surveys are active, using channels from this provider. Deleting the channels will interrupt the surveys.")} @@ -57,7 +55,6 @@ ProviderModal.propTypes = { onConfirm: PropTypes.func, loading: PropTypes.bool, surveys: PropTypes.any, - error: PropTypes.any, } export default translate()(ProviderModal) diff --git a/assets/vendor/css/materialize/components/_global.scss b/assets/vendor/css/materialize/components/_global.scss index b974a78f1..86b54eb35 100755 --- a/assets/vendor/css/materialize/components/_global.scss +++ b/assets/vendor/css/materialize/components/_global.scss @@ -801,7 +801,3 @@ td, th{ } } } - -.provider-error { - color: $input-error-color; -} diff --git a/lib/ask/survey.ex b/lib/ask/survey.ex index 9141c1f5b..d77551fe4 100644 --- a/lib/ask/survey.ex +++ b/lib/ask/survey.ex @@ -20,7 +20,8 @@ defmodule Ask.Survey do RespondentStats, ConfigHelper, SystemTime, - PanelSurvey + PanelSurvey, + ProjectMembership } alias Ask.Ecto.Type.JSON @@ -530,10 +531,16 @@ defmodule Ask.Survey do %{survey | down_channels: down_channels} end - def with_active_channels(provider, base_url) do + def with_active_channels(user_id, provider, base_url) do query = from s in Survey, where: s.state == :running, + join: pm in ProjectMembership, + on: pm.project_id == s.project_id and pm.user_id == ^user_id, + select: s + + query = + from s in subquery(query), join: group in RespondentGroup, on: s.id == group.survey_id, join: rgc in RespondentGroupChannel, diff --git a/lib/ask_web/controllers/survey_controller.ex b/lib/ask_web/controllers/survey_controller.ex index c5180f29a..1f812ad5b 100644 --- a/lib/ask_web/controllers/survey_controller.ex +++ b/lib/ask_web/controllers/survey_controller.ex @@ -530,7 +530,7 @@ defmodule AskWeb.SurveyController do end def active_channels(conn, %{"provider" => provider, "base_url" => base_url}) do - surveys = Survey.with_active_channels(provider, base_url) + surveys = Survey.with_active_channels(current_user(conn).id, provider, base_url) render(conn, "index.json", surveys: surveys) end diff --git a/locales/template/translation.json b/locales/template/translation.json index 07f02100a..bba418c69 100644 --- a/locales/template/translation.json +++ b/locales/template/translation.json @@ -170,7 +170,6 @@ "Error ID:": "", "Error details": "", "Error message": "", - "Error searching active surveys...": "", "Error: CSV doesn't have a header for the primary language": "", "Error: CSV is empty": "", "Error: primary language name not found for code": "", diff --git a/test/ask/survey_test.exs b/test/ask/survey_test.exs index e03b63963..36a61a30f 100644 --- a/test/ask/survey_test.exs +++ b/test/ask/survey_test.exs @@ -118,28 +118,41 @@ defmodule Ask.SurveyTest do end test "enumerates surveys with active channel" do + user = insert(:user) + project = create_project_for_user(user) + + user2 = insert(:user) + project2 = create_project_for_user(user2) + surveys = [ - insert(:survey, state: :ready), - insert(:survey, state: :running), - insert(:survey, state: :running), - insert(:survey, state: :running), + insert(:survey, state: :ready, project: project), + insert(:survey, state: :running, project: project), + insert(:survey, state: :running, project: project2), + insert(:survey, state: :running, project: project2), ] channels = [ - insert(:channel, provider: "sms", base_url: "test"), - insert(:channel, provider: "sms", base_url: "test"), - insert(:channel, provider: "ivr", base_url: "prod"), - insert(:channel, provider: "sms", base_url: "test"), + insert(:channel, provider: "sms", base_url: "test", projects: [project]), + insert(:channel, provider: "sms", base_url: "test", projects: [project]), + insert(:channel, provider: "ivr", base_url: "prod", projects: [project2]), + insert(:channel, provider: "sms", base_url: "test", projects: [project2]), ] setup_surveys_with_channels(surveys, channels) active_surveys = - Survey.with_active_channels("sms", "test") + Survey.with_active_channels(user.id, "sms", "test") + |> Enum.map(fn c -> c.id end) + |> Enum.sort() + + assert active_surveys == [Enum.at(surveys, 1).id] + + active_surveys2 = + Survey.with_active_channels(user2.id, "sms", "test") |> Enum.map(fn c -> c.id end) |> Enum.sort() - assert active_surveys == [Enum.at(surveys, 1).id, Enum.at(surveys, 3).id] + assert active_surveys2 == [Enum.at(surveys, 3).id] end test "enumerates channels of a survey" do