You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue.go 18 kB

Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Restricted users (#6274) * Restricted users (#4334): initial implementation * Add User.IsRestricted & UI to edit it * Pass user object instead of user id to places where IsRestricted flag matters * Restricted users: maintain access rows for all referenced repos (incl public) * Take logged in user & IsRestricted flag into account in org/repo listings, searches and accesses * Add basic repo access tests for restricted users Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Mention restricted users in the faq Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert unnecessary change `.isUserPartOfOrg` -> `.IsUserPartOfOrg` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Remove unnecessary `org.IsOrganization()` call Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert to an `int64` keyed `accessMap` * Add type `userAccess` * Add convenience func updateUserAccess() * Turn accessMap into a `map[int64]userAccess` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * or even better: `map[int64]*userAccess` * updateUserAccess(): use tighter syntax as suggested by lafriks * even tighter * Avoid extra loop * Don't disclose limited orgs to unauthenticated users * Don't assume block only applies to orgs * Use an array of `VisibleType` for filtering * fix yet another thinko * Ok - no need for u * Revert "Ok - no need for u" This reverts commit 5c3e886aabd5acd997a3b35687d322439732c200. Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv>
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
6 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package repo
  6. import (
  7. "fmt"
  8. "net/http"
  9. "strings"
  10. "time"
  11. "code.gitea.io/gitea/models"
  12. "code.gitea.io/gitea/modules/context"
  13. issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
  14. "code.gitea.io/gitea/modules/log"
  15. "code.gitea.io/gitea/modules/setting"
  16. api "code.gitea.io/gitea/modules/structs"
  17. "code.gitea.io/gitea/modules/timeutil"
  18. "code.gitea.io/gitea/modules/util"
  19. issue_service "code.gitea.io/gitea/services/issue"
  20. )
  21. // SearchIssues searches for issues across the repositories that the user has access to
  22. func SearchIssues(ctx *context.APIContext) {
  23. // swagger:operation GET /repos/issues/search issue issueSearchIssues
  24. // ---
  25. // summary: Search for issues across the repositories that the user has access to
  26. // produces:
  27. // - application/json
  28. // parameters:
  29. // - name: state
  30. // in: query
  31. // description: whether issue is open or closed
  32. // type: string
  33. // - name: labels
  34. // in: query
  35. // description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded
  36. // type: string
  37. // - name: page
  38. // in: query
  39. // description: page number of requested issues
  40. // type: integer
  41. // - name: q
  42. // in: query
  43. // description: search string
  44. // type: string
  45. // - name: priority_repo_id
  46. // in: query
  47. // description: repository to prioritize in the results
  48. // type: integer
  49. // format: int64
  50. // responses:
  51. // "200":
  52. // "$ref": "#/responses/IssueList"
  53. var isClosed util.OptionalBool
  54. switch ctx.Query("state") {
  55. case "closed":
  56. isClosed = util.OptionalBoolTrue
  57. case "all":
  58. isClosed = util.OptionalBoolNone
  59. default:
  60. isClosed = util.OptionalBoolFalse
  61. }
  62. // find repos user can access (for issue search)
  63. repoIDs := make([]int64, 0)
  64. opts := &models.SearchRepoOptions{
  65. PageSize: 15,
  66. Private: false,
  67. AllPublic: true,
  68. TopicOnly: false,
  69. Collaborate: util.OptionalBoolNone,
  70. OrderBy: models.SearchOrderByRecentUpdated,
  71. Actor: ctx.User,
  72. }
  73. if ctx.IsSigned {
  74. opts.Private = true
  75. opts.AllLimited = true
  76. }
  77. issueCount := 0
  78. for page := 1; ; page++ {
  79. opts.Page = page
  80. repos, count, err := models.SearchRepositoryByName(opts)
  81. if err != nil {
  82. ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err)
  83. return
  84. }
  85. if len(repos) == 0 {
  86. break
  87. }
  88. log.Trace("Processing next %d repos of %d", len(repos), count)
  89. for _, repo := range repos {
  90. switch isClosed {
  91. case util.OptionalBoolTrue:
  92. issueCount += repo.NumClosedIssues
  93. case util.OptionalBoolFalse:
  94. issueCount += repo.NumOpenIssues
  95. case util.OptionalBoolNone:
  96. issueCount += repo.NumIssues
  97. }
  98. repoIDs = append(repoIDs, repo.ID)
  99. }
  100. }
  101. var issues []*models.Issue
  102. keyword := strings.Trim(ctx.Query("q"), " ")
  103. if strings.IndexByte(keyword, 0) >= 0 {
  104. keyword = ""
  105. }
  106. var issueIDs []int64
  107. var labelIDs []int64
  108. var err error
  109. if len(keyword) > 0 && len(repoIDs) > 0 {
  110. issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword)
  111. }
  112. labels := ctx.Query("labels")
  113. if splitted := strings.Split(labels, ","); labels != "" && len(splitted) > 0 {
  114. labelIDs, err = models.GetLabelIDsInReposByNames(repoIDs, splitted)
  115. if err != nil {
  116. ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err)
  117. return
  118. }
  119. }
  120. // Only fetch the issues if we either don't have a keyword or the search returned issues
  121. // This would otherwise return all issues if no issues were found by the search.
  122. if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
  123. issues, err = models.Issues(&models.IssuesOptions{
  124. RepoIDs: repoIDs,
  125. Page: ctx.QueryInt("page"),
  126. PageSize: setting.UI.IssuePagingNum,
  127. IsClosed: isClosed,
  128. IssueIDs: issueIDs,
  129. LabelIDs: labelIDs,
  130. SortType: "priorityrepo",
  131. PriorityRepoID: ctx.QueryInt64("priority_repo_id"),
  132. })
  133. }
  134. if err != nil {
  135. ctx.Error(http.StatusInternalServerError, "Issues", err)
  136. return
  137. }
  138. apiIssues := make([]*api.Issue, len(issues))
  139. for i := range issues {
  140. apiIssues[i] = issues[i].APIFormat()
  141. }
  142. ctx.SetLinkHeader(issueCount, setting.UI.IssuePagingNum)
  143. ctx.JSON(http.StatusOK, &apiIssues)
  144. }
  145. // ListIssues list the issues of a repository
  146. func ListIssues(ctx *context.APIContext) {
  147. // swagger:operation GET /repos/{owner}/{repo}/issues issue issueListIssues
  148. // ---
  149. // summary: List a repository's issues
  150. // produces:
  151. // - application/json
  152. // parameters:
  153. // - name: owner
  154. // in: path
  155. // description: owner of the repo
  156. // type: string
  157. // required: true
  158. // - name: repo
  159. // in: path
  160. // description: name of the repo
  161. // type: string
  162. // required: true
  163. // - name: state
  164. // in: query
  165. // description: whether issue is open or closed
  166. // type: string
  167. // - name: labels
  168. // in: query
  169. // description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded
  170. // type: string
  171. // - name: page
  172. // in: query
  173. // description: page number of requested issues
  174. // type: integer
  175. // - name: q
  176. // in: query
  177. // description: search string
  178. // type: string
  179. // responses:
  180. // "200":
  181. // "$ref": "#/responses/IssueList"
  182. var isClosed util.OptionalBool
  183. switch ctx.Query("state") {
  184. case "closed":
  185. isClosed = util.OptionalBoolTrue
  186. case "all":
  187. isClosed = util.OptionalBoolNone
  188. default:
  189. isClosed = util.OptionalBoolFalse
  190. }
  191. var issues []*models.Issue
  192. keyword := strings.Trim(ctx.Query("q"), " ")
  193. if strings.IndexByte(keyword, 0) >= 0 {
  194. keyword = ""
  195. }
  196. var issueIDs []int64
  197. var labelIDs []int64
  198. var err error
  199. if len(keyword) > 0 {
  200. issueIDs, err = issue_indexer.SearchIssuesByKeyword([]int64{ctx.Repo.Repository.ID}, keyword)
  201. }
  202. if splitted := strings.Split(ctx.Query("labels"), ","); len(splitted) > 0 {
  203. labelIDs, err = models.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted)
  204. if err != nil {
  205. ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err)
  206. return
  207. }
  208. }
  209. // Only fetch the issues if we either don't have a keyword or the search returned issues
  210. // This would otherwise return all issues if no issues were found by the search.
  211. if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
  212. issues, err = models.Issues(&models.IssuesOptions{
  213. RepoIDs: []int64{ctx.Repo.Repository.ID},
  214. Page: ctx.QueryInt("page"),
  215. PageSize: setting.UI.IssuePagingNum,
  216. IsClosed: isClosed,
  217. IssueIDs: issueIDs,
  218. LabelIDs: labelIDs,
  219. })
  220. }
  221. if err != nil {
  222. ctx.Error(http.StatusInternalServerError, "Issues", err)
  223. return
  224. }
  225. apiIssues := make([]*api.Issue, len(issues))
  226. for i := range issues {
  227. apiIssues[i] = issues[i].APIFormat()
  228. }
  229. ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, setting.UI.IssuePagingNum)
  230. ctx.JSON(http.StatusOK, &apiIssues)
  231. }
  232. // GetIssue get an issue of a repository
  233. func GetIssue(ctx *context.APIContext) {
  234. // swagger:operation GET /repos/{owner}/{repo}/issues/{index} issue issueGetIssue
  235. // ---
  236. // summary: Get an issue
  237. // produces:
  238. // - application/json
  239. // parameters:
  240. // - name: owner
  241. // in: path
  242. // description: owner of the repo
  243. // type: string
  244. // required: true
  245. // - name: repo
  246. // in: path
  247. // description: name of the repo
  248. // type: string
  249. // required: true
  250. // - name: index
  251. // in: path
  252. // description: index of the issue to get
  253. // type: integer
  254. // format: int64
  255. // required: true
  256. // responses:
  257. // "200":
  258. // "$ref": "#/responses/Issue"
  259. // "404":
  260. // "$ref": "#/responses/notFound"
  261. issue, err := models.GetIssueWithAttrsByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  262. if err != nil {
  263. if models.IsErrIssueNotExist(err) {
  264. ctx.NotFound()
  265. } else {
  266. ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
  267. }
  268. return
  269. }
  270. ctx.JSON(http.StatusOK, issue.APIFormat())
  271. }
  272. // CreateIssue create an issue of a repository
  273. func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
  274. // swagger:operation POST /repos/{owner}/{repo}/issues issue issueCreateIssue
  275. // ---
  276. // summary: Create an issue. If using deadline only the date will be taken into account, and time of day ignored.
  277. // consumes:
  278. // - application/json
  279. // produces:
  280. // - application/json
  281. // parameters:
  282. // - name: owner
  283. // in: path
  284. // description: owner of the repo
  285. // type: string
  286. // required: true
  287. // - name: repo
  288. // in: path
  289. // description: name of the repo
  290. // type: string
  291. // required: true
  292. // - name: body
  293. // in: body
  294. // schema:
  295. // "$ref": "#/definitions/CreateIssueOption"
  296. // responses:
  297. // "201":
  298. // "$ref": "#/responses/Issue"
  299. // "403":
  300. // "$ref": "#/responses/forbidden"
  301. // "412":
  302. // "$ref": "#/responses/error"
  303. // "422":
  304. // "$ref": "#/responses/validationError"
  305. var deadlineUnix timeutil.TimeStamp
  306. if form.Deadline != nil && ctx.Repo.CanWrite(models.UnitTypeIssues) {
  307. deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
  308. }
  309. issue := &models.Issue{
  310. RepoID: ctx.Repo.Repository.ID,
  311. Repo: ctx.Repo.Repository,
  312. Title: form.Title,
  313. PosterID: ctx.User.ID,
  314. Poster: ctx.User,
  315. Content: form.Body,
  316. DeadlineUnix: deadlineUnix,
  317. }
  318. var assigneeIDs = make([]int64, 0)
  319. var err error
  320. if ctx.Repo.CanWrite(models.UnitTypeIssues) {
  321. issue.MilestoneID = form.Milestone
  322. assigneeIDs, err = models.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
  323. if err != nil {
  324. if models.IsErrUserNotExist(err) {
  325. ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
  326. } else {
  327. ctx.Error(http.StatusInternalServerError, "AddAssigneeByName", err)
  328. }
  329. return
  330. }
  331. // Check if the passed assignees is assignable
  332. for _, aID := range assigneeIDs {
  333. assignee, err := models.GetUserByID(aID)
  334. if err != nil {
  335. ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
  336. return
  337. }
  338. valid, err := models.CanBeAssigned(assignee, ctx.Repo.Repository, false)
  339. if err != nil {
  340. ctx.Error(http.StatusInternalServerError, "canBeAssigned", err)
  341. return
  342. }
  343. if !valid {
  344. ctx.Error(http.StatusUnprocessableEntity, "canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: ctx.Repo.Repository.Name})
  345. return
  346. }
  347. }
  348. } else {
  349. // setting labels is not allowed if user is not a writer
  350. form.Labels = make([]int64, 0)
  351. }
  352. if err := issue_service.NewIssue(ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs); err != nil {
  353. if models.IsErrUserDoesNotHaveAccessToRepo(err) {
  354. ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
  355. return
  356. }
  357. ctx.Error(http.StatusInternalServerError, "NewIssue", err)
  358. return
  359. }
  360. if form.Closed {
  361. if err := issue_service.ChangeStatus(issue, ctx.User, true); err != nil {
  362. if models.IsErrDependenciesLeft(err) {
  363. ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
  364. return
  365. }
  366. ctx.Error(http.StatusInternalServerError, "ChangeStatus", err)
  367. return
  368. }
  369. }
  370. // Refetch from database to assign some automatic values
  371. issue, err = models.GetIssueByID(issue.ID)
  372. if err != nil {
  373. ctx.Error(http.StatusInternalServerError, "GetIssueByID", err)
  374. return
  375. }
  376. ctx.JSON(http.StatusCreated, issue.APIFormat())
  377. }
  378. // EditIssue modify an issue of a repository
  379. func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
  380. // swagger:operation PATCH /repos/{owner}/{repo}/issues/{index} issue issueEditIssue
  381. // ---
  382. // summary: Edit an issue. If using deadline only the date will be taken into account, and time of day ignored.
  383. // consumes:
  384. // - application/json
  385. // produces:
  386. // - application/json
  387. // parameters:
  388. // - name: owner
  389. // in: path
  390. // description: owner of the repo
  391. // type: string
  392. // required: true
  393. // - name: repo
  394. // in: path
  395. // description: name of the repo
  396. // type: string
  397. // required: true
  398. // - name: index
  399. // in: path
  400. // description: index of the issue to edit
  401. // type: integer
  402. // format: int64
  403. // required: true
  404. // - name: body
  405. // in: body
  406. // schema:
  407. // "$ref": "#/definitions/EditIssueOption"
  408. // responses:
  409. // "201":
  410. // "$ref": "#/responses/Issue"
  411. // "403":
  412. // "$ref": "#/responses/forbidden"
  413. // "404":
  414. // "$ref": "#/responses/notFound"
  415. // "412":
  416. // "$ref": "#/responses/error"
  417. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  418. if err != nil {
  419. if models.IsErrIssueNotExist(err) {
  420. ctx.NotFound()
  421. } else {
  422. ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
  423. }
  424. return
  425. }
  426. issue.Repo = ctx.Repo.Repository
  427. err = issue.LoadAttributes()
  428. if err != nil {
  429. ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
  430. return
  431. }
  432. if !issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWrite(models.UnitTypeIssues) {
  433. ctx.Status(http.StatusForbidden)
  434. return
  435. }
  436. if len(form.Title) > 0 {
  437. issue.Title = form.Title
  438. }
  439. if form.Body != nil {
  440. issue.Content = *form.Body
  441. }
  442. // Update or remove the deadline, only if set and allowed
  443. if (form.Deadline != nil || form.RemoveDeadline != nil) && ctx.Repo.CanWrite(models.UnitTypeIssues) {
  444. var deadlineUnix timeutil.TimeStamp
  445. if (form.RemoveDeadline == nil || !*form.RemoveDeadline) && !form.Deadline.IsZero() {
  446. deadline := time.Date(form.Deadline.Year(), form.Deadline.Month(), form.Deadline.Day(),
  447. 23, 59, 59, 0, form.Deadline.Location())
  448. deadlineUnix = timeutil.TimeStamp(deadline.Unix())
  449. }
  450. if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
  451. ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
  452. return
  453. }
  454. issue.DeadlineUnix = deadlineUnix
  455. }
  456. // Add/delete assignees
  457. // Deleting is done the GitHub way (quote from their api documentation):
  458. // https://developer.github.com/v3/issues/#edit-an-issue
  459. // "assignees" (array): Logins for Users to assign to this issue.
  460. // Pass one or more user logins to replace the set of assignees on this Issue.
  461. // Send an empty array ([]) to clear all assignees from the Issue.
  462. if ctx.Repo.CanWrite(models.UnitTypeIssues) && (form.Assignees != nil || form.Assignee != nil) {
  463. oneAssignee := ""
  464. if form.Assignee != nil {
  465. oneAssignee = *form.Assignee
  466. }
  467. err = issue_service.UpdateAssignees(issue, oneAssignee, form.Assignees, ctx.User)
  468. if err != nil {
  469. ctx.Error(http.StatusInternalServerError, "UpdateAssignees", err)
  470. return
  471. }
  472. }
  473. if ctx.Repo.CanWrite(models.UnitTypeIssues) && form.Milestone != nil &&
  474. issue.MilestoneID != *form.Milestone {
  475. oldMilestoneID := issue.MilestoneID
  476. issue.MilestoneID = *form.Milestone
  477. if err = issue_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
  478. ctx.Error(http.StatusInternalServerError, "ChangeMilestoneAssign", err)
  479. return
  480. }
  481. }
  482. if err = models.UpdateIssueByAPI(issue); err != nil {
  483. ctx.Error(http.StatusInternalServerError, "UpdateIssueByAPI", err)
  484. return
  485. }
  486. if form.State != nil {
  487. if err = issue_service.ChangeStatus(issue, ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
  488. if models.IsErrDependenciesLeft(err) {
  489. ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
  490. return
  491. }
  492. ctx.Error(http.StatusInternalServerError, "ChangeStatus", err)
  493. return
  494. }
  495. }
  496. // Refetch from database to assign some automatic values
  497. issue, err = models.GetIssueByID(issue.ID)
  498. if err != nil {
  499. ctx.InternalServerError(err)
  500. return
  501. }
  502. if err = issue.LoadMilestone(); err != nil {
  503. ctx.InternalServerError(err)
  504. return
  505. }
  506. ctx.JSON(http.StatusCreated, issue.APIFormat())
  507. }
  508. // UpdateIssueDeadline updates an issue deadline
  509. func UpdateIssueDeadline(ctx *context.APIContext, form api.EditDeadlineOption) {
  510. // swagger:operation POST /repos/{owner}/{repo}/issues/{index}/deadline issue issueEditIssueDeadline
  511. // ---
  512. // summary: Set an issue deadline. If set to null, the deadline is deleted. If using deadline only the date will be taken into account, and time of day ignored.
  513. // consumes:
  514. // - application/json
  515. // produces:
  516. // - application/json
  517. // parameters:
  518. // - name: owner
  519. // in: path
  520. // description: owner of the repo
  521. // type: string
  522. // required: true
  523. // - name: repo
  524. // in: path
  525. // description: name of the repo
  526. // type: string
  527. // required: true
  528. // - name: index
  529. // in: path
  530. // description: index of the issue to create or update a deadline on
  531. // type: integer
  532. // format: int64
  533. // required: true
  534. // - name: body
  535. // in: body
  536. // schema:
  537. // "$ref": "#/definitions/EditDeadlineOption"
  538. // responses:
  539. // "201":
  540. // "$ref": "#/responses/IssueDeadline"
  541. // "403":
  542. // "$ref": "#/responses/forbidden"
  543. // "404":
  544. // "$ref": "#/responses/notFound"
  545. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  546. if err != nil {
  547. if models.IsErrIssueNotExist(err) {
  548. ctx.NotFound()
  549. } else {
  550. ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
  551. }
  552. return
  553. }
  554. if !ctx.Repo.CanWrite(models.UnitTypeIssues) {
  555. ctx.Error(http.StatusForbidden, "", "Not repo writer")
  556. return
  557. }
  558. var deadlineUnix timeutil.TimeStamp
  559. var deadline time.Time
  560. if form.Deadline != nil && !form.Deadline.IsZero() {
  561. deadline = time.Date(form.Deadline.Year(), form.Deadline.Month(), form.Deadline.Day(),
  562. 23, 59, 59, 0, form.Deadline.Location())
  563. deadlineUnix = timeutil.TimeStamp(deadline.Unix())
  564. }
  565. if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
  566. ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
  567. return
  568. }
  569. ctx.JSON(http.StatusCreated, api.IssueDeadline{Deadline: &deadline})
  570. }